Skip to main content

LangChain and LangGraph integration for the Mnemosyne memory substrate. BaseChatMessageHistory, BaseMemory, and BaseRetriever adapters with hybrid BM25+vector recall, per-session thread tracking, automatic redaction, TTL support.

Project description

mnemosyne-langchain

PyPI version Python versions License: MIT

LangChain and LangGraph integration for the Mnemosyne memory substrate. MnemosyneChatHistory, MnemosyneRetriever, and MnemosyneMemory classes, with hybrid BM25+vector recall, per-session thread tracking, automatic redaction, and TTL support.

Install

pip install mnemosyne-langchain
# or with the type stubs for full IDE support:
pip install "mnemosyne-langchain[langchain]"

Quick start

import os
from mnemosyne_langchain import MnemosyneChatHistory, MnemosyneRetriever, MnemosyneMemory

os.environ["MNEMOSYNE_API_KEY"] = "mn_..."

# Standalone chat history
history = MnemosyneChatHistory(session_id="alice-1", container_tag="default")
history.add_user_message("Hello!")
history.add_ai_message("Hi, how can I help?")
for m in history.messages:
    print(m)

# Retriever
retriever = MnemosyneRetriever(container_tag="default")
docs = retriever.invoke("Python best practices")
for d in docs:
    print(d.page_content, d.metadata)

# Full memory object
memory = MnemosyneMemory(session_id="alice-1")
vars = memory.load_memory_variables({"input": "what did I ask before?"})
print(vars)
memory.save_context({"input": "thanks!"}, {"output": "you're welcome"})
memory.clear()

With a LangChain chain

from langchain_openai import ChatOpenAI
from langchain.chains import LLMChain
from langchain.prompts import PromptTemplate
from mnemosyne_langchain import MnemosyneMemory

llm = ChatOpenAI(model="gpt-4")
prompt = PromptTemplate(
    input_variables=["history", "context", "input"],
    template="Context:\n{context}\n\nHistory:\n{history}\n\nUser: {input}\nAssistant:",
)
memory = MnemosyneMemory(session_id="alice-1", k=3)
chain = LLMChain(llm=llm, prompt=prompt, memory=memory)

chain.invoke({"input": "remind me what we discussed about caching"})

License

MIT © Geass Labs

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

mnemosyne_langchain-0.1.0.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

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

mnemosyne_langchain-0.1.0-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mnemosyne_langchain-0.1.0.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for mnemosyne_langchain-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1d58c613a1e57c8034c7c77777186db4bd754e6ea2d25515f3ebc78376565fe8
MD5 02bfaf068b6b8471a2bd7d8d6283195c
BLAKE2b-256 7848af43d90eddae343b9cb02da87ac6c1746e7d091535b401ab20d0cc794791

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mnemosyne_langchain-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b2c3b5c35f4edff2bdd109ad663825123ef9a93fa101514c59f783d345133f20
MD5 161a72972ba18e282c241d3dd100f99c
BLAKE2b-256 19245b3bb19a3f2cc1ec949e9b33abcc8a339bad80e80d0f8c5d01224f6442cb

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