Skip to main content

lexigram-ai-memory

AI memory system for the Lexigram Framework — episodic, semantic, and working memory


Overview

Three-tier AI memory system for the Lexigram Framework. Provides working, episodic, and semantic memory with pluggable backends, automatic consolidation scheduling, token-aware context assembly, and multi-source retrieval — all wired through the DI container via MemoryModule. Zero-config usage starts with sensible defaults.

Full documentation: docs.lexigram.dev

Install

uv add lexigram-ai-memory
# Optional extras
uv add "lexigram-ai-memory[redis]"

Quick Start

from lexigram import Application
from lexigram.di.module import Module, module

from lexigram.ai.memory import MemoryModule
from lexigram.ai.memory.config import MemoryConfig


@module(imports=[MemoryModule.configure(MemoryConfig(default_backend="in_memory"))])
class AppModule(Module):
    pass


async with Application.boot(modules=[AppModule]) as app:
    # use app.container to resolve services
    ...

Configuration

Zero-config usage: Call MemoryModule.configure() with no arguments to use defaults.

Option 1 — YAML file

# application.yaml
ai_memory:
  default_backend: "vector"
  ttl_seconds: 2592000
  consolidation:
    enabled: true
    interval_seconds: 3600.0

Option 2 — Profiles + Environment Variables (recommended)

export LEX_AI_MEMORY__DEFAULT_BACKEND=vector
# Environment variables for each field

Option 3 — Python

from lexigram.ai.memory.config import MemoryConfig
from lexigram.ai.memory import MemoryModule

config = MemoryConfig(
    default_backend="vector",
)
MemoryModule.configure(config)

Config reference

Field Default Env var Description
enabled True LEX_AI_MEMORY__ENABLED Enable the AI memory subsystem
default_backend "in_memory" LEX_AI_MEMORY__DEFAULT_BACKEND Backend type: in_memory, cache, database, vector
ttl_seconds 2592000 LEX_AI_MEMORY__TTL_SECONDS Default entry TTL in seconds (0 = never expire)
working.system_prompt_tokens 512 LEX_AI_MEMORY__WORKING__SYSTEM_PROMPT_TOKENS Fixed token allocation for system prompt
working.recent_turns_fraction 0.4 LEX_AI_MEMORY__WORKING__RECENT_TURNS_FRACTION Fraction of remaining budget for recent turns
episodic.default_top_k 10 LEX_AI_MEMORY__EPISODIC__DEFAULT_TOP_K Default number of episodes to retrieve
semantic.min_confidence 0.5 LEX_AI_MEMORY__SEMANTIC__MIN_CONFIDENCE Minimum confidence score for stored facts
consolidation.enabled True LEX_AI_MEMORY__CONSOLIDATION__ENABLED Whether automatic background consolidation is active
consolidation.interval_seconds 3600.0 LEX_AI_MEMORY__CONSOLIDATION__INTERVAL_SECONDS How often to run a consolidation pass

Module Factory Methods

Method Description
MemoryModule.configure(config, enable_consolidation) Production-ready module with full consolidation pipeline
MemoryModule.stub(config) Test-friendly module with in-memory backends

Key Features

  • Three-tier memory: Working (context assembly), Episodic (conversation episodes), Semantic (entity facts)
  • Pluggable backends: In-memory, Redis, SQLAlchemy, Qdrant/Chroma/PGVector
  • Token budget allocation: Distributes available tokens across memory sources
  • Automatic consolidation: Background scheduler promotes episodic to semantic storage
  • Multi-source retrieval: Unified MemoryRetriever queries all tiers with relevance ranking
  • Dynamic pruning: DynamicContextPruner fits context into hard token limits

Testing

async with Application.boot(modules=[MemoryModule.stub()]) as app:
    # your test code
    ...

Key Source Files

File What it contains
src/lexigram/ai/memory/module.py MemoryModule — DI module factory methods
src/lexigram/ai/memory/config.py MemoryConfig and tier-specific config classes
src/lexigram/ai/memory/di/provider.py MemoryProvider — wires all protocols and services
src/lexigram/ai/memory/working/manager.py WorkingMemoryManager — context assembly
src/lexigram/ai/memory/episodic/store.py EpisodicMemoryStore — episode storage
src/lexigram/ai/memory/semantic/store.py SemanticMemoryStore — fact storage
src/lexigram/ai/memory/consolidation/consolidator.py MemoryConsolidator — consolidation pipeline
src/lexigram/ai/memory/retrieval/retriever.py MemoryRetriever — multi-source retrieval

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lexigram_ai_memory-0.1.4.tar.gz (67.8 kB view details)

Uploaded Source

Built Distribution

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

lexigram_ai_memory-0.1.4-py3-none-any.whl (59.3 kB view details)

Uploaded Python 3

File details

Details for the file lexigram_ai_memory-0.1.4.tar.gz.

File metadata

  • Download URL: lexigram_ai_memory-0.1.4.tar.gz
  • Upload date:
  • Size: 67.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.14

File hashes

Hashes for lexigram_ai_memory-0.1.4.tar.gz
Algorithm Hash digest
SHA256 fa19fe3bf80ce27ecd0d16fa09460fd0ec955b5fcaa003fb6c64f03edeecfa47
MD5 25efc6ff245dc8a70270f4d38f21fdc3
BLAKE2b-256 3397f6fa09e5746cfa8219994388958893fe6cb14d2ec5ec9a9f1dd060c7c822

See more details on using hashes here.

File details

Details for the file lexigram_ai_memory-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for lexigram_ai_memory-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 f1ccbb22fff618ca51114b8e867e990ac1b6087c83149214955e97238e1ee6af
MD5 a5830e8f9018f7f80ccfab95f4c11cbb
BLAKE2b-256 3095ce4d194948f9ba825edba54dc01bef265c0b786a89d3ef569d86cadcf9cc

See more details on using hashes here.

Release history Release notifications | RSS feed

0.1.5008

1 file

0.1.5003

1 file

0.1.5001

2 files

0.1.3007

1 file

0.1.3006

1 file

0.1.3005

1 file

This release

0.1.4 This release

2 files

0.1.2

1 file

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page