Editor’s note: Laura is a speaker for ODSC West this November 1st-3rd. Be sure to check out her talk, “Vector Search – A Gentle Introduction,” there!
Traditional search engines perform a keyword-based search. Such search engines return results that contain an exact match or a close variation of a search query, like searching for papers about “Covid-19“. Those keyword-based search engines work well in some cases, but fall short in use cases where semantics play a role. This means that traditional search engines do not take the actual meaning of the query and documents or data into account. Documents in a database that might be of interest might not be found, because different wording is used. This means that, for example, a paper with the word “coronavirus” in it will not be found with the search term “Covid-19.”
Vector-based search (or semantic search, neural search) tries to solve this problem. Vector search engines like Weaviate retrieve documents by meaning, not by exact matching keywords. With machine learning models like BERT or ResNet50, a vector database converts data objects (text, images, etc) to embeddings. Embeddings are vector representations, which are stored in a high-dimensional vector space. The following image shows a simplified example of embedded concepts and images. Note that some of the name “cat” lies close to an image of a cat. And that “dog” lies closer to “cat” than “banana.”
If we would search for “kitten” in our simple database, the machine learning model would calculate a vector for this word, and return the closest data points. Although there is no datapoint matching exactly the word “kitten“, the vector search engine would return objects like the image of the cat, because this is semantically close to the query. This is visualized in Figure 2.
Using Weaviate to do a vector-based search
Weaviate is an open-source vector-based search engine. With Weaviate you can perform a semantic search for various data types (text, images, etc) as described above. To embed data and queries, you can use out-of-the-box models, use open models (e.g. from HuggingFace), or connect your own machine learning model. Weaviate is horizontally scalable, which enables you to scale ML models and search through big data very fast.
To get a glimpse of how semantic search in practice works, you can try out the following demo. This demo contains a small dataset of around 3500 news articles, which are embedded with a BERT model. You can access this dataset using the Weaviate Console, where you can query this dataset.
With the following GraphQL query, you search the dataset for Articles that are around the topic of “kitten”. The query “kitten” will be vectorized using the BERT model, and Articles that are close to this vector will be retrieved. The title of the top articles along with the calculated “certainty” (ranging from 0.0-1.0) are shown.
If you run this query, you’ll see that the results will all be around the topic of “kitten” or related (cats or pets).
The previous query uses the BERT model as retriever model to vectorize textual articles and queries. With Weaviate you can also attach reader or generator models to enhance the search experience. An example is a Question Answering model, which works on top of the retriever model, and thus works with the results that the BERT model returns. A Q&A BERT model is attached to the demo setup, which extracts an answer for a given question from the list of retrieved articles (context documents). You can try this out with the following query:
Feel free to use this demo dataset to make your own queries!
Vector search for your own dataset
If you get excited by the technology described above, you can learn to apply Weaviate to your own dataset. Visit Weaviate’s documentation or join the (virtual) presentation during the ODSC West conference in November!
This article is written by Laura Ham. Laura is ML Product Researcher at SeMI Technologies, the company behind the vector search engine Weaviate. She researches new machine learning features for Weaviate and works on everything UX/DX related to Weaviate. Additionally, she likes to solve custom use cases with Weaviate, and introduces Weaviate to other people by means of meetups, talks and presentations.