Skip to main content

Agnostic Memory Management Library for Local AI (Ollama, LM Studio, vLLM, etc)

Project description

AILocalMemory 🧠

Agnostic Memory Management Library for Local AI.

AILocalMemory is a lightweight Python library designed to handle chat history, state persistence, and context window optimization for any local AI endpoint (Ollama, LM Studio, vLLM, Llama.cpp, etc.).

Since most local AI instances are stateless, AILocalMemory handles the tedious parts of conversational AI: storing past messages, truncating them when they get too long (so your AI doesn't crash from OOM), and abstracting the API calls.

Installation

pip install -e .

Quick Start (Using Adapters)

The easiest way to use the library is via built-in adapters.

from ailocalmemory import ChatSession, OllamaAdapter

# 1. Initialize a session (keeps messages in memory by default)
session = ChatSession(session_id="user_1")

# 2. Wrap it with an adapter (e.g., Ollama)
chat = OllamaAdapter(model="llama3", memory_session=session)

# 3. Chat! The adapter automatically handles context saving and retrieving.
response = chat.send("Hello, my name is Alice and my favorite color is blue.")
print("AI:", response)

response = chat.send("What is my name and favorite color?")
print("AI:", response) # It remembers!

Pure Agnostic Usage

If you prefer calling the AI endpoint yourself, you can use AILocalMemory purely as a state manager:

from ailocalmemory import ChatSession

session = ChatSession(session_id="user_1", storage="sqlite")
session.add_user_message("What is the capital of France?")

# Get the optimized context (truncated to fit model limits)
context = session.get_context()

# ... send `context` to your AI engine of choice ...
response_text = "Paris"

session.add_assistant_message(response_text)

Storage Options

  • memory (Default): Volatile, lost when script ends.
  • sqlite: Persistent, saves to a local ailocalmemory.db file automatically.

Optimizers

By default, the session uses TokenLimitOptimizer(max_tokens=2048) to ensure your context doesn't explode. You can also use SlidingWindowOptimizer to just keep the last $K$ messages.

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

ailocalmemory-0.1.0.tar.gz (9.7 kB view details)

Uploaded Source

Built Distribution

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

ailocalmemory-0.1.0-py3-none-any.whl (10.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ailocalmemory-0.1.0.tar.gz
  • Upload date:
  • Size: 9.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.3

File hashes

Hashes for ailocalmemory-0.1.0.tar.gz
Algorithm Hash digest
SHA256 4dffca8ef2e31248fffe3944593727e436cf3effe25ab75e23473ec1e3b11b0a
MD5 0edab053cb68538fa55ef6500c794ed9
BLAKE2b-256 6704f76b247a4bdb9ad4fde15e09699f27fd2b2c34e2b66210804cb920d4be72

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ailocalmemory-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.3

File hashes

Hashes for ailocalmemory-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1726589170c4840451d35ca42549b3a983bcdb0770e824eb6ab783aa4e2199f2
MD5 c87366914c858c3161826e13a7ce8a92
BLAKE2b-256 a3b6f64ccd297033680ec41da82b5dd3351b447a597993b393b8a78326256aad

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