present (sb for a job etc)
The Query Conversion User's Manual demonstrates the use of the query transformation in the retrieval of the enhanced generation (RAG) Multiple techniques for transformations and decompositions before executing a user query in a query engine, intelligence, or other process. These transformations can improve the quality and relevance of responses in AI applications.
https://github.com/adithya-s-k/AI-Engineering.academy/tree/main/RAG/06_Query_Transformation_RAG
Query conversion technology
1. Routing
Routing involves identifying a subset of tools relevant to a given query.
flowchart LR A[User Query] --> B[Selector] B --> C[Tool 1] B --> D[Tool 2] B --> E[Tool N] C & D & E --> F[Selected Tool]
Realization method:
- utilization
LLMSingleSelector
maybeLLMMultiSelector
Make a selection based on a large language model - utilization
PydanticSingleSelector
maybePydanticMultiSelector
Make function call-based selections - utilization
ToolMetadata
Defining Tool Options
2. Query rewriting
Query rewriting involves generating multiple variants of the original query to improve the retrieval results.
Realization method:
- utilization
PromptTemplate
and Large Language Model (LLM) for custom implementations - utilization
HyDEQueryTransform
Perform hypothetical document embedding queries
3. Sub-query generation
This technique decomposes a complex query into multiple subqueries, each oriented to a specific tool.
Realization method:
- utilization
OpenAIQuestionGenerator
maybeLLMQuestionGenerator
- utilization
ToolMetadata
Defining Tool Options
4. ReAct Intelligent Body Tool Selection
This method uses ReAct The framework determines the tool to be used and the queries to be executed on that tool.
Realization method:
- utilization
ReActChatFormatter
Perform input formatting - utilization
ReActOutputParser
Parsing Large Language Model Output - utilization
FunctionTool
Definition tools
utilization
Each of the query transformation techniques can be used as modular components in a larger system. The following are examples of basic usage of query rewriting:
from llama_index.core import PromptTemplate
from llama_index.llms.openai import OpenAI
query_gen_prompt = PromptTemplate("Your prompt template is here")
llm = OpenAI(model="gpt-3.5-turbo")
def generate_queries(query: str, llm, num_queries: int = 4):
response = llm.predict(query_gen_prompt, num_queries=num_queries, query=query)
queries = response.split("\n")
return queries
queries = generate_queries("Your queries are here", llm)
summarize
The Query Transformation User Manual provides a complete set of techniques to help developers enhance query processing in AI applications. By utilizing these transformation techniques, developers can create more powerful and accurate information retrieval and Q&A systems.
For more on detailed implementation and integration with a specific query engine or retriever, please refer to the LlamaIndex documentation.
This README provides an overview of the Query Transformation User's Manual, including brief descriptions and Mermaid charts for each query transformation technique, covering the four main query transformation techniques: Routing, Query Rewriting, SubQuery Generation, and ReAct Intelligent Body Tool Selection.
Each section includes a flowchart visualization, a brief description of the technology, and basic implementation details. In addition, this README includes a simple usage example of query rewriting to provide users with a starting point.
What part of this README would you like me to expand or modify in detail?