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. Each one implements a native LlamaIndex interface, so you can use it anywhere a vanilla LlamaIndex memory or retriever is accepted.

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. 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:
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.

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), 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.aretrieve returns [] and logs an error
  • Memory reads degrade gracefully: SynapChatMemory.get returns an empty buffer and logs an error
  • Memory writes surface failures: SynapChatMemory.put raises SynapIntegrationError so callers know persistence failed
This is by design: read failures should never break a user-facing turn, while write failures 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.