Início rápido: Python
O SDK de Python é um cliente síncrono e assíncrono escrito à mão sobre
httpx. Precisa de Python 3.9 ou posterior e de um servidor em execução.
O SDK se chama mnemo-ai-sdk e ainda não está no PyPI. O pacote chamado
mnemosyne-sdk no PyPI pertence a um projeto sem relação: não o instale.
Suba um servidor e crie uma chave
Siga o início rápido com Docker até que
curl http://localhost:3939/health/ready mostre todas as verificações em
ok. Depois crie uma chave:
docker compose exec server node scripts/create-api-key.cjs --label "python"Instale o SDK a partir do repositório
pip install "git+https://github.com/lucasmailland/mnemosyne.git#subdirectory=packages/sdk-python"Primeira chamada
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 devolve um dict simples que corresponde ao JSON do servidor.
Variante assíncrona
AsyncMnemosyneClient tem os mesmos nomes de método. Adicione 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())Integração com 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)Construtor
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 recebe os mesmos parâmetros.
LangChain e LlamaIndex
O pacote não inclui hoje nenhum adaptador para LangChain nem para LlamaIndex.
Chame MnemosyneClient a partir da sua própria classe de retriever ou de
memória.