Skip to main content

Open-source, model-agnostic memory layer for LLMs

Project description

mindlayer

PyPI version CI License: MIT Python 3.9+

Open-source, model-agnostic memory layer for LLMs.

Drop mindlayer into any LLM application to give it persistent, structured memory — no API key required, no infrastructure to run, no vendor lock-in.

import mindlayer

with mindlayer.MemCore() as mem:
    mem.add("My name is Alice. I prefer dark mode and I work in Python.")
    results = mem.search("programming preferences")
    for r in results:
        print(r.content)

Why mindlayer?

Most LLM apps lose context between sessions. Vector databases are heavy to set up. Existing memory libraries tie you to a specific LLM or cloud service.

mindlayer is:

  • Zero config — SQLite storage, works out of the box
  • Model agnostic — plug in any LLM or use the built-in Gemma extractor
  • Pure library — no daemon, no background process, no ports
  • Open source — MIT licensed, runs fully offline

Installation

pip install mindlayer-ai

With semantic vector search (downloads ~130MB embedding model on first use):

pip install "mindlayer-ai[vector]"

With LLM-powered extraction (downloads Gemma ~800MB on first use):

pip install "mindlayer-ai[llm]"

Architecture

mindlayer uses a 3-layer memory model inspired by human cognition:

Layer Description Promoted when
Working Short-term, recent facts accessed 3+ times
Episodic Mid-term, frequently used facts accessed 10+ times
Semantic Long-term, core knowledge stays permanently

5 core primitives

Primitive What it does
Ingestion Extracts discrete facts from raw text
Consolidation Promotes memories across layers
Decay Reduces scores on idle memories, prunes stale ones
Retrieval Fetches relevant memories, boosts access count
Conflict resolution Deduplicates near-duplicate memories

Usage

Default (rule-based extractor, no LLM needed)

import mindlayer

mem = mindlayer.MemCore()
mem.add("I am a Python developer. I love open source.")
results = mem.search("developer")

With semantic vector search (best recall)

# pip install "mindlayer[vector]"
mem = mindlayer.MemCore(use_vector=True)
mem.add("I prefer concise explanations and dislike verbose output.")
results = mem.search("communication style")  # matches semantically, not just by keyword

With Gemma LLM extractor (best quality)

mem = mindlayer.MemCore(use_llm=True)
# Downloads gemma-3-1b-it-Q4_K_M.gguf (~800MB) on first run
mem.add("Long conversation text with lots of context...")

Bring your own LLM extractor

from mindlayer.extractors.base import BaseExtractor

class MyExtractor(BaseExtractor):
    def extract(self, text: str) -> list[str]:
        # call OpenAI, Anthropic, Ollama, anything
        return ["fact 1", "fact 2"]

mem = mindlayer.MemCore(extractor=MyExtractor())

Custom storage backend

from mindlayer.storage.base import BaseStorage

class PostgresStorage(BaseStorage):
    # implement the interface
    ...

mem = mindlayer.MemCore(storage=PostgresStorage())

Memory maintenance

mem.consolidate()   # promote memories based on access patterns
mem.decay()         # decay and prune stale memories

Roadmap

  • Vector similarity search (FAISS / sqlite-vec)
  • Async support
  • PostgreSQL storage backend
  • LLM-based conflict resolution
  • REST API server mode
  • JavaScript / TypeScript port

Contributing

Contributions are welcome. Please open an issue before submitting large PRs.

git clone https://github.com/Genious07/mindlayer
cd mindlayer
pip install -e ".[dev,vector]"
pytest

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

mindlayer-0.1.0.tar.gz (14.0 kB view details)

Uploaded Source

Built Distribution

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

mindlayer-0.1.0-py3-none-any.whl (15.0 kB view details)

Uploaded Python 3

File details

Details for the file mindlayer-0.1.0.tar.gz.

File metadata

  • Download URL: mindlayer-0.1.0.tar.gz
  • Upload date:
  • Size: 14.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for mindlayer-0.1.0.tar.gz
Algorithm Hash digest
SHA256 76659490b605275628e8507439c68ebd0820df8a5ca5be25c2ae7f9e41266a38
MD5 d94ae6deacc6fa5be19a99dad6e1d42c
BLAKE2b-256 2601a17bd1ff92bf2541386bb4b4c484eaca9fc1b21ab99eff7849f0ddac0359

See more details on using hashes here.

File details

Details for the file mindlayer-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: mindlayer-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 15.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for mindlayer-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7a8d3d0af7ca9630b9afb64bbaa5916ff50747d58bce872788bf9fdcb3d00a91
MD5 1225b4623dc3964fe9a1cb238909318a
BLAKE2b-256 86ddd98f65d681f8b3ca57c052e2bb735dd6e963e7514e6a888b021b1fa7b6ca

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