run-llama / llama_index

LlamaIndex is a data framework for your LLM applications
https://docs.llamaindex.ai
MIT License
36.94k stars 5.3k forks source link

[Question]: Invalid query mode: hybrid #16325

Open ehsankf opened 1 month ago

ehsankf commented 1 month ago

Question Validation

Question

vector_store = OpensearchVectorStore(client)
embedding_model = HuggingFaceEmbedding(model_name=embedding_model_name,max_length=384)
index = VectorStoreIndex.from_vector_store(vector_store=vector_store, embed_model=embedding_model)    
text  = "What are the recent advances in llama-index?"
query = VectorStoreQuery(
        query_embedding=embedding_model.get_query_embedding(text),  # Your query embedding
        query_str=text,  # Your query string for text-based filtering
        similarity_top_k=10,  # Number of top similar items to retrieve
        mode=VectorStoreQueryMode.HYBRID  # Set the query mode to HYBRID
    )
 # Perform the query
 result = vector_store.query(query)
 index = VectorStoreIndex(result.nodes, embed_model=embedding_model)
 rerank = RerankModule.colbert_rerank(10)
 llm = get_llm_model()
retriever = index.as_retriever(similarity_top_k=similarity_top_k, node_postprocessors=[rerank], vector_store_query_mode=VectorStoreQueryMode.HYBRID)
prompt = retriever.retrieve(text)
*** ValueError: Invalid query mode: hybrid

I get this error: Invalid query mode: hybrid

dosubot[bot] commented 1 month ago

@ehsankf Hello there! I'm here to help you with any bugs, questions, or contributions. Let's tackle this issue together.

To resolve the "ValueError: Invalid query mode: hybrid" error, ensure that you provide a valid query_str and that self._search_pipeline is set when using the hybrid query mode. Additionally, make sure that hybrid search is enabled by setting enable_hybrid=True in the constructor of your vector store. Also, ensure that the necessary sparse query functions, such as sparse_query_fn and hybrid_fusion_fn, are provided or defaulted, as these are required for hybrid search to function correctly [1][2].

To continue talking to Dosu, mention @dosu.

logan-markewich commented 1 month ago

The default vector store does not support hybrid.

Try a vector store that supports hybrid, or make your own hybrid search

ehsankf commented 1 month ago

This index:index = VectorStoreIndex.from_vector_store(vector_store=vector_store, embed_model=embedding_model) supports hybrid but indexing the entire data base is less efficient than query the vector store before indexing it. Is there a work around to use VectorStoreIndex in the previous solution.

logan-markewich commented 1 month ago

I dont know what you mean by less efficient? This is the core syntax, it only indexes the data once, and then just reconnects to the vector store