Skip to main content
Local search generates answers by combining relevant data from the AI-extracted knowledge graph with text chunks of raw documents. This method is ideal for questions requiring understanding of specific entities mentioned in the documents.

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

The LocalSearch class accepts the following key parameters:
model
LLMCompletion
required
Language model chat completion object for response generation
context_builder
LocalContextBuilder
required
Context builder object for preparing context data from knowledge model objects
system_prompt
str
Prompt template for generating the search response. Default: LOCAL_SEARCH_SYSTEM_PROMPT
response_type
str
default:"multiple paragraphs"
Free-form text describing the desired response format (e.g., “Multiple Paragraphs”, “Single Paragraph”, “List”)
llm_params
dict
Additional parameters (e.g., temperature, max_tokens) passed to the LLM call
context_builder_params
dict
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 units
  • community_prop: Proportion of context window for community reports
  • top_k_mapped_entities: Number of top entities to include
  • top_k_relationships: Number of top relationships to include
  • include_entity_rank: Include entity importance scores
  • include_relationship_weight: Include relationship weights
  • max_context_tokens: Maximum tokens for context
callbacks
list[QueryCallbacks]
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:
Balance text units and community reports: Adjust text_unit_prop and community_prop to find the optimal mix for your use case.
  • More text units: Better for specific, detailed questions
  • More community reports: Better for broader entity context

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_entities based on query complexity

Token budget

Manage token usage to balance quality and cost:

Best practices

1

Start with entity-rich queries

Local search performs best when queries mention specific entities or concepts
2

Tune context proportions

Experiment with text_unit_prop and community_prop to optimize for your domain
3

Use conversation history

Include conversation history for follow-up questions to maintain context
4

Monitor context usage

Check the context_data in responses to understand what information was retrieved
5

Adjust top-k parameters

Increase top_k_mapped_entities and top_k_relationships for complex multi-entity questions

Examples

Entity-specific question

Multi-entity question

Follow-up question with conversation history

AspectLocal SearchGlobal Search
Use caseSpecific entity questionsDataset-wide questions
Starting pointEntity embeddingsCommunity reports
ContextEntity neighborhoodAll community reports
SpeedFasterSlower
CostLowerHigher
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