Official Python SDK for MemHQ — a Mem0-style drop-in memory layer for AI agents.
Project description
memhq — Python SDK for MemHQ
The official Python client for MemHQ, a drop-in memory
layer for AI agents. Same shape as Mem0, with a built-in synthesis pass
(ask()) for cited answers.
Install
pip install memhq
Quickstart
import os
from memhq import MemoryClient
client = MemoryClient(api_key=os.environ["MEMHQ_API_KEY"])
# 1. Add — auto-creates the user + default thread
client.add(
messages=[{"role": "user", "content": "I'm a vegetarian, allergic to nuts."}],
user_id="user_123",
)
# 2. Search — hybrid retrieval (BM25 + vector + graph)
results = client.search("dietary restrictions", user_id="user_123")
for memory in results:
print(memory.score, memory.content)
# 3. Ask — synthesized answer with citations
answer = client.ask("What should I avoid eating?", user_id="user_123")
print(answer.text)
for cit in answer.citations:
print(" •", cit.content)
Async
import asyncio
from memhq import AsyncMemoryClient
async def main():
async with AsyncMemoryClient() as client: # picks up MEMHQ_API_KEY
await client.add(
messages=[{"role": "user", "content": "I live in Brooklyn"}],
user_id="user_123",
)
result = await client.ask("Where does the user live?", user_id="user_123")
print(result.text)
asyncio.run(main())
Configuration
| Env var | Default | Notes |
|---|---|---|
MEMHQ_API_KEY |
(required) | Get one from the dashboard. |
MEMHQ_BASE_URL |
https://api.memhq.ai |
Override for self-host or local dev. |
# Self-hosted MemoryOS or local development
client = MemoryClient(api_key="...", base_url="http://localhost:3000")
Reference
client.add(messages, *, user_id, group_id=None, metadata=None) -> AddResult
Ingest one or more messages into the user's memory graph. Extraction runs asynchronously on the server — typically completes in under three seconds.
client.search(query, *, user_id=None, group_ids=None, limit=10) -> SearchResult
Hybrid search across the user's graph plus any shared group graphs. Returns
an iterable SearchResult; each element is a Memory(id, content, type, score).
client.ask(question, *, user_id=None, group_ids=None, limit=8) -> AskResult
Retrieve, rerank, and synthesize a cited answer. Returns an AskResult with
answer (alias: text) and a list of Citation(id, content).
client.users.get(user_id), client.users.delete(user_id), client.users.list()
User management. user_id accepts the external id you passed to add().
License
Apache-2.0.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file memhq-0.1.0.tar.gz.
File metadata
- Download URL: memhq-0.1.0.tar.gz
- Upload date:
- Size: 12.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
935e0df81d02a8d342785ded5f390b427945e317339e5173983df61dd8c30ab2
|
|
| MD5 |
41b346d3e64884642db12048f2af0585
|
|
| BLAKE2b-256 |
d4142b1f63770a3b7304ad645ea02f9d96b2dff263f2d31b9b12e2ba018713cc
|
File details
Details for the file memhq-0.1.0-py3-none-any.whl.
File metadata
- Download URL: memhq-0.1.0-py3-none-any.whl
- Upload date:
- Size: 13.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3ef280f71122d4e39564b06e58e48540003fceded3c0fef3955bebaf19f06e6a
|
|
| MD5 |
0d97a2c10255f83dd2258576d7bc7100
|
|
| BLAKE2b-256 |
0f0dee0be90f0e2b5dfc64fd6f7b5cf6d5c7b4f166a4ce0cca85e23a1d904701
|