Metadata-Version: 2.4
Name: langchain-memorae
Version: 0.1.0
Summary: MeMorae memory and retrieval adapters for LangChain and LangGraph
Requires-Python: >=3.11
Description-Content-Type: text/markdown
Requires-Dist: httpx<1,>=0.25
Requires-Dist: langchain-core<2,>=0.3
Requires-Dist: langchain-classic<2,>=1
Provides-Extra: test
Requires-Dist: pytest>=8; extra == "test"
Provides-Extra: examples
Requires-Dist: langchain-openai>=0.2; extra == "examples"
Requires-Dist: langgraph>=0.2; extra == "examples"
Requires-Dist: flask>=3; extra == "examples"

# langchain-memorae

Connect an existing LangChain, LangGraph, or local chatbot to MeMorae's project-key API. MeMorae handles ingestion, approval, and retrieval; this package only calls the existing endpoints. The MeMorae backend must already be running.

MCP exposes MeMorae tools to MCP clients. This package provides Python memory and retriever objects for application code using LangChain or LangGraph.

## Install

From the repository root:

```bash
pip install -e integrations/langchain-memorae
```

When published, install with `pip install langchain-memorae`.

## Basic usage

```python
from langchain_memorae import MeMoraeMemory, MeMoraeRetriever

memory = MeMoraeMemory(api_key="MEMORAE_PROJECT_API_KEY",
                       base_url="http://localhost:8000",
                       subject_id="user_123", namespace="default")
context = memory.load_memory_variables({"input": "What food do I like?"})
memory.save_context({"input": "I love pizza"}, {"output": "Got it."})

retriever = MeMoraeRetriever(api_key="MEMORAE_PROJECT_API_KEY",
                             base_url="http://localhost:8000",
                             subject_id="user_123", namespace="default")
docs = retriever.invoke("What sports do I enjoy?")
```

`context["history"]` is a compact string of retrieved memories. `docs` contains LangChain `Document` objects with `memory_id` and `source_ids` metadata. Ingestion is asynchronous on the server; a new message may take time to appear in search. Assistant output is saved only with `save_assistant=True`.

`subject_id` identifies the end user whose memories are recalled. `namespace` separates memory spaces for that user; use the same values for saving and searching. A project API key determines the project scope. Keep it on your server, load it from an environment variable, and never put it in browser code or logs.

## LangGraph

In a graph, call `memory.load_memory_variables({"input": question})` in a recall node before the answer node. Call `memory.save_context({"input": question}, {"output": answer})` in a save node afterward. See [langgraph_chatbot.py](examples/langgraph_chatbot.py) for a complete small graph.

## Local chatbot

Wrap your existing answer function: load `history`, pass it to the function as context, then save the question and answer. See [local_chatbot_flask.py](examples/local_chatbot_flask.py) for a Flask route and [basic_chatbot.py](examples/basic_chatbot.py) for ChatOpenAI. Examples read `MEMORAE_API_KEY`, `MEMORAE_BASE_URL`, and `MEMORAE_SUBJECT_ID` from the environment. The ChatOpenAI examples also need `OPENAI_API_KEY` and their optional dependencies.

`clear()` is a no-op because clearing remote memories is a separate MeMorae review action.
