Find answers from the community

Updated 4 weeks ago

Implementing Sprase, Hybrid, and Full-text Search with Milvus Vector Store

How to implement sprase, hybrid and full text search with Milvus Vector store?
@kapa.ai
k
2 comments
----------------------
To implement sparse, hybrid, and full-text search with Milvus Vector Store in LlamaIndex, you can follow these steps:

  1. Sparse Search:
Sparse search is enabled by setting enable_sparse=True when initializing the MilvusVectorStore. The default sparse embedding method uses BGE-M3 from FlagEmbedding.

  1. Hybrid Search:
Hybrid search combines dense and sparse embeddings. To implement it:

  • Set enable_sparse=True when creating MilvusVectorStore
  • Configure a hybrid ranker (e.g., RRFRanker or WeightedRanker)
  • Use vector_store_query_mode="hybrid" when querying
Here's an example of setting up MilvusVectorStore for hybrid search:

Plain Text
vector_store = MilvusVectorStore(
    dim=1536,
    overwrite=True,
    enable_sparse=True,
    hybrid_ranker="RRFRanker",
    hybrid_ranker_params={"k": 60},
)
storage_context = StorageContext.from_defaults(vector_store=vector_store)
index = VectorStoreIndex.from_documents(
    documents, storage_context=storage_context
)


To query using hybrid mode:

Plain Text
query_engine = index.as_query_engine(vector_store_query_mode="hybrid")
response = query_engine.query("Your query here")


  1. Full-text Search:
Full-text search in Milvus is implemented as part of the sparse search functionality. When you enable sparse search, you're essentially enabling full-text search capabilities.

It's important to note that hybrid retrieval is only supported in Milvus 2.4.0 or later. If you're using an earlier version, you'll need to update.
For more detailed information and customization options, you can refer to the MilvusVectorStore documentation and the Milvus Hybrid Index Demo.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Add a reply
Sign up and join the conversation on Discord