LightMem (lmem) Python SDK
Ultra-Fast Local AI Agent Persistent Memory Engine with Neural Extractive QA, Multimodal BLOB Vault & Knowledge Graph.
LightMem combines SQLite WAL + FTS5 BM25 with lazy-initialized ONNX vector search (fastembed), local ONNX Extractive QA (minilm-squad2 / tinyroberta-squad2) & swappable Ollama rerankers (ollama:<model>), immutable SHA-256-verified multimodal BLOB attachments (images, audio, video, documents), Obsidian-grade [[wikilinks]] & multi-hop knowledge graph traversal, nearest-neighbor conflict merging, and temporal point-in-time (as_of) & single-day (date) queries — with zero Python dependencies.
⚡ Quickstart
Installation
pip install lmem
Python SDK Usage
from lmem import LightMem
# Initialize vault (defaults to ~/.lightmem/memories.db or custom db_path)
lm = LightMem()
# 1. Store a memory (auto-infers across 14 categories if omitted)
memory = lm.remember(
"PostgreSQL primary runs on port 5432 with WAL archiving enabled",
category="fact",
title="PostgreSQL Primary Config",
tags=["postgres", "database", "production"],
confidence=0.95,
)
print("Stored memory:", memory.id)
# 2. Store Multimodal Attachments (images, audio, 4K video, PDFs in isolated 0600 SQLite BLOB vault)
diagram = lm.remember(
"API Gateway routes to [[PostgreSQL Primary Config]]",
files=["./ingress-architecture.png"],
tags=["architecture", "gateway"],
extract=False, # True to invoke configured LLM for visual/document summary extraction
)
# 3. Hybrid Search (FTS5 BM25 + Vector Cosine RRF + Graph Multi-Hop & Media Filter)
results = lm.recall("postgres port", limit=5, multi_hop=True)
for r in results:
print(f"[{r.score:.2f}] {r.memory.title}: {r.memory.content}")
# Materialize verified attachment file paths directly on disk
image_paths = lm.recall("gateway", media="image", limit=1, path=True)
inspected_paths = lm.inspect(diagram.id, path=True)
# 4. Neural Extractive QA (exact fact extraction via ONNX SQuAD-2.0 or Ollama)
answer = lm.answer("what port does postgresql use?")
print("Extracted answer:", answer.answer) # "5432"
print("Confidence:", answer.confidence)
print("Reranker:", answer.reranker_used)
# 5. Conversational Observation & Atomic Fact Extraction
candidates = lm.observe(
"User: We switched Redis to port 6380.\nAssistant: Updated!",
dry_run=True,
)
for c in candidates:
print(f"[{c.category}] {c.title}: {c.content}")
# 6. Intentional Knowledge Graph Linking & Multi-Hop Traversal
lm.link(diagram.id, memory.id, relation="depends_on", weight=1.0)
related = lm.related(memory.id, hops=2)
for rel in related:
print(f"Hop {rel.distance}: {rel.memory.title} via {' -> '.join(rel.relation_path)}")
# 7. Conflict Detection, Deduplication & Vault Telemetry
conflicts = lm.conflicts(min_similarity=0.80)
stats = lm.stats()
print(f"Active memories: {stats.active_memories} | Vectors: {stats.vector_count}")
# 8. Deploy Skill to AI Agents (Antigravity, Codex, Hermes, Cursor, Claude)
lm.connect("antigravity")
🧩 Python SDK Reference (LightMem)
| Method | Description |
|---|---|
lm.remember(content, ..., files=None, extract=False, supersede=False) |
Store a memory and optional binary attachments (files=[...]), auto-linking [[wikilinks]]. |
lm.recall(query, limit=5, category=None, media=None, multi_hop=False, path=False) |
Hybrid BM25 + Cosine RRF search; returns List[ScoredMemory] or List[str] file paths when path=True. |
lm.answer(question, category=None, reranker=None, as_of=None, date=None) |
Extractive QA via local ONNX (minilm-squad2, tinyroberta-squad2), ollama:<model>, or top1. |
lm.observe(input_text_or_path, yes=False, dry_run=False, reranker=None) |
Extract atomic candidate memories from dialogue transcripts or notes. |
lm.inspect(memory_id, *extra_ids, save_to=None, path=False) |
Inspect full record + graph links + attachments, or materialize verified file paths (path=True). |
lm.list(page=None, limit=20, category=None, media=None, path=False) |
Paginated chronological listing (PaginatedList or List[str] paths when path=True). |
lm.link(source, target, relation="relates_to", weight=1.0) |
Create or update a directional knowledge graph edge. |
lm.unlink(source, target, relation=None) |
Remove a directional edge between two memories. |
lm.related(memory_id, hops=2) |
Breadth-first multi-hop traversal with hop-decay scoring. |
lm.graph(focus=None, hops=2) |
Export full or neighborhood knowledge graph {nodes, edges}. |
lm.conflicts(yes=False, min_similarity=0.78, reranker=None) |
Detect (and optionally auto-merge with yes=True) conflicting or near-duplicate memories. |
lm.deduplicate() |
Smart-merge exact duplicate memories. |
lm.forget(memory_id, hard=False) |
Soft-expire (hard=False) or permanently purge (hard=True, cascading BLOBs & cached files). |
lm.stats() |
Vault telemetry (StorageStats: active/expired counts, vector count, categories, DB size). |
lm.connect(platform=None, workspace=False, path=None) |
Install SKILL.md to AI coding agents (antigravity, codex, hermes, cursor, claude, all). |
💻 CLI Commands (Included)
The pip install lmem package also installs the standalone lmem (and lightmem) CLI:
lmem remember "Redis cache runs on port 6379" -t fact
lmem remember "Itachi 4K wallpaper" -f ./itachi-4k.mp4 --extract
lmem observe conversation.txt --yes
lmem recall "redis port" -l 5 --multi-hop
lmem recall "itachi" -m video -l 1 --path
lmem inspect <ID> --paths
lmem answer "what is my pan card no"
lmem link <SRC_ID> <DST_ID> -r "depends_on"
lmem related <ID> --hops 2
lmem graph --focus <ID> --hops 2
lmem conflicts
lmem connect all
📄 License
MIT License. Created by Pathi Krishna Kanth.
Metadata
Release files for lmem 0.3.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| lmem-0.3.1.tar.gz | 11.2 kB | With provenance | Details |
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| lmem-0.3.1-py3-none-win_amd64.whl | Python 3 | none | Windows x86-64 | Details |
| lmem-0.3.1-py3-none-manylinux2014_x86_64.whl | Python 3 | none | Linux glibc 2.17+ x86-64 | Details |
| lmem-0.3.1-py3-none-macosx_11_0_arm64.whl | Python 3 | none | macOS 11.0+ ARM64 | Details |
Total release size: 38.4 MB
Release files / lmem-0.3.1.tar.gz
| Download URL | lmem-0.3.1.tar.gz |
|---|---|
| Size | 11.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f10bf613e7fb2ded54ec6012864071d22ad997a9ded74e8e31ebbd82ef3f6232
|
|
BLAKE2b-256 checksum How to use checksums |
e526fa09666c5977f9359a0b26e9f293436078225e856b830bb913d8b08174a9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 16, 2026.
Transparency logRelease files / lmem-0.3.1-py3-none-win_amd64.whl
| Download URL | lmem-0.3.1-py3-none-win_amd64.whl |
|---|---|
| Size | 12.2 MB |
| Tags | Python 3 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
3c8329b71b1bbfb32fc9e14bcd792b654a5869e596dc8ce9bcac9f3d0b66c6f6
|
|
BLAKE2b-256 checksum How to use checksums |
d54ecbfb2bfdd2421e4a7402b7b0498cfea9893770afbc44d7134cd31bcc1dc7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 16, 2026.
Transparency logRelease files / lmem-0.3.1-py3-none-manylinux2014_x86_64.whl
| Download URL | lmem-0.3.1-py3-none-manylinux2014_x86_64.whl |
|---|---|
| Size | 14.3 MB |
| Tags | Linux glibc 2.17+ x86-64 Python 3 |
|
SHA-256 checksum How to use checksums |
f6ec0960797796c52b05df1e66db52314e93f19a215bdb2670fa698e7b133441
|
|
BLAKE2b-256 checksum How to use checksums |
9e6540c3d54202e90b740efb9ae3f853e09b52061feedbe86782f99c8b580134
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 16, 2026.
Transparency logRelease files / lmem-0.3.1-py3-none-macosx_11_0_arm64.whl
| Download URL | lmem-0.3.1-py3-none-macosx_11_0_arm64.whl |
|---|---|
| Size | 11.8 MB |
| Tags | Python 3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
532b73c42f017550fc7f08e9e0576f540cb70036a6a16e167cc3ee1c4428dfb8
|
|
BLAKE2b-256 checksum How to use checksums |
909c488d11029933c957c64d0bc9f10a339608cc89fd9ca531a0a7f9c18220cf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 16, 2026.
Transparency logSecurity for lmem 0.3.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 4 files in this release have been uploaded with provenance metadata.
Attestation for lmem-0.3.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 16, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.