This page references the local_search.ipynb notebook from the GraphRAG repository.
When to use local search
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
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
- Context parameters
- Model parameters
Create search engine
Run queries
Basic queries
Inspect context data
See which entities, relationships, and sources were used:- Entities
- Relationships
- Community reports
- Source chunks
- Claims
Question generation
Generate follow-up questions based on conversation history:Example queries
Entity information
Entity information
Relationship queries
Relationship queries
Multi-hop reasoning
Multi-hop reasoning
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 responsesLimit entity retrieval
Reduce
top_k_mapped_entitiesSkip community reports
Set community proportion to 0
Use conversation history
Enable for context-aware follow-ups
Advanced features
Conversation history
Custom response types
Comparison with global search
| Aspect | Local Search | Global Search |
|---|---|---|
| Question Type | Specific, detailed | High-level, broad |
| Data Source | Entities + text chunks + reports | Community reports only |
| Cost | Lower | Higher |
| Response Time | Faster | Slower |
| Best For | Entity details, facts | Themes, summaries |
Troubleshooting
Empty or irrelevant results
Empty or irrelevant results
Solutions:
- Increase
top_k_mapped_entitiesfor broader retrieval - Check if entities exist in your knowledge graph
- Verify embedding model matches indexing model
- Increase
text_unit_propfor more context
Token limit exceeded
Token limit exceeded
Solutions:
- Reduce
max_tokensin context parameters - Lower
top_k_mapped_entitiesandtop_k_relationships - Decrease
text_unit_prop - Use a model with larger context window
Slow performance
Slow performance
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