docs: add comprehensive RAG search architecture documentation - #536
Open
flexocode442 wants to merge 1 commit into
Open
docs: add comprehensive RAG search architecture documentation#536flexocode442 wants to merge 1 commit into
flexocode442 wants to merge 1 commit into
Conversation
…stia#481) Document the RAG pipeline used by /index/message and /search endpoints: - Architecture diagrams for indexing and retrieval pipelines - Step-by-step flow for both endpoints - OpenAI usage: text-embedding-3-small for search vs gpt-4o-mini for chat (independent systems) - Data scope and conversation isolation via Weaviate filters - Error handling table for all failure scenarios (503, 422, etc.) - Privacy considerations: conversation isolation at DB query level - Dependencies reference with version requirements - Current integration status: /search is standalone, not yet integrated into /chat prompts OpenAI usage is documented separately from the LLM chat pipeline so future contributors understand the two distinct API roles.
|
@flexocode442 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
This PR adds comprehensive architecture documentation for the RAG (Retrieval-Augmented Generation) / semantic search pipeline that powers the
/index/messageand/searchendpoints in the Clicked AI Agent.Problem Statement
The Clicked AI Agent has a sophisticated RAG pipeline for semantic message search — users can search their conversation history using natural language queries, finding messages by meaning rather than exact keywords. However, this pipeline was completely undocumented:
/searchexists but is NOT wired into/chatpromptsThis documentation addresses every one of these gaps. It is written for two audiences: (1) new contributors who need to understand the architecture before modifying it, and (2) future feature developers who need to know how to wire
/searchresults into the/chatLLM prompt.Production Impact
Without this documentation, every new contributor must reverse-engineer the RAG pipeline by reading
main.py. This documentation:gpt-4o-minifor search instead oftext-embedding-3-small)/searchis standalone and not yet integrated into/chat— preventing confusion about why chat doesn't use RAG contextRelated Issue
Closes #481
Changes
[ADD]
apps/ai_agent/docs/concepts-rag-search-architecture.md(186 lines)A single Markdown document in the
docs/directory following the project's existing documentation conventions (alongsideapi-index-search.md,api-chat.md, etc.).Document Structure
The document is organized into 9 clearly-labeled sections:
POST /index/messageGET /searchtext-embedding-3-small) vs chat completions (gpt-4o-mini)/searchis NOT yet integrated into/chat; describes the intended 3-step integration patternfastapi,openai,weaviate-client,uvicornwith version constraintsArchitecture Diagrams (Section 2)
ASCII diagrams that render in any text viewer:
Indexing Pipeline:
Retrieval Pipeline:
Indexing Pipeline: Step-by-Step (Section 3)
Documents every step of
POST /index/message:messageId,conversationId,senderId,contentweaviate.connect_to_local()"Message"collection if first messagecontent→openai_client.embeddings.create(input=content, model="text-embedding-3-small")→ 1536-dimensional vectormessageId(handles edited messages)Key detail documented: Only
contentis embedded. Metadata fields (messageId,conversationId,senderId) are stored as filterable Weaviate properties but are NOT part of the embedding vector.Retrieval Pipeline: Step-by-Step (Section 4)
Documents every step of
GET /search:qandconversationId{"results": []}immediately if no messages indexed (avoids unnecessary OpenAI call)weaviate.connect_to_local()q→ sametext-embedding-3-smallmodelnear_vectorwithFilter.by_property("conversationId").equal(conversationId), limit 5messageId,conversationId,senderId,contentOpenAI Usage Documentation (Section 5)
Explicitly documents that embeddings and chat completions are independent systems:
text-embedding-3-small/index/message,/searchopenai_client.embeddings.create(input=..., model="text-embedding-3-small")gpt-4o-mini/chat,/transfers/analyse,/proposals/summariseopenai_client.chat.completions.create(model="gpt-4o-mini", messages=...)Important note in the doc: These share the same
OPENAI_API_KEYenvironment variable but serve different architectural roles. The embedding model is never used for chat, and the chat model is never used for search. Confusing them would cause runtime errors (wrong API endpoints) and architectural mistakes.Current Integration Status (Section 6)
Honest documentation of the current gap:
The
/chatendpoint uses onlygpt-4o-miniwith a static system prompt. It does NOT call/searchto retrieve relevant messages for RAG context injection.The intended future integration pattern is documented as a 3-step recipe:
POST /index/messageGET /search?q=<user query>&conversationId=<conv>This transparency prevents contributors from assuming RAG is already wired in and wasting time debugging why chat doesn't use search results.
Privacy & Data Scope (Section 7)
Documents the security boundary:
Filter.by_property("conversationId").equal(conversationId)content → OpenAI API → Weaviate (vector + text)Error Handling Reference (Section 8)
Operators can look up exactly what each HTTP response means:
/index/messageBehavior/searchBehavior"Weaviate connection failed""Weaviate connection failed""OPENAI_API_KEY is not configured""OPENAI_API_KEY is not configured"{"results": []}Dependencies Reference (Section 9)
fastapi>=0.135.1/index/messageand/searchopenai>=1.0.0text-embedding-3-small) + chat completionsweaviate-client>=4.0.0uvicorn>=0.42.0Documentation Quality Properties
main.pyimplementationpyproject.tomldependencies/searchintegration gap rather than implying it worksapi-index-search.md,api-chat.md, etc.Files Changed
apps/ai_agent/docs/concepts-rag-search-architecture.mdDesign Decisions
rag-indexing.md+rag-retrieval.md)/chatcould waste hours. Documenting the gap explicitly saves that time and points to the intended solution.conversationIdfilter is a security boundary. Documenting it as database-level filtering ensures contributors understand it's not application-level (which could be bypassed).docs/alongside existing docsdocs/architecture/directoryapi-index-search.md,api-chat.mdare indocs/). No new directory structure needed.Verification
This is a documentation-only PR — no code changes. Verification consists of:
1. Content Accuracy
All code paths and API calls documented match the actual implementation in
main.py:POST /index/messageflowmain.py/index/messagehandlerGET /searchflowmain.py/searchhandlertext-embedding-3-smallmain.pyembedding callgpt-4o-minimain.pychat callconnect_to_local()main.pyWeaviate setupFilter.by_property("conversationId")main.pysearch filtermain.pylimit=5main.pyexception handlermain.pykey check2. Dependency Versions
pyproject.tomlfastapi>=0.135.10.135.1openai>=1.0.01.xweaviate-client>=4.0.04.xuvicorn>=0.42.00.42.03. Markdown Rendering
The document uses standard GitHub-Flavored Markdown with:
)code)4. Documentation Style Consistency
concepts-rag-search-architecture.md(alongsideapi-index-search.md,api-chat.md)main.py(e.g., "embedding", "vector", "collection")Acceptance Criteria
main.pypyproject.tomltext-embedding-3-small,gpt-4o-miniverifiedapps/ai_agent/docs/alongsideapi-index-search.mdOut of Scope
/searchinto/chat: This PR documents the existing architecture and the current gap. Implementing the RAG integration into chat is a separate feature PR.main.pyor any source code: Pure documentation change.docs/directory structure.api-index-search.md: That doc covers the API reference (endpoints, params, responses). This doc covers the concept and architecture. They complement each other without overlap.