Overview
The local search method combines structured data from the knowledge graph with unstructured data from input documents to augment the LLM context with relevant entity information at query time.Example use case: “What are the healing properties of chamomile?”Local search excels at questions requiring detailed understanding of specific entities and their relationships.
How it works
Local search operates through a multi-step retrieval and ranking process:Entity extraction
Given a user query and optional conversation history, local search identifies entities from the knowledge graph that are semantically related to the user input using entity description embeddings.Context building
The identified entities serve as access points into the knowledge graph, enabling extraction of:- Connected entities: Related entities with their attributes
- Relationships: Edges connecting entities with relationship metadata
- Entity covariates: Additional structured data associated with entities
- Community reports: Summaries of entity communities
- Text units: Raw text chunks from source documents associated with the entities
Prioritization and filtering
Candidate data sources are ranked and filtered to fit within a single context window of pre-defined size. This ensures the most relevant information is included in the prompt.Configuration
TheLocalSearch class accepts the following key parameters:
Language model chat completion object for response generation
Context builder object for preparing context data from knowledge model objects
Prompt template for generating the search response. Default:
LOCAL_SEARCH_SYSTEM_PROMPTFree-form text describing the desired response format (e.g., “Multiple Paragraphs”, “Single Paragraph”, “List”)
Additional parameters (e.g., temperature, max_tokens) passed to the LLM call
Additional parameters passed to the context builder when building context for the search prompt. Common parameters:
text_unit_prop: Proportion of context window for text unitscommunity_prop: Proportion of context window for community reportstop_k_mapped_entities: Number of top entities to includetop_k_relationships: Number of top relationships to includeinclude_entity_rank: Include entity importance scoresinclude_relationship_weight: Include relationship weightsmax_context_tokens: Maximum tokens for context
Optional callback functions for custom event handlers during LLM completion streaming
API usage
Basic usage
Streaming usage
Advanced configuration
Performance considerations
Context window optimization
Local search performance depends heavily on context window composition:Entity extraction quality
The quality of entity extraction directly impacts search results:- Embedding model: Use high-quality embedding models for entity descriptions
- Entity descriptions: Ensure entities have rich, descriptive text during indexing
- Top-k tuning: Adjust
top_k_mapped_entitiesbased on query complexity
Token budget
Manage token usage to balance quality and cost:Best practices
Start with entity-rich queries
Local search performs best when queries mention specific entities or concepts
Tune context proportions
Experiment with
text_unit_prop and community_prop to optimize for your domainMonitor context usage
Check the
context_data in responses to understand what information was retrievedExamples
Entity-specific question
Multi-entity question
Follow-up question with conversation history
Comparison with global search
| Aspect | Local Search | Global Search |
|---|---|---|
| Use case | Specific entity questions | Dataset-wide questions |
| Starting point | Entity embeddings | Community reports |
| Context | Entity neighborhood | All community reports |
| Speed | Faster | Slower |
| Cost | Lower | Higher |
| Best for | ”What/who/where” questions | ”Top-N”, theme analysis |
Next steps
Global search
Learn about dataset-wide reasoning
DRIFT search
Explore hybrid search methods
Example notebooks
See local search in action
Configuration
Configure local search settings