Skip to main content
Local search generates answers by combining relevant knowledge graph data with text chunks from the original documents. This method is ideal for questions about specific entities or detailed information.
This page references the local_search.ipynb notebook from the GraphRAG repository.
Local search excels at:
  • Entity-specific questions - “Who is Dr. Jordan Hayes?”
  • Relationship queries - “What is the connection between X and Y?”
  • Detailed information - “What are the properties of this concept?”
  • Fact retrieval - “When did this event occur?”

How local search works

1

Query embedding

Your question is converted to an embedding vector.
2

Entity retrieval

Semantically similar entities are retrieved from the vector store.
3

Context expansion

Related relationships, text units, and community reports are gathered.
4

Response generation

The LLM synthesizes an answer from the assembled context.

Setting up the notebook

Import required libraries

Configure paths

Load data tables

Load entities

Load relationships

Load covariates (optional)

Covariates extract claims from your documents and generally require prompt tuning to be valuable. See the GRAPHRAG_CLAIM_* settings.

Load community reports

Load text units

Configure language models

Create local search context builder

If you use entity titles as vector store IDs, set embedding_vectorstore_key=EntityVectorStoreKey.TITLE.

Configure search parameters

Create search engine

Run queries

Basic queries

Inspect context data

See which entities, relationships, and sources were used:

Question generation

Generate follow-up questions based on conversation history:

Example queries

Tuning parameters

Context allocation

Adjust the proportion of context dedicated to different data types:

Entity retrieval

Debug mode

Enable candidate context to see what was considered:

Performance optimization

Reduce context size

Lower max_tokens for faster responses

Limit entity retrieval

Reduce top_k_mapped_entities

Skip community reports

Set community proportion to 0

Use conversation history

Enable for context-aware follow-ups

Advanced features

Conversation history

Custom response types

AspectLocal SearchGlobal Search
Question TypeSpecific, detailedHigh-level, broad
Data SourceEntities + text chunks + reportsCommunity reports only
CostLowerHigher
Response TimeFasterSlower
Best ForEntity details, factsThemes, summaries

Troubleshooting

Solutions:
  • Increase top_k_mapped_entities for broader retrieval
  • Check if entities exist in your knowledge graph
  • Verify embedding model matches indexing model
  • Increase text_unit_prop for more context
Solutions:
  • Reduce max_tokens in context parameters
  • Lower top_k_mapped_entities and top_k_relationships
  • Decrease text_unit_prop
  • Use a model with larger context window
Solutions:
  • Reduce context size parameters
  • Disable community reports if not needed
  • Use faster embedding model
  • Cache frequent queries

Next steps

Global search

Learn about global search for dataset-wide questions

DRIFT search

Explore dynamic iterative search

Search comparison

Compare all search methods side-by-side

Query guide

Complete local search documentation