Persistent semantic memory for AI agents — SQLite-backed, local-first, zero config
Project description
cartisien-engram
Persistent semantic memory for AI agents — Python SDK
from engram import Engram, EngramConfig
memory = Engram(EngramConfig(db_path="./memory.db"))
# Store
memory.remember("user_123", "User prefers TypeScript and dark mode", "user")
# Recall semantically — finds the right memory without exact keyword match
results = memory.recall("user_123", "what are the user's preferences?", limit=5)
# [MemoryEntry(content='User prefers TypeScript and dark mode', similarity=0.82, ...)]
Install
pip install cartisien-engram
Optional: LangChain integration
pip install "cartisien-engram[langchain]"
Optional: Local embeddings (recommended)
# Install Ollama: https://ollama.ai
ollama pull nomic-embed-text
Without Ollama, keyword search is used automatically.
Quick Start
from engram import Engram, EngramConfig
memory = Engram(EngramConfig(
db_path="./agent.db",
embedding_url="http://localhost:11434", # Ollama default
))
# In your agent loop
def handle_message(session_id: str, user_input: str) -> str:
# 1. Recall relevant context
context = memory.recall(session_id, user_input, limit=5)
context_str = "\n".join(f"[{e.role}]: {e.content}" for e in context)
# 2. Build prompt + call your LLM
response = llm.chat(f"Context:\n{context_str}\n\nUser: {user_input}")
# 3. Store both sides
memory.remember(session_id, user_input, "user")
memory.remember(session_id, response, "assistant")
return response
LangChain Integration
Drop-in replacement for ConversationBufferMemory:
from engram.langchain import EngramMemory
from langchain.chains import ConversationChain
from langchain.llms import OpenAI
memory = EngramMemory(
session_id="user_abc",
db_path="./memory.db",
recall_limit=10
)
chain = ConversationChain(llm=OpenAI(), memory=memory)
chain.predict(input="My name is Jeff and I'm building GovScout")
# Start a new session — memory persists
chain.predict(input="What am I building?") # Remembers "GovScout"
API
Engram(config?)
config = EngramConfig(
db_path="./memory.db", # SQLite path (default: ":memory:")
max_context_length=4000, # Max chars per entry
embedding_url="http://localhost:11434", # Ollama base URL
embedding_model="nomic-embed-text", # Embedding model
semantic_search=True, # Enable semantic search
)
memory = Engram(config)
remember(session_id, content, role="user", metadata=None)
entry = memory.remember("session_1", "User loves Thai food", "user")
# MemoryEntry(id=..., content=..., role='user', timestamp=...)
recall(session_id, query=None, limit=10, options=None)
Semantic search when Ollama available, keyword fallback otherwise.
results = memory.recall("session_1", "food preferences", limit=5)
# [MemoryEntry(..., similarity=0.84)]
history(session_id, limit=20)
Chronological conversation history.
chat = memory.history("session_1", limit=20)
forget(session_id, id=None, before=None)
memory.forget("session_1") # clear all
memory.forget("session_1", id="abc123") # delete one
memory.forget("session_1", before=datetime.now()) # delete old
stats(session_id)
stats = memory.stats("session_1")
# {"total": 42, "by_role": {"user": 21, "assistant": 21}, "with_embeddings": 42}
Context manager
with Engram(EngramConfig(db_path="./memory.db")) as memory:
memory.remember("s1", "test", "user")
Part of the Cartisien Memory Suite
| Package | Language | Purpose |
|---|---|---|
cartisien-engram |
Python | This package |
@cartisien/engram |
TypeScript/Node | TS SDK |
@cartisien/engram-mcp |
TypeScript | MCP server |
@cartisien/extensa |
TypeScript | Vector infrastructure (soon) |
@cartisien/cogito |
TypeScript | Agent identity (soon) |
MIT © Cartisien Interactive
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cartisien_engram-0.3.0.tar.gz.
File metadata
- Download URL: cartisien_engram-0.3.0.tar.gz
- Upload date:
- Size: 11.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4855891fa4fa399a2ff795aa4ef4596aca686bd57aa6e82c20a6b4bda44c011f
|
|
| MD5 |
3c070b627d7ccc93543e26b1435b292e
|
|
| BLAKE2b-256 |
31418177e8f6ce7712c992bc9d3232ee15b4574aebe77f05edbcc88988401d2a
|
File details
Details for the file cartisien_engram-0.3.0-py3-none-any.whl.
File metadata
- Download URL: cartisien_engram-0.3.0-py3-none-any.whl
- Upload date:
- Size: 9.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ed8077a776a5e8bd3ffd0c59f3713af004f3eb7a2081173610bc8a1643c1fdb7
|
|
| MD5 |
552fe7275c374bb406ff56e7445148a2
|
|
| BLAKE2b-256 |
e2c0e2baa5ecfb27ab4dca5b0c18ce2ff342a06daaa2c641a1dfc1212482c692
|