Global Search 🔎
Whole Dataset Reasoning
Baseline RAG struggles with queries that require aggregation of information across the dataset to compose an answer. Queries such as “What are the top 5 themes in the data?” perform terribly because baseline RAG relies on a vector search of semantically similar text content within the dataset. There is nothing in the query to direct it to the correct information.
However, with GraphRAG we can answer such questions, because the structure of the LLM-generated knowledge graph tells us about the structure (and thus themes) of the dataset as a whole. This allows the private dataset to be organized into meaningful semantic clusters that are pre-summarized. Using our global search method, the LLM uses these clusters to summarize these themes when responding to a user query.
Methodology
---
title: Global Search Dataflow
---
%%{ init: { 'flowchart': { 'curve': 'step' } } }%%
flowchart LR
uq[User Query] --- .1
ch1[Conversation History] --- .1
subgraph RIR
direction TB
ri1[Rated Intermediate<br/>Response 1]~~~ri2[Rated Intermediate<br/>Response 2] -."{1..N}".-rin[Rated Intermediate<br/>Response N]
end
.1--Shuffled Community<br/>Report Batch 1-->RIR
.1--Shuffled Community<br/>Report Batch 2-->RIR---.2
.1--Shuffled Community<br/>Report Batch N-->RIR
.2--Ranking +<br/>Filtering-->agr[Aggregated Intermediate<br/>Responses]-->res[Response]
classDef green fill:#26B653,stroke:#333,stroke-width:2px,color:#fff;
classDef turquoise fill:#19CCD3,stroke:#333,stroke-width:2px,color:#fff;
classDef rose fill:#DD8694,stroke:#333,stroke-width:2px,color:#fff;
classDef orange fill:#F19914,stroke:#333,stroke-width:2px,color:#fff;
classDef purple fill:#B356CD,stroke:#333,stroke-width:2px,color:#fff;
classDef invisible fill:#fff,stroke:#fff,stroke-width:0px,color:#fff, width:0px;
class uq,ch1 turquoise;
class ri1,ri2,rin rose;
class agr orange;
class res purple;
class .1,.2 invisible;
Given a user query and, optionally, the conversation history, the global search method uses a collection of LLM-generated community reports from a specified level of the graph's community hierarchy as context data to generate response in a map-reduce manner. At the map
step, community reports are segmented into text chunks of pre-defined size. Each text chunk is then used to produce an intermediate response containing a list of point, each of which is accompanied by a numerical rating indicating the importance of the point. At the reduce
step, a filtered set of the most important points from the intermediate responses are aggregated and used as the context to generate the final response.
The quality of the global search’s response can be heavily influenced by the level of the community hierarchy chosen for sourcing community reports. Lower hierarchy levels, with their detailed reports, tend to yield more thorough responses, but may also increase the time and LLM resources needed to generate the final response due to the volume of reports.
Configuration
Below are the key parameters of the GlobalSearch class:
llm
: OpenAI model object to be used for response generationcontext_builder
: context builder object to be used for preparing context data from community reportsmap_system_prompt
: prompt template used in themap
stage. Default template can be found at map_system_promptreduce_system_prompt
: prompt template used in thereduce
stage, default template can be found at reduce_system_promptresponse_type
: free-form text describing the desired response type and format (e.g.,Multiple Paragraphs
,Multi-Page Report
)allow_general_knowledge
: setting this to True will include additional instructions to thereduce_system_prompt
to prompt the LLM to incorporate relevant real-world knowledge outside of the dataset. Note that this may increase hallucinations, but can be useful for certain scenarios. Default is False *general_knowledge_inclusion_prompt
: instruction to add to thereduce_system_prompt
ifallow_general_knowledge
is enabled. Default instruction can be found at general_knowledge_instructionmax_data_tokens
: token budget for the context datamap_llm_params
: a dictionary of additional parameters (e.g., temperature, max_tokens) to be passed to the LLM call at themap
stagereduce_llm_params
: a dictionary of additional parameters (e.g., temperature, max_tokens) to passed to the LLM call at thereduce
stagecontext_builder_params
: a dictionary of additional parameters to be passed to thecontext_builder
object when building context window for themap
stage.concurrent_coroutines
: controls the degree of parallelism in themap
stage.callbacks
: optional callback functions, can be used to provide custom event handlers for LLM's completion streaming events
How to Use
An example of a global search scenario can be found in the following notebook.