Skip to main content

Production-grade AI memory infrastructure �?Python SDK with full parity to the TypeScript core.

Project description

LimbicDB Python SDK

CI Python License: MIT

Production-grade AI memory infrastructure for Python. Full feature parity with the TypeScript/Node.js core — same .limbic database files, identical cognitive scoring, native LangChain and LlamaIndex support.


Features

Feature Status
SQLite storage — reads/writes .limbic files (cross-language compatible)
PostgreSQL + pgvector — cloud/enterprise backend
ExplainEngine — identical Ebbinghaus decay + ACT-R scoring to TS
HLC — Hybrid Logical Clock for P2P sync
LangChainLimbicChatMemory + LimbicVectorStore
LlamaIndexLimbicReader + LimbicQueryEngine
pytest — 53+ tests, 80% coverage gate
ruff — zero lint errors

Installation

# Core (SQLite only — zero extra deps)
pip install limbicdb

# With PostgreSQL + pgvector
pip install "limbicdb[postgres]"

# With LangChain
pip install "limbicdb[langchain]"

# With LlamaIndex
pip install "limbicdb[llamaindex]"

# Full
pip install "limbicdb[postgres,langchain,llamaindex]"

Quick Start

from limbicdb import open as ldb_open

db = ldb_open("./agent.limbic")

db.remember("User prefers dark mode")
db.remember("User is building an AI agent in Python", tags=["project", "ai"])

result = db.recall("Python AI preferences")
for memory in result.memories:
    print(memory.content)

# With full cognitive score explanation
result = db.recall("preferences", explain=True)
for memory in result.memories:
    print(f"[score={memory.explanation.score:.3f}] {memory.content}")
    print(f"  decay={memory.explanation.decay:.3f}")
    print(f"  repetition={memory.explanation.repetition:.3f}")

db.close()

Context Manager

with ldb_open("./agent.limbic") as db:
    db.remember("Context manager example")
    result = db.recall("Context manager")
    print(result.memories[0].content)

PostgreSQL Backend

from limbicdb import LimbicDB, LimbicDBConfig
from limbicdb.storage.postgres_store import PostgresStore

store = PostgresStore(
    conninfo="postgresql://postgres:password@localhost:5432/mydb",
    schema="agent_memory",
    embedding_dimensions=1536,
)
store.init()

db = LimbicDB(LimbicDBConfig(storage=store))
db.remember("Stored in PostgreSQL!")
db.close()

Requires pip install "limbicdb[postgres]"


LangChain Integration

Chat Memory

from limbicdb.integrations.langchain import LimbicChatMemory
from langchain.chains import ConversationChain
from langchain_openai import ChatOpenAI

memory = LimbicChatMemory(
    path="./chat.limbic",
    session_id="user-42",
    max_history=20,
)

chain = ConversationChain(llm=ChatOpenAI(), memory=memory)
response = chain.invoke({"input": "Hello, my name is Alice"})

RAG Vector Store

from limbicdb.integrations.langchain import LimbicVectorStore

store = LimbicVectorStore(path="./knowledge.limbic")
store.add_texts(["LimbicDB uses Ebbinghaus decay", "Python SDK supports PostgreSQL"])

retriever = store.as_retriever(k=5)
# Use retriever in any LangChain RetrievalQA chain

LlamaIndex Integration

from limbicdb.integrations.llamaindex import LimbicQueryEngine

engine = LimbicQueryEngine(path="./agent.limbic", top_k=5)
response = engine.query("UI preferences")
print(response.response)
print(response.source_nodes)

# Or as a Reader for VectorStoreIndex
from limbicdb.integrations.llamaindex import LimbicReader
from llama_index.core import VectorStoreIndex

nodes = LimbicReader(path="./agent.limbic").load_data()
index = VectorStoreIndex(nodes)

Cross-Language Interoperability

The Python SDK reads and writes the exact same .limbic format as the TypeScript/Node.js core:

