Cognitive AI memory for agents — episodic, semantic, and working memory with multi-hop graph reasoning.
Project description
AtlasMem: Cognitive AI Memory SDK
AtlasMem is the official Python SDK for the Bsyncs Atlas Cognitive Brain service (CAB-QA). It equips your LLM agents with long-term, query-adaptive Episodic, Semantic (Knowledge Graph), and Working Memory.
Designed to be lightweight and zero-dependency (only requests needed), it works seamlessly with OpenAI, LangChain, CrewAI, LlamaIndex, and plain Python applications.
🚀 Installation
pip install atlas-mem
For async support (requires httpx), install with the async extra:
pip install "atlas-mem[async]"
⚡ Quickstart
Initialize the client with your API key.
from atlas_mem import AtlasMem
# 1. Initialize Memory
brain = AtlasMem(
api_key="atlas_your_api_key_here",
base_url="https://api.bsyncs.com", # Point to your NGINX router or SaaS URL
user_id="user-123", # Isolate memories per user
session_id="session-abc" # Optional: sliding working memory window
)
# 2. Ingest Facts (Automatically extracts Graph Nodes, Edges, and Vector Chunks)
brain.add("Sarah Jenkins is the Lead Software Engineer at Acme Corp.")
brain.add("Acme Corp's primary database was recently migrated to PostgreSQL.")
# 3. Retrieve Context (Hybrid Search across Graph + Vector DBs)
results = brain.search("Who is Sarah and what database does her company use?")
# 4. Format for your LLM System Prompt
print(results.format())
🧠 Advanced Features
📦 Batch Ingestion
When you have a lot of historical context to inject at once, use add_batch to process it efficiently.
brain.add_batch([
"Alex prefers Python over Java.",
"The frontend is built with React and Vite.",
"Deployment happens automatically via GitHub Actions."
])
🕸️ Natural Language Graph QA
Query your knowledge graph directly using natural language. The CAB-QA engine will translate the question into a multi-hop Cypher query, traverse the graph, and return a grounded answer.
answer = brain.ask("How many hops are there between Sarah Jenkins and the PostgreSQL database?")
print(answer)
🧹 Memory Lifecycle Management
Keep your AI's memory clean, highly relevant, and performant. Atlas supports Ebbinghaus temporal decay, cluster compression, and pruning.
# View current graph schema
print(brain.get_schema())
# Dry-run pruning to see how many low-relevance nodes would be deleted
prune_status = brain.prune(threshold=0.1, dry_run=True)
print(f"Candidates for pruning: {prune_status['candidates']}")
# Run full memory consolidation (decays older memories & compresses clusters)
brain.consolidate(force=True)
# View memory stats (Entity count, relation count, etc.)
print(brain.stats())
⏱️ Async Usage
If you are running inside an asynchronous framework like FastAPI, LangGraph, or Discord.py, use AsyncAtlasMem:
import asyncio
from atlas_mem import AsyncAtlasMem
async def main():
# Use as an async context manager
async with AsyncAtlasMem(api_key="atlas_...", user_id="user-123") as brain:
await brain.add("We decided to use AWS RDS for production.")
results = await brain.search("Where is production hosted?")
print(results.format())
if __name__ == "__main__":
asyncio.run(main())
🤖 Agent Framework Integrations
AtlasMem is designed to be injected directly into modern agent frameworks as custom tools. Here is how you can easily wrap it for LangChain:
from langchain.agents import initialize_agent, AgentType
from langchain_openai import ChatOpenAI
from langchain_core.tools import Tool
from atlas_mem import AtlasMem
# 1. Init Brain
brain = AtlasMem(api_key="atlas_...", user_id="user-123")
# 2. Wrap as LangChain Tools
tools = [
Tool(
name="atlas_save_memory",
func=lambda text: brain.add(text).msg,
description="Save important facts, decisions, or context to long-term memory."
),
Tool(
name="atlas_search_memory",
func=lambda query: brain.search(query).format(),
description="Search long-term memory for relevant context before answering."
),
Tool(
name="atlas_graph_qa",
func=lambda q: brain.ask(q),
description="Answer complex relational questions using knowledge graph reasoning."
)
]
# 3. Give to Agent
llm = ChatOpenAI(temperature=0)
agent = initialize_agent(tools, llm, agent=AgentType.CHAT_ZERO_SHOT_REACT_DESCRIPTION)
agent.run("Remember that my favorite programming language is Python.")
📚 API Reference Overview
AtlasMem & AsyncAtlasMem
| Method | Description |
|---|---|
.add(text, source="user") |
Extracts entities/relations and stores them in memory. |
.add_batch(texts) |
Ingests a list of strings efficiently. |
.search(query, k=5) |
Performs hybrid search returning relevant memory facts. |
.ask(question, max_hops=3) |
Performs multi-hop Graph QA, returning a direct answer. |
.consolidate(force=False) |
Runs the lifecycle engine (decay, compress, prune). |
.prune(threshold, dry_run) |
Removes low-confidence memories. |
.get_schema() |
Returns the current Neo4j ontology/schema as a string. |
.stats() |
Returns counts of current episodic chunks and semantic relations. |
.health() |
Pings the backing databases to ensure the service is online. |
💡 Support
For detailed documentation, architectural overviews, and support, visit docs.bsyncs.com.
Project details
Release history Release notifications | RSS feed
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 atlas_mem-2.0.2.tar.gz.
File metadata
- Download URL: atlas_mem-2.0.2.tar.gz
- Upload date:
- Size: 13.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a115e021902f74c9d1127ceb86dd856b75cb98eca02a2e54846c05fee3bfb5c8
|
|
| MD5 |
9f24529e795e57c0e79d2fd7cebbb41d
|
|
| BLAKE2b-256 |
d31c73d9662310bbe8aec1d5a0a851eadcae4903759ba9869e7291109d776f33
|
File details
Details for the file atlas_mem-2.0.2-py3-none-any.whl.
File metadata
- Download URL: atlas_mem-2.0.2-py3-none-any.whl
- Upload date:
- Size: 13.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
515d2d1afd4b72518ddfb8750012a5424e4ac77d91ceb1caf0d3f556a02dca7e
|
|
| MD5 |
7f89ea136859b8d84408f72f69d40514
|
|
| BLAKE2b-256 |
c01d36b96260729c66cd51522ef1a6c02339c573e6c95da3342a7417e9cccc06
|