Skip to main content

memhq-langchain

MemHQ adapter for LangChain (Python). Drop-in chat message history and retriever backed by the MemHQ hosted API. Sync and async both supported via httpx.

Install

pip install memhq-langchain

Quickstart — Chat history

import os
from langchain_openai import ChatOpenAI
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
from langchain_core.runnables.history import RunnableWithMessageHistory

from memhq_langchain import MemHQChatMessageHistory

model = ChatOpenAI(model="gpt-4o-mini")
prompt = ChatPromptTemplate.from_messages([
    ("system", "You have access to the user's memory."),
    MessagesPlaceholder("history"),
    ("human", "{input}"),
])

chain = RunnableWithMessageHistory(
    prompt | model,
    lambda session_id: MemHQChatMessageHistory(
        api_key=os.environ["MEMHQ_API_KEY"],
        session_id=session_id,
        user_id="user_42",
    ),
    input_messages_key="input",
    history_messages_key="history",
)

reply = chain.invoke(
    {"input": "What's my favorite coffee order?"},
    config={"configurable": {"session_id": "conv_42"}},
)

Quickstart — Retriever

from memhq_langchain import MemHQRetriever

retriever = MemHQRetriever(
    api_key=os.environ["MEMHQ_API_KEY"],
    user_id="user_42",
    limit=8,
)

docs = retriever.invoke("pricing discussions")

Configuration

Argument Description
api_key MemHQ project API key. Falls back to MEMHQ_API_KEY.
user_id External user id. Required.
session_id Thread anchor for the history adapter.
recall_limit Memories surfaced per history read. Default 10.
limit Memories returned per retriever query. Default 10.
mode "hybrid" (default), "vector", or "lexical".
base_url Override the API base.

Reference

Full reference: https://docs.memhq.ai/sdks/langchain-py

Metadata

Release files for memhq-langchain 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for memhq-langchain 0.1.0
File Size Uploaded
memhq_langchain-0.1.0.tar.gz 9.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for memhq-langchain 0.1.0
File Interpreter ABI Platform
memhq_langchain-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 20.1 kB

Release files / memhq_langchain-0.1.0.tar.gz

Download URL memhq_langchain-0.1.0.tar.gz
Size 9.3 kB
Tags Source
SHA-256 checksum
How to use checksums
c1dabae72c5e318e497d0172ef06c18915aba7b7a4762e7acb66504bdcfb7e64
BLAKE2b-256 checksum
How to use checksums
cd978930a90139bf96d65fd4e9d44cd80c3dd0ed94dec1099c1840ebe497a24a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.8

Release files / memhq_langchain-0.1.0-py3-none-any.whl

Download URL memhq_langchain-0.1.0-py3-none-any.whl
Size 10.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2067175ab00b67d275f73cc2c4c192985c2ffb3535e37f192fba465d8392fb5a
BLAKE2b-256 checksum
How to use checksums
d7aa37be87e173c4b9e111f831329ac69710aaa4536548d03e17db40798c705a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.8

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release 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