Skip to main content

LlamaIndex memory provider backed by the Unison brain — long-term agent memory via a knowledge graph.

Project description

Unison Brain

llama-index-memory-unison

Long-term agent memory for LlamaIndex — powered by the Unison brain.

Drop in wherever you'd use ChatMemoryBuffer. Agents get persistent, knowledge-graph-powered recall across sessions with zero infrastructure changes.

CI PyPI License: MIT Stars

InstallQuick startReplacing ChatMemoryBufferHow it worksFor agents


Reading this as an AI agent? See AGENTS.md — install, auth, and UnisonMemory.from_client(session_id=...) usage in one place.

Install

pip install llama-index-memory-unison

Quick start

import os
from llama_index.memory.unison import UnisonMemory
from llama_index.core.agent import ReActAgent
from llama_index.llms.openai import OpenAI

# Build Unison memory for this user/session
memory = UnisonMemory.from_client(
    session_id="user-123",          # stable per-user or per-thread ID
    api_key="usk_live_...",         # or set UNISON_TOKEN env var
    # api_url="https://brain.unisonlabs.ai",  # default
    # search_k=5,                             # hits per recall
)

# Pass it to any LlamaIndex agent or chat engine
llm = OpenAI(model="gpt-4o", api_key=os.environ["OPENAI_API_KEY"])
agent = ReActAgent.from_tools([], llm=llm, memory=memory, verbose=True)

# Subsequent calls automatically recall relevant long-term context
response = agent.chat("What did we discuss last week about Alice?")
print(response)

Replacing ChatMemoryBuffer

# Before
from llama_index.core.memory import ChatMemoryBuffer
memory = ChatMemoryBuffer.from_defaults(token_limit=3000)

# After — drop-in replacement with long-term recall
from llama_index.memory.unison import UnisonMemory
memory = UnisonMemory.from_client(session_id="user-123", api_key="usk_live_...")

Using environment variables

export UNISON_TOKEN="usk_live_..."
export UNISON_API_URL="https://brain.unisonlabs.ai"  # optional, this is the default
from llama_index.memory.unison import UnisonMemory

# Reads UNISON_TOKEN and UNISON_API_URL automatically
memory = UnisonMemory.from_defaults(session_id="user-123")

Environment variables

Variable Description Default
UNISON_TOKEN Unison API token (usk_live_...) Required
UNISON_API_URL Unison brain base URL https://brain.unisonlabs.ai

How it works

LlamaIndex call What UnisonMemory does
put(message) Appends to a local in-session buffer and POSTs the turn to POST /v1/brain/ingest. Ingestion is async on the Unison side — entity resolution and fact extraction happen server-side.
get(input=query) Fetches GET /v1/brain/context?q=<query> and, if the brain has relevant hits (weakEvidence=false), prepends a SYSTEM message containing the recalled contextMd block ahead of the local buffer.
get_all() Returns the raw local buffer only (no recall).
set(messages) Replaces the local buffer. Server memory is not modified.
reset() Clears the local buffer. Server memory is not deleted.

Network errors are caught and logged; they never crash the agent.

Releasing

Set a PyPI token, then run one command:

export TWINE_USERNAME=__token__
export TWINE_PASSWORD=pypi-...
python3 scripts/release.py

Or configure ~/.pypirc instead of the env vars.

The script builds llama-index-memory-unison, publishes to PyPI (idempotent — skips if the version is already on PyPI), then tags and pushes v<version>.

Links

Contributing & security

Contributions welcome — see CONTRIBUTING.md. Found a vulnerability? See SECURITY.md — please report privately, not via a public issue.

Part of the Unison Labs constellation

One brain, every agent. Every repo below reads from and writes to the same Unison brain — no per-tool memory silos.

Repo What it does
unison-brain CLI · SDK · MCP server — the core
claude-unison Memory for Claude Code
cursor-unison Memory for Cursor
codex-unison Memory for OpenAI Codex CLI
opencode-unison Memory for OpenCode
openclaw-unison Memory for OpenClaw
pipecat-unison Memory for Pipecat voice agents
langchain-unison LangChain memory, history & retriever
llama-index-memory-unison LlamaIndex memory provider ← you are here
unison-ai-sdk Vercel AI SDK memory middleware
unison-mastra Mastra agent memory provider
python-sdk Python SDK for the brain
install-mcp One-command MCP installer
unison-fs Mount the brain as a filesystem
backchannel Async messaging between agents
Unison-evals Open memory benchmark suite

License

MIT — see LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

llama_index_memory_unison-0.1.1.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

llama_index_memory_unison-0.1.1-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

Details for the file llama_index_memory_unison-0.1.1.tar.gz.

File metadata

File hashes

Hashes for llama_index_memory_unison-0.1.1.tar.gz
Algorithm Hash digest
SHA256 5bfe6a9e6242b87ef1092ebc90376ce7f12b2050496af4d256bdc1bd36796b25
MD5 a118abe979d40bb936f41f34f78fac6e
BLAKE2b-256 8435f980ac957be8400444879c93cd7aa92aca800371897a2ee8c4aa1b4b9cb7

See more details on using hashes here.

File details

Details for the file llama_index_memory_unison-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for llama_index_memory_unison-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8b9943406148e6dd792fdf4c6ae6ad4f03fffaf9da03f1d38e177f9eefcc343a
MD5 1ee9fc5a8df5b8ea41eb3fe34cd5bde7
BLAKE2b-256 11a04f57af7460d52b8ed746eb40b1c450a1c4c2582159520357680736245484

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page