Improved Search with Vectara Query Rewriting (Tech Preview)
Vectara's Intelligent Query Rewriting (Tech Preview) improves RAG search accuracy by separating queries into their natural language and filter expression components.
4-minute read time
We’re excited to launch the tech preview of Intelligent Query Rewriting, a new feature designed to improve the accuracy of search results within the Vectara platform. This feature tackles the challenge of deconstructing natural language queries into their separate filter criteria and core search intent. By extracting and applying filters independently, Intelligent Query Rewriting enables more effective searching and ensures that all aspects of a user's request are accurately captured and interpreted correctly.
This structured understanding of natural language queries provides essential information for agentic workflows, enabling more sophisticated and automated actions based on user intent. This leads to more precise and relevant search results and lays the groundwork for richer, agentic experiences.
The Problem: Parsing Natural Language for Filters
Users often combine natural language search with filter criteria in a single query, usually without realizing it. For example, a user might ask: "What are some of the highest grossing movies made in the US, UK or India?" While the intent is clear to a human, the search engine must disentangle the core search request ("highest grossing movies") from the filter conditions ("made in US, UK or India").
This mixture of search intent and filter criteria within the natural language query can make it difficult for a retrieval system to accurately interpret and execute the search, leading to potentially suboptimal results. The system may struggle to identify the key terms for searching and separately apply the filtering logic.
The Solution: Intelligent Query Rewriting (Tech Preview)
Vectara's Intelligent Query Rewriting feature addresses this issue by automatically separating the filter criteria from the core search intent within a query. Taking the previous example, "What are some of the highest grossing movies made in the US, UK or India?", Intelligent Query Rewriting performs the following steps:
- Filter Extraction: The system identifies and extracts the metadata filters:
doc.production_country IN ('United States of America', 'United Kingdom', 'India')
. This process understands that "made in US, UK or India" refers to a filtering condition based on thedoc.production_country
attribute - Query Reformulation: The original query is reformulated to focus solely on the core search intent: "What are some of the highest grossing movies?" This reformulated query is now optimized for efficient searching against the corpus
- Combined Search and Filtering: Vectara executes the reformulated query to retrieve potentially relevant results. Then, the extracted metadata filter is applied to these results to ensure only documents matching the specified criteria are returned
This separation of concerns—searching based on core intent and then filtering—allows Vectara to operate more effectively. By explicitly extracting and applying filters, Intelligent Query Rewriting ensures that all aspects of the user's request are correctly handled, leading to more accurate and relevant search results.
Technical Details
This feature is accessed via the intelligent_query_rewriting: true
parameter and enabling this feature adds some latency. You can set this in the query parameters of the simple single corpus query request or in the request body for any of these four endpoints:
Successful filter extraction is shown in the response payload:
Errors result in the original query being executed, with a warning in the response:
Combining Filters
If your request includes a metadata_filter
and intelligent_query_rewriting
is enabled, the extracted filter is combined (ANDed) with your existing filter.
Best Practices
For best results, provide detailed descriptions of your filter attributes. For text attributes, list possible values (e.g., "color: color of the product, can be WHITE, BLACK, or GREY"). Specify case conventions and whether values are abbreviations or full names. While date types are not fully supported, they can function as text in YYYY-MM-DD format for comparison operators.
Conclusion
This is a tech preview release. We encourage you to use it and provide feedback by emailing our product team. Your input is much appreciated. We believe this feature improves how you interact with your data, enabling more direct and effective searches by automating the translation of natural language into structured queries.
You can learn more about Intelligent Query Rewriting in our docs or connect with us on our forums, on our Discord, or on our community. If you’d like to see what Vectara can offer you for retrieval augmented generation on your application or website, sign up for an account!