Skip to main content

A brain-inspired, dynamic memory system for AI applications

Project description

neural-memory

A brain-inspired, dynamic memory layer for AI applications.

Most AI systems treat memory as a static store — embed text, retrieve by similarity. neural-memory goes further: memories have importance scores, decay over time, get reinforced on access, and can be automatically merged or abstracted into higher-level concepts.

from neural_memory import MemorySystem
from neural_memory.providers import LocalProvider

mem = MemorySystem(provider=LocalProvider())

mem.store("The user prefers concise responses.")
mem.store("Project deadline is 2026-05-01", importance=0.9)

results = mem.recall("How should I respond to the user?")
print(results[0].memory.content)
# → "The user prefers concise responses."

Installation

No API key required (local embeddings):

pip install neural-ai-memory[local]

With OpenAI:

pip install neural-ai-memory[openai]

With Anthropic (Claude):

pip install neural-ai-memory[anthropic,local]

Providers

Provider Embeddings LLM scoring Requires
LocalProvider sentence-transformers heuristic neural-memory[local]
OpenAIProvider text-embedding-3-small gpt-4o-mini neural-memory[openai]
AnthropicProvider sentence-transformers Claude Haiku neural-memory[anthropic,local]
from neural_memory.providers import OpenAIProvider, AnthropicProvider

# OpenAI
mem = MemorySystem(provider=OpenAIProvider(api_key="sk-..."))

# Anthropic
mem = MemorySystem(provider=AnthropicProvider(api_key="sk-ant-..."))

# Custom: subclass BaseLLMProvider and implement embed(), score_importance(), complete()

API

store(content, importance=None, context=None, tags=None, metadata=None) → Memory

Ingest and persist a piece of information. Importance is scored automatically unless overridden.

mem.store("Alice is the project lead", tags=["team"])
mem.store("Deploy by Friday", importance=0.95, metadata={"source": "slack"})

store_many(contents, importance=None, ...) → List[Memory]

Batch ingest — embeddings computed in one call instead of N. Significantly faster for large imports.

facts = ["Fact one", "Fact two", "Fact three"]
memories = mem.store_many(facts, importance=0.7)

recall(query, top_k=5, context=None, min_importance=0.0) → List[RetrievalResult]

Retrieve the most relevant memories. Scoring combines semantic relevance, importance, and recency.

results = mem.recall("Who is responsible for deployment?", top_k=3)
for r in results:
    print(f"{r.final_score:.2f}  {r.memory.content}")

forget(memory_id)

Permanently delete a memory.

mem.forget(memory.id)

run_maintenance() → dict

Trigger lifecycle operations manually (also runs automatically every 50 stores):

  • Decay — importance drops for memories not accessed recently
  • Prune — memories below threshold are deleted
  • Merge — highly similar memories are combined into one
  • Abstract — clusters of related memories become a single concept
summary = mem.run_maintenance()
# → {"decayed": 12, "pruned": 3, "merged": 2, "abstracted": 1}

stats() → MemoryStats

s = mem.stats()
print(s.total_memories, s.avg_importance, s.by_category)

Configuration

from neural_memory import MemorySystem, MemoryConfig, LifecycleConfig, RetrievalWeights

config = MemoryConfig(
    persist_directory="./my_memory",
    retrieval=RetrievalWeights(relevance=0.5, importance=0.3, recency=0.2),
    lifecycle=LifecycleConfig(
        decay_rate=0.05,           # importance lost per day of inactivity
        decay_threshold=0.05,      # memories below this are pruned
        merge_similarity_threshold=0.92,
        abstraction_cluster_size=5,
        auto_maintenance_interval=50,
    ),
    use_llm_importance_scoring=True,
    recency_half_life_days=7.0,
)

mem = MemorySystem(provider=LocalProvider(), config=config)

Architecture

store(text)
    │
    ▼
IngestionLayer          normalize, tag detection, metadata
    │
    ▼
EncodingLayer           embed, importance score, category classification
    │
    ├──▶ VectorStorage  ChromaDB — semantic search
    ├──▶ KVStorage      dict/JSON — fast ID lookup
    └──▶ GraphStorage   networkx — relationship tracking

recall(query)
    │
    ▼
RetrievalEngine         weighted score: relevance × 0.5 + importance × 0.3 + recency × 0.2
    │
    ▼
LifecycleManager        reinforce accessed memories

run_maintenance()
    │
    ├── decay + prune
    ├── merge similar pairs
    └── abstract clusters → concept memories

Async API

Every method has an async equivalent — safe to use in FastAPI, asyncio, or any async framework:

from neural_memory import MemorySystem
from neural_memory.providers import LocalProvider

mem = MemorySystem(provider=LocalProvider())

# In an async function:
m = await mem.astore("Deadline is Friday", importance=0.9)
results = await mem.arecall("When is the deadline?")
await mem.aforget(m.id)
summary = await mem.arun_maintenance()

# Batch async:
memories = await mem.astore_many(["Fact A", "Fact B", "Fact C"])

Auto-maintenance triggered by store() always runs in a background thread — it never blocks the calling code.


Extending

Implement BaseLLMProvider to add any embedding or LLM backend:

from neural_memory import BaseLLMProvider, MemorySystem

class MyProvider(BaseLLMProvider):
    def embed(self, text: str) -> list[float]:
        ...

    def score_importance(self, content: str, context=None) -> float:
        ...

    def complete(self, prompt: str) -> str:
        ...

mem = MemorySystem(provider=MyProvider())

License

MIT

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

neural_ai_memory-0.2.0.tar.gz (29.1 kB view details)

Uploaded Source

Built Distribution

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

neural_ai_memory-0.2.0-py3-none-any.whl (32.2 kB view details)

Uploaded Python 3

File details

Details for the file neural_ai_memory-0.2.0.tar.gz.

File metadata

  • Download URL: neural_ai_memory-0.2.0.tar.gz
  • Upload date:
  • Size: 29.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for neural_ai_memory-0.2.0.tar.gz
Algorithm Hash digest
SHA256 14df3065165fe12d2bca91f0625497a3acc5ce5cc84305f0af12fc76231c93cc
MD5 88a0a49e42e6a463e4e71ef6435597bc
BLAKE2b-256 89e9bc39374ba2cb951b3299e09ddbd6ea69a4cd9d78c3734996a92e5edc594f

See more details on using hashes here.

File details

Details for the file neural_ai_memory-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for neural_ai_memory-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c474c816b061618f7b78514c02163e072e2c7eb2ab174a91f462bd6984901de6
MD5 d27ee02fe55ed9149a7b4b012202a8f2
BLAKE2b-256 126cb585906b5c92f54a923dd3b075857a68ec992dc816edac8a74b5c2f0d1ef

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