Inicio rápido: Python
El SDK de Python es un cliente síncrono y asíncrono escrito a mano sobre
httpx. Necesita Python 3.9 o posterior y un servidor en marcha.
El SDK se llama mnemo-ai-sdk y todavía no está en PyPI. El paquete llamado
mnemosyne-sdk en PyPI pertenece a un proyecto ajeno: no lo instales.
Levanta un servidor y crea una clave
Sigue el inicio rápido con Docker hasta que
curl http://localhost:3939/health/ready muestre todas las comprobaciones en
ok. Luego crea una clave:
docker compose exec server node scripts/create-api-key.cjs --label "python"Instala el SDK desde el repositorio
pip install "git+https://github.com/lucasmailland/mnemosyne.git#subdirectory=packages/sdk-python"Primera llamada
from mnemo import MnemosyneClient
client = MnemosyneClient(
url="http://localhost:3939",
api_key="mns_live_...",
)
client.create_fact("Acme prefers communication in Spanish.", tags=["language"])
result = client.recall("what language should we use with Acme?", top_k=3)
for hit in result["hits"]:
print(hit["score"], hit["content"])Cada método devuelve un dict simple que coincide con el JSON del servidor.
Variante asíncrona
AsyncMnemosyneClient tiene los mismos nombres de método. Agrega await.
import asyncio
from mnemo import AsyncMnemosyneClient
async def main() -> None:
async with AsyncMnemosyneClient(
url="http://localhost:3939",
api_key="mns_live_...",
) as client:
result = await client.recall("what language should we use with Acme?", top_k=3)
for hit in result["hits"]:
print(hit["score"], hit["content"])
asyncio.run(main())Integración con FastAPI
from fastapi import FastAPI, Depends
from mnemo import MnemosyneClient
app = FastAPI()
def get_memory():
return MnemosyneClient(
url="http://localhost:3939",
api_key="mns_live_...",
)
@app.post("/agents/recall")
def agent_recall(query: str, client: MnemosyneClient = Depends(get_memory)):
return client.recall(query, top_k=5)Constructor
MnemosyneClient(
url, # required: server base URL
api_key, # required: sent as a bearer token
timeout=30.0, # per-request timeout in seconds
user_agent_suffix=None, # appended to the User-Agent header
max_retries=3, # extra attempts on 429, 500, 502, 503 and 504
)AsyncMnemosyneClient recibe los mismos parámetros.
LangChain y LlamaIndex
El paquete no incluye hoy ningún adaptador para LangChain ni para LlamaIndex.
Llama a MnemosyneClient desde tu propia clase de retriever o de memoria.