Runbook: RAG & Memory (Phase 2)¶
Operating hybrid retrieval, re-ranking, grounded answers, and per-agent memory.
Prerequisites¶
docker compose up -d # Qdrant + Postgres (memory) + the rest
ollama serve # llama3.2:3b + nomic-embed-text
aop diagnose # qdrant + postgres OK
A corpus must be ingested first (Phase 1):
Retrieval & answers¶
# Hybrid (dense+sparse, RRF) then re-rank
aop rag search "how does hybrid retrieval work?" -c docs -k 5
# Grounded, cited answer
aop rag ask "what is re-ranking and why use it?" -c docs
# Per-agent scope (physical collection: agent7__docs)
aop rag ask "..." --namespace agent7 -c docs
- Re-ranker selection: Cohere when
AOP_COHERE_API_KEYis set, else a local cross-encoder (downloadsms-marco-MiniLM-L-6-v2~80 MB on first use). - Embedding backend for the query must match ingest (
--embed-backend hffor collections built with late chunking).
Conversation memory¶
aop memory add user "My project is KRONOS and I prefer Python" -n agent7 -s s1
aop memory add assistant "Noted." -n agent7 -s s1
aop memory context --query "what language do I prefer?" -n agent7 -s s1
aop memory chat "remind me about my project" -n agent7 -s s1 # memory-aware reply
Memory tiers: durable log (Postgres) + working window (token budget) + summary
compression (LLM) + episodic recall (Qdrant mem__<namespace>).
Troubleshooting¶
| Symptom | Cause | Fix |
|---|---|---|
rag search empty |
wrong collection/namespace or backend mismatch | aop collections; match --namespace / --embed-backend. |
| cross-encoder import error | embeddings extra missing |
pip install -e ".[embeddings]". |
| memory commands error on Postgres | stack not up | docker compose up -d; aop diagnose. |
| answers ignore context | corpus not ingested into that collection | ingest first (Phase 1). |
Tuning (settings / .env)¶
AOP_RAG_CANDIDATES (hybrid candidates), AOP_RAG_TOP_K (kept after rerank),
AOP_RRF_K (fusion constant), AOP_MEMORY_WINDOW_TOKENS,
AOP_EPISODIC_RECALL_K, AOP_COHERE_RERANK_MODEL, AOP_CROSS_ENCODER_MODEL.