Skip to main content
Give LlamaIndex chat engines and RAG pipelines persistent memory backed by Synap. Conversations survive restarts, and Synap-stored memories sit alongside your document retrieval as first-class context.
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
The Synap LlamaIndex integration ships two drop-in components and one helper. Each component implements a native LlamaIndex interface, so you can use it anywhere a vanilla LlamaIndex memory or retriever is accepted.

How the integration connects

You do not open a connection yourself. The first message put on SynapChatMemory opens Synap’s gRPC stream, and from then on turns, tool calls, tool results and reasoning go over it. Opening gets up to 10 seconds; if it fails, the memory tries once more a few seconds later, then no more than once a minute, and writes each turn over REST in the meantime, never both.
  • A stream your own code opened with listen() is used as is.
  • To keep the integration on REST, set SYNAP_AUTO_LISTEN=false in the environment, or call set_auto_listen(sdk, False) from synap_integrations_common.
  • Tool calls, tool results and reasoning exist only on the stream. Without one they are not reported, and the turns still are.
  • Initialize the SDK first (below). Until it is initialized the memory cannot open the stream.
  • Use the async entry points (achat, agent.run). They run on your event loop, which is where the stream lives.
See gRPC vs REST for what the stream carries.

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 ....
Configure your API key. Generate one from the Synap Dashboard.
.env
Initialize the SDK once at application startup:
See SDK Initialization for the full lifecycle and configuration options.

Basic integration

The smallest useful integration plugs SynapChatMemory into any LlamaIndex chat engine. History is loaded on each call, and new turns are recorded on the way out:
SynapChatMemory loads history on get() and writes new turns back to Synap on put(). A failed read logs an error and falls back to the messages this process already holds; a failed write surfaces 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:
Each 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. SynapChatMemory replaces the chat buffer, so get() decides what history the model is sent:
  • Not compacted yet: the messages put on the memory in this process, with their tool calls, results and reasoning. A fresh process that has put nothing yet gets the recent turns Synap holds.
  • Compacted: Synap’s compaction replaces every turn before the current one, followed by the turns after the compaction. The current turn, with the tool calls and results after it, is left as the agent built it. Each turn reaches the model once.
  • Synap cannot answer: the messages held in this process are sent as they are.
When you pass a user message to get(), which chat engines do, the memory also adds a system message of long-term context for that message. To record a whole agent run, pass the memory to a function agent. The agent hands the memory its whole scratchpad, so the user turn, the assistant turn, the model’s reasoning, each tool call and each tool result reach Synap:
For a chat engine you assemble by hand, synap_st_chat_message(sdk, conversation_id, system="...") returns an async factory. Calling it gives a system ChatMessage made of Synap’s compaction and your own system text, or None when both are empty. It adds the compaction only, and nothing before the first compaction.

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:
The two retrieval modes trade latency against comprehensiveness: 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:
Three things to notice in this pattern:
  1. SynapChatMemory is constructed per-conversation so multiple sessions can run side-by-side without interfering.
  2. SynapRetriever is fused with the document retriever via QueryFusionRetriever, so user-specific facts and corpus documents come back as one ranked list.
  3. 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), customer_id (B2B instances only), optional conversation_id. customer_id is required on B2B Synap instances and not accepted on B2C (single-tenant) ones, where a call carrying it is rejected with HTTP 400. 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 surface: SynapRetriever.aretrieve logs the error and raises SynapIntegrationError
  • Memory reads degrade gracefully: SynapChatMemory.get logs an error and returns the messages held in this process
  • Memory writes surface failures: SynapChatMemory.put raises SynapIntegrationError when neither the stream nor REST took the turn
  • Reports never raise: tool calls, tool results and reasoning are sent best-effort and cannot stop the agent
This is by design: memory reads should never break a user-facing turn, while writes must be visible to callers.

Going further


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.