Performance Optimization Guide
This guide covers best practices for optimizing Zep’s performance in production environments.
Reuse the Zep SDK Client
The Zep SDK client maintains an HTTP connection pool that enables connection reuse, significantly reducing latency by avoiding the overhead of establishing new connections. To optimize performance:
- Create a single client instance and reuse it across your application
- Avoid creating new client instances for each request or function
- Consider implementing a client singleton pattern in your application
- For serverless environments, initialize the client outside the handler function
Optimizing Memory Operations
The memory.add
and memory.get
methods are optimized for conversational messages and low-latency retrieval. For optimal performance:
- Keep individual messages under 10K characters
- Use
graph.add
for larger documents, tool outputs, or business data - Consider chunking large documents before adding them to the graph (the
graph.add
endpoint has a 300,000 character limit) - Remove unnecessary metadata or content before persistence
- For bulk document ingestion, process documents in parallel while respecting rate limits
Optimizing Search Queries
Zep uses hybrid search combining semantic similarity and BM25 full-text search. For optimal performance:
- Keep your queries concise. Queries are automatically truncated to 8,192 tokens (approximately 32,000 Latin characters)
- Longer queries may not improve search quality and will increase latency
- Consider breaking down complex searches into smaller, focused queries
- Use specific, contextual queries rather than generic ones
Best practices for search:
- Keep search queries concise and specific
- Structure queries to target relevant information
- Use natural language queries for better semantic matching
- Consider the scope of your search (user vs group graphs)
Summary
- Reuse Zep SDK client instances to optimize connection management
- Use appropriate methods for different types of content (
memory.add
for conversations,graph.add
for large documents) - Keep search queries focused and under the token limit for optimal performance