# Python writes
with ldb_open("./shared.limbic") as db:
    db.remember("Written by Python!")

# Node.js reads (TypeScript):
# const db = open('./shared.limbic')
# const result = await db.recall('Python')
# → "Written by Python!"

Enables polyglot Agent architectures:

FastAPI (Python) ←── .limbic ──→ Next.js (TypeScript)

ExplainEngine — Score Formula

Component Formula Weight
Semantic Cosine similarity 50%
Decay Ebbinghaus exp(-t/S) 30%
Repetition Pimsleur sigmoid over access_count 15%
Recency exp(-elapsed_days/7) 5%

Weights are identical to the TypeScript ExplainEngine — cross-language score parity guaranteed.


Running Tests

cd python

uv sync --extra dev

# Unit tests (no PostgreSQL)
uv run pytest tests/test_core.py tests/test_hlc.py tests/test_integrations.py -v

# PostgreSQL integration tests
PG_TEST_URL=postgres://postgres:password@localhost:5432/testdb \
  uv run pytest tests/test_postgres.py -v

# Lint + type check
uv run ruff check src/
uv run mypy src/

Project Layout

python/
├── pyproject.toml
├── src/limbicdb/
│   ├── types.py                  # Memory, Session, MemoryKind, …
│   ├── open.py                   # Convenience open() function
│   ├── core/
│   │   ├── limbicdb.py           # LimbicDB (remember/recall/forget)
│   │   └── explain_engine.py     # ExplainEngine (Ebbinghaus + ACT-R)
│   ├── storage/
│   │   ├── interface.py          # IStorage Protocol
│   │   ├── sqlite_adapter.py     # SQLiteStorageAdapter
│   │   ├── memory_adapter.py     # MemoryStorageAdapter (tests)
│   │   └── postgres_store.py     # PostgresStore (psycopg3 + pgvector)
│   ├── sync/
│   │   └── hlc.py                # HybridLogicalClock
│   └── integrations/
│       ├── langchain.py          # LimbicChatMemory + LimbicVectorStore
│       └── llamaindex.py         # LimbicReader + LimbicQueryEngine
└── tests/
    ├── test_core.py              # 20 core + interop tests
    ├── test_hlc.py               # 12 HLC tests
    ├── test_integrations.py      # 21 LangChain + LlamaIndex tests
    └── test_postgres.py          # 8 PostgreSQL integration tests

License

MIT © Kousoyu

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

limbicdb-5.0.0.tar.gz (259.9 kB view details)

Uploaded Source

Built Distribution

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

limbicdb-5.0.0-py3-none-any.whl (34.4 kB view details)

Uploaded Python 3

File details

Details for the file limbicdb-5.0.0.tar.gz.

File metadata

  • Download URL: limbicdb-5.0.0.tar.gz
  • Upload date:
  • Size: 259.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.11

File hashes

Hashes for limbicdb-5.0.0.tar.gz
Algorithm Hash digest
SHA256 13cc68351f17ed56f0aa38e1f6fd8879e2c4efd191470cbe535cda8d54809116
MD5 f918d1260b4e70a53bf3da5fac2938c8
BLAKE2b-256 dbf0529647ab3d80f2df91c76cea5557dfdd4c66128113f223bd5fa0c5a5df0d

See more details on using hashes here.

File details

Details for the file limbicdb-5.0.0-py3-none-any.whl.

File metadata

  • Download URL: limbicdb-5.0.0-py3-none-any.whl
  • Upload date:
  • Size: 34.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.11

File hashes

Hashes for limbicdb-5.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a4dadf9391c956a84c8fd63d355afa6a61a2e2b09d49e17ec7542e974f0c90f4
MD5 c8eb66f2d7f1ed3df9b4846f7ab047da
BLAKE2b-256 53ddd70fea3ad9da06b16cd0bab5af743025c7367161e6fe4c70c98ccd97ee91

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