Requires Python 3.11+.
Overview
This guide shows how to add Synap to a LlamaIndex application to build pipelines that:- Maintain chat history across sessions and processes
- Retrieve user-scoped memories alongside document chunks in a RAG flow
- Fuse memory-based and document-based retrieval into a single ranked result set
Setup
Install the package alongside LlamaIndex:The pip package is
maximem-synap-llamaindex, but the import drops the maximem- prefix and uses underscores: from synap_llamaindex import .....env
Basic integration
The smallest useful integration plugsSynapChatMemory into any LlamaIndex chat engine. Past turns are loaded automatically on each call, and new turns are persisted on the way out:
SynapChatMemory loads prior messages on get() and writes new turns back to Synap on put(). Failed reads return an empty buffer and log an error; failed writes surface explicitly so callers know if persistence failed.
To make user-specific memories retrievable inside the chat engine (alongside or in place of documents), layer in SynapRetriever below.
Core concepts
Persistent chat memory
SynapChatMemory implements BaseMemory. Every LlamaIndex chat engine accepts a memory object: drop this one in to make the conversation durable:
conversation_id maps one-to-one to a Synap conversation. Restart your process, instantiate SynapChatMemory again with the same conversation_id, and the chat engine resumes with the prior history.
Semantic retrieval
SynapRetriever implements BaseRetriever and returns NodeWithScore objects, the same shape every LlamaIndex RAG component expects. Use it as the retriever of a RetrieverQueryEngine, or as a sub-retriever inside a RouterRetriever / QueryFusionRetriever:
fast is lower-latency and suited to the hot path; accurate adds LLM-driven query decomposition and reranking for relationship-aware queries at a higher latency cost. See Context Fetch for the full retrieval contract.
Complete example: support assistant with memory + docs
The following pipeline gives a chat engine both Synap-backed conversation memory and a fused retriever that blends user-specific memories with document chunks:SynapChatMemoryis constructed per-conversation so multiple sessions can run side-by-side without interfering.SynapRetrieveris fused with the document retriever viaQueryFusionRetriever, so user-specific facts and corpus documents come back as one ranked list.- Memory and retrieval are independent. Drop either and the pipeline still works; together they cover both the “what did we say” and “what do I know about this user” axes.
Advanced patterns
Multi-tenant scoping
Both components accept the same scoping triple:user_id (required), optional customer_id, optional conversation_id. customer_id is required on B2B Synap instances and ignored on single-tenant ones. See Memory Scopes.
Tuning retrieval mode per query
SynapRetriever takes a default mode at construction, but you can swap it temporarily for a single high-recall lookup:
Composing with other retrievers
SynapRetriever is a regular BaseRetriever, so it composes cleanly with LlamaIndex’s RouterRetriever, QueryFusionRetriever, or any custom retriever you build. Combine it with a document retriever (as in the example above), or route between Synap memories and a vector store based on the query.
Failure semantics
The integration follows the Synap-wide contract:- Retrieval failures degrade gracefully:
SynapRetriever.aretrievereturns[]and logs an error - Memory reads degrade gracefully:
SynapChatMemory.getreturns an empty buffer and logs an error - Memory writes surface failures:
SynapChatMemory.putraisesSynapIntegrationErrorso callers know persistence failed
Going further
- Patterns overview: reusable memory patterns across frameworks.
- Cookbook overview: end-to-end worked examples.
Next steps
LangChain
Memory, retriever, and tools for LangChain chains and agents.
Haystack
Retriever and memory-writer pipeline components for Haystack.
Context Fetch
The retrieval API that powers
SynapRetriever: modes, scopes, and response shapes.Memory Scopes
How
user_id, customer_id, and conversation_id interact across retrievals.