Vector storage is coming to Meilisearch to empower search through AI
Tags: search, machinelearning, database, opensource
Published: 2023-07-11 11:05:36

Vector search enables efficient retrieval of objects sharing similar characteristics. This AI-powered search technique uses embedding vectors. These vectors are mathematical representations of objects generated by machine learning models (like LLMs). In the upcoming 1.3 release, Meilisearch will support storing and searching vectors.

> The release candidate for Meilisearch v1.3 is out—[try it now](https://github.com/meilisearch/meilisearch/releases/tag/v1.3.0-rc.0)!

## Powering the Future of Search

Vector search might be the dawn of a new era for search. Its use cases are numerous. In [ecommerce](https://ecommerce.meilisearch.com/?utm_campaign=vector-search&utm_source=devto), it enables offering recommendations for similar products. It also allows building multi-modal search, like image or audio search. Building upon conversational AI technologies enables the creation of Q&A applications. Combining vector search with user-provided information like geolocation and search history can power even more contextual search experiences. 

Vector search is also the foundation for [semantic search](https://en.wikipedia.org/wiki/Semantic_search), which aims to understand the query’s meaning. Conversely, traditional lexical search only matches keywords. With semantic search, a `warm clothes` query could give results like `gloves`, `coat`, and more results related to winter clothing.

Vector search unlocks a world of new capabilities for search. Take a look at what some users have already implemented:
- [similar videos recommendations](https://github.com/adrienpoly/rubyvideo/pull/19) on a site listing Ruby conferences
- a [documentation chatbot](https://blazy-chat.vercel.app/) proof of concept using [GPT3.5](https://platform.openai.com/docs/models/gpt-3-5) and [LangChain](https://github.com/hwchase17/langchain)

## Getting started with Meilisearch vector store

Starting with v1.3, you can use Meilisearch as a vector store. Meilisearch allows you to store vector embeddings alongside your documents conveniently. You will need to create the vector embeddings using your third-party tool of choice ([Hugging Face](https://huggingface.co/), [OpenAI](https://openai.com/)). As we published the first [v1.3 release candidate](https://github.com/meilisearch/meilisearch/releases/tag/v1.3.0-rc.0), you can try out vector search today.

First, pull the release candidate by using this Docker image:

```sh
docker run -p 7700:7700 -v $(pwd)/meili_data:/meili_data getmeili/meilisearch:v1.3.0-rc.0
```

Then, enable the vector store experimental feature:

```sh
curl \
  -X PATCH 'http://localhost:7700/experimental-features/' \
  -H 'Content-Type: application/json'  \
  --data-binary '{
    "vectorStore": true
  }'
```

> 💡 This guide uses curl to make HTTP requests to communicate with Meilisearch. When v1.3 will officially be released, you will be able to use the corresponding [SDK methods](https://github.com/meilisearch/integration-guides) instead.


Meilisearch now accepts a `_vector` field in your documents. Use it to store the vector embeddings corresponding to your document in this field.

```sh
curl -X POST -H 'content-type: application/json' \
     'localhost:7700/indexes/songs/documents' \
     --data-binary '[
         { "id": 0, "_vectors": [0, 0.8, -0.2], "title": "Across The Universe" },
         { "id": 1, "_vectors": [1, -0.2, 0], "title": "All Things Must Pass" },
         { "id": 2, "_vectors": [[0.5, 3, 1], [-0.2, 4, 6]], "title": "And Your Bird Can Sing" }
     ]'
```

After storing your vectorized documents in Meilisearch, you can query them using the `search` or `multi-search` route. To do this, you need to compute the vector of your query (using a third-party tool) and send it in the `vector` field.

```sh
curl -X POST -H 'content-type: application/json' \
   'localhost:7700/indexes/songs/search' \
   --data-binary '{ "vector": [0, 1, 2] }'
```

When using vector search, returned documents include a `semanticScore` field:

```sh
{
  "hits": [
    { "id": 0, "_vectors": [0, 0.8, -0.2], "title": "Across The Universe", "_semanticScore": 0.6754 },
    { "id": 1, "_vectors": [1, -0.2, 0], "title": "All Things Must Pass", "_semanticScore": 0.7546 },
    { "id": 2, "_vectors": [[0.5, 3, 1], [-0.2, 4, 6]], "title": "And Your Bird Can Sing", "_semanticScore": 0.78 }
  ],
  "query": "",
  "vector": [0, 1, 2],
  "processingTimeMs": 0,
  "limit": 20,
  "offset": 0,
  "estimatedTotalHits": 2
}
```

> 📢 This API is experimental. You can help us improve it by sharing your feedback in [this Github discussion](https://github.com/meilisearch/product/discussions/677).

## A First Step Toward Semantic Search

Vector search is our first step towards semantic search. But our long-term goal is to provide hybrid search—combining the benefits of full-text and semantic search to provide the most relevant search experience. Clément Renault, founder and CTO of Meilisearch, shared his thoughts on Github about [exploring semantic search](https://github.com/meilisearch/meilisearch/issues/3838) — read for a founder’s perspective. We can’t wait to share more with you!

Drop your email below to learn more about our progress with AI-powered search. We’ll keep you posted on all updates regarding vector search & semantic search.

We’re excited to walk our first steps toward semantic search. We can’t wait to hear your thoughts on integrating Meilisearch as a vector store. You can give your feedback in [this Github discussion](https://github.com/meilisearch/product/discussions/677).

You can stay in the loop by subscribing to our [newsletter](https://meilisearch.us2.list-manage.com/subscribe?u=27870f7b71c908a8b359599fb&id=79582d828e). To learn more about Meilisearch's future and help shape it, look at our [roadmap](https://roadmap.meilisearch.com/) and participate in our [Product Discussions](https://github.com/meilisearch/product/discussions/).

For anything else, join our developers community on [Discord](https://discord.gg/meilisearch).

I’ll see you there.