Find answers from the community

Updated last week

Filter

Is there a way to instantiate metadata filtering as part of the hybrid search? This cookbook (https://docs.llamaindex.ai/en/stable/examples/vector_stores/Qdrant_metadata_filter/) requires specifying the filter ahead of time before instantiating the retriever so in production you're going to keep instantiating the query engine with different filters with each query. This tutorial on the other hand allows for instantiation of richer metadata (https://docs.llamaindex.ai/en/stable/examples/metadata_extraction/MetadataExtraction_LLMSurvey/) and I'm currently using the LLMQuestionGenerator -> SubQuestionQueryEngine strategy to try and get it to look at the metadata:

Plain Text
from llama_index.core.question_gen import LLMQuestionGenerator
from llama_index.core.question_gen.prompts import (
    DEFAULT_SUB_QUESTION_PROMPT_TMPL,
)


question_gen = LLMQuestionGenerator.from_defaults(
    llm=llm,
    prompt_template_str="""
        Follow the example, but instead of giving a question, always prefix the question 
        with: 'By first identifying and quoting the most relevant sources, '. 
        """
    + DEFAULT_SUB_QUESTION_PROMPT_TMPL,
)


But I was thinking if it was possible to have a triple hybrid search - dense, sparse embedding search and metadata search?
L
3 comments
You pretty much need to specify it before creating the retriever/query engine. It's a no-op, so it should really be a huge deal?
The alternative is using vector_store.query() directly
For that, it's something like

Plain Text
from llama_index.core.vector_stores.types import VectorStoreQuery

query_embed = embed_model.get_query_embedding("query")
query_obj = VectorStoreQuery(query_embedding=query_embed, similarity_top_k=2, filters=filters)

result = vector_store.query(query_obj)
Add a reply
Sign up and join the conversation on Discord