Searching the Graph
Zep employs hybrid search, combining semantic similarity with BM25 full-text. Results are merged and ranked. Additional details can be found in the API Reference.
The example below demonstrates a simple search.
Python
TypeScript
Read more about chat message history search.
Best Practices
Keep queries short: they are truncated at 8,192 tokens. Long queries may increase latency without improving search quality. Break down complex searches into smaller, targeted queries. Use precise, contextual queries rather than generic ones
Configurable Search Parameters
Zep allows several parameters to fine-tune search behavior:
Search Scopes
Nodes are connection points in the graph that represent either:
- Chat history entities
- Business data added through the Graph API
Each node maintains a summary of facts from its connections (edges), giving you a quick overview of things related to that node.
Edges represent individual connections between nodes, containing specific interactions or pieces of information. Edge search (the default) is best for finding specific details or conversations, while node search helps you understand the broader context around entities in your graph.
The example below demonstrates a node search.
Python
TypeScript
Reranking Search Results
Besides the default Reciprocal Rank Fusion (rrf
) which combines results from semantic and BM25, Zep supports several reranking methods to improve search results:
Maximal Marginal Relevance Re-Ranking
Standard similarity searches often return highly similar top results, potentially limiting the information added to a prompt. mmr
addresses this by re-ranking results to promote diversity, downranking similar results in favor of relevant but distinct alternatives.
Required:
mmr_lambda
- tunes the balance between relevance and diversity
Example of MMR search:
Python
TypeScript
Node Distance
node_distance
re-ranks search results based on the number of hops between the search result and a center node. This can be useful for finding facts related to a specific node, such as a user or a topic.
Required:
center_node_uuid
- UUID of the node to use as the center of the search
Example of Node Distance search:
Python
TypeScript
Episode Mentions
episode_mentions
re-ranks search results based on the number of times the node or edge has been mentioned in the chat history.
Example of Episode Mentions search:
Python
TypeScript
Cross Encoder
cross_encoder
re-ranks search results by using a specialized model that jointly analyzes the query and each search result together, providing more accurate relevance scoring than traditional methods that analyze them separately.
Example of Cross Encoder search: