-
-
Notifications
You must be signed in to change notification settings - Fork 0
RAG and Memory
Agents remember. Each task pulls the relevant per-user context — past conversation memory plus chunks of uploaded documents — from Qdrant and injects it into the agent prompts. Everything is strictly user-scoped. The logic lives in services/memory_service.py and services/document_service.py.
Two Qdrant collections (see Database-Schema):
| Collection | Holds |
|---|---|
conversation_memories |
Embeddings of past conversation turns |
document_chunks |
Embeddings of uploaded document chunks |
EMBEDDING_DIM = 768, produced by nomic-embed-text via Ollama. Every query is filtered by user_id, so one user's memory can never surface for another.
embed_texts (in llm_service.py) calls the embedding endpoint. It resolves to EMBEDDING_ENDPOINT when set, otherwise falls back to FREE_MODEL_ENDPOINT (the dev default). In production this points at a small dedicated ollama service that serves embeddings only — see Deployment and Configuration. If the embedding endpoint is unreachable, document upload returns 500 and RAG silently degrades, which is why the dedicated prod service exists.
memory_service:
-
add_memory— after a task finalizes, its conversation is embedded and stored (called from the FINALIZE step, see Agent-Orchestration). -
retrieve_memories— at task start, semantically relevant memories are fetched (user-filtered) and formatted into the prompt viaformat_memory_block. -
ensure_collection— lazily creates the collection with the right vector size.
document_service + the /documents endpoints (see API-Reference):
-
ingest— accepts.txt/.mdup toDOCUMENT_MAX_BYTES = 2 MB. Splits withchunk_text(DOCUMENT_CHUNK_SIZE = 1000, overlap 150), embeds each chunk, and writes them todocument_chunks. Document metadata goes to MongoDBdocuments. -
list_documents— lists the user's uploaded documents. -
delete_document— removes the metadata and the associated vector chunks (delete_document_chunks).
task_service._gather_context assembles the RAG context (relevant memories + document chunks) that the orchestrator/main-agent/subagents receive through AgentContext.memory_context. This is how a subagent "knows" what the user discussed before or uploaded.
On account purge, memory_service.purge_user_vectors removes both conversation_memories and document_chunks for the user. This runs before the PostgreSQL row is deleted (purge order Mongo → Qdrant → PG), so vectors are never orphaned. See Security.
Maestro — source repository · Sustainable Use License v1.0 · This wiki documents the current code; where it differs from README.md, the wiki is authoritative.
Overview
Backend
- Backend-Reference
- API-Reference
- Database-Schema
- LLM-Providers-and-BYOK
- Security
- Billing-and-Quota
- RAG-and-Memory
- Realtime-and-WebSockets
Frontend
Operations
Project