This project has been archived by its maintainers, and is no longer receiving any updates.
Lightweight and extensible memory layer for LLMs.
Important Disclaimer: This library is intended to be production-ready, but currently is in active development.
🔥 Key Features
- Framework agnostic: Use your preferred AI agent framework.
- Own infrastructure: Use your preferred cloud provider. No third-party api keys; your data, your rules.
- Multiple backends: Move from your local POC to production deployment, seamlessly (SQLite, MongoDB, PostgreSQL).
- Sync and async api: Highly compatible with modern and legacy frameworks.
- No forced schema: As long it is a list of json serializable objects.
- Resumable memory: Perfect for chat applications and REST APIs
- Robust: Get production-ready code with minimal effort.
⚙️ Installation
From pypi
pip install memx-lm
Or clone the repo and install it
pip install .
🚀 Quickstart
OpenAI
Simple conversation with OpenAI Python library
# https://platform.openai.com/docs/guides/conversation-state?api-mode=responses
# tested on openai==2.6.1
from openai import OpenAI
from memx.memory.sqlite import SQLiteMemory
sqlite_uri = "sqlite+aiosqlite:///message-storage.db"
m1 = SQLiteMemory(sqlite_uri, "memx-messages")
client = OpenAI()
m1.sync.add([{"role": "user", "content": "tell me a good joke about programmers"}])
first_response = client.responses.create(
model="gpt-4o-mini", input=m1.sync.get(), store=False
)
print(first_response.output_text)
m1.sync.add(
[{"role": r.role, "content": r.content[0].text} for r in first_response.output]
)
m1.sync.add([{"role": "user", "content": "tell me another"}])
second_response = client.responses.create(
model="gpt-4o-mini", input=m1.sync.get(), store=False
)
m1.sync.add(
[{"role": r.role, "content": r.content[0].text} for r in second_response.output]
)
print(f"\n\n{second_response.output_text}")
print(m1.sync.get())
Pydantic AI
Message history with async Pydantic AI + Gemini
import asyncio
import os
import orjson
from memx.memory.sqlite import SQLiteMemory
from pydantic_ai import Agent, ModelMessagesTypeAdapter
from pydantic_ai.models.google import GoogleModel
from pydantic_ai.providers.google import GoogleProvider
# Reference: https://ai.pydantic.dev/message-history/
# Initialize the GoogleProvider for Vertex AI
PROJECT = os.getenv("GCP_PROJECT_ID")
LOCATION = os.getenv("GCP_LOCATION")
provider = GoogleProvider(
vertexai=True, project=PROJECT, location=LOCATION
)
model = GoogleModel(
model_name="gemini-2.0-flash",
provider=provider,
)
agent = Agent(model)
async def main():
sqlite_uri = "sqlite+aiosqlite:///message_store.db"
m1 = SQLiteMemory(sqlite_uri, "my-messages")
result1 = await agent.run('Where does "hello world" come from?')
# it is your responsibility to add the messages as a list[dict]
messages = orjson.loads(result1.new_messages_json())
await m1.add(messages) # messages: list[dict] must be json serializable
session_id = m1.get_id()
print("Messages added with session_id: ", session_id)
# resume the conversation from 'another' memory
m2 = SQLiteMemory(sqlite_uri, "my-messages", session_id=session_id)
old_messages = ModelMessagesTypeAdapter.validate_python(await m2.get())
print("Past messages:\n", old_messages)
result2 = await agent.run(
"Could you tell me more about the authors?", message_history=old_messages
)
print("\n\nContext aware result:\n", result2.output)
if __name__ == "__main__":
asyncio.run(main())
You can change the memory backend with minimal modifications. Same api to add and get messages.
from memx.memory.mongodb import MongoDBMemory
from memx.memory.postgres import PostgresMemory
from memx.memory.sqlite import SQLiteMemory
# SQLite backend
sqlite_uri = "sqlite+aiosqlite:///message_store.db"
m1 = SQLiteMemory(sqlite_uri, "my-messages")
# PostgreSQL backend
pg_uri = "postgresql+psycopg://admin:1234@localhost:5433/test-database"
m2 = PostgresMemory(pg_uri, "memx-messages")
# MongoDB backend
mongodb_uri = "mongodb://admin:1234@localhost:27017"
m3 = MongoDBMemory(uri=mongodb_uri, database="memx-test", collection="memx-messages")
Tasks
- Add mongodb backend
- Add SQLite backend
- Add Postgres backend
- Add redis backend
- Add tests
- Publish on pypi
- Add full sync support
- Add docstrings
Metadata
Release files for memx-lm 0.1.7
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 | |
|---|---|---|---|---|
| memx_lm-0.1.7.tar.gz | 6.7 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| memx_lm-0.1.7-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 18.3 kB
Release files / memx_lm-0.1.7.tar.gz
| Download URL | memx_lm-0.1.7.tar.gz |
|---|---|
| Size | 6.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8f8e8266bb62ae1da43f5840a9273f1b779a61834dcf59f8a9796ab9b2f9ef1e
|
|
BLAKE2b-256 checksum How to use checksums |
105d9cc687a2184ed26bba1a46632638b591833d9133f2cdb345f0779676d4f1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.5
|
Release files / memx_lm-0.1.7-py3-none-any.whl
| Download URL | memx_lm-0.1.7-py3-none-any.whl |
|---|---|
| Size | 11.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c90b8c9b8240ff5cf163572e5a8d14d1d12751d2711d8982e7df8c313135e7ad
|
|
BLAKE2b-256 checksum How to use checksums |
9dc0672ae8fba364011739155e8524d6ff6dcd1fa7e7f8896c92cda595cc99cd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.5
|
Security for memx-lm 0.1.7
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A 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.
To learn more about protecting yourself from malicious actors, visit our package security documentation.