FastAPI Copilot Doc is an offline Retrieval-Augmented Generation (RAG) system that indexes FastAPI markdown documentation and answers developer questions by grounding responses in the indexed docs.
- Document loading & chunking via
src.indexing.create_chunks - Indexing pipeline (walk markdowns → chunks → store) via
src.indexing.initiate_indexing_process - FAISS vector store for retrieval (index saved to
./faiss_index) viasrc.indexing.vector_storeandsrc.vector_store.get_vector_store - HuggingFace embeddings (sentence-transformers/all-MiniLM-L6-v2) used in
src.indexing/src.vector_store - Agent with middleware that injects retrieval context into prompts:
src.agent.agent+src.middleware.prompt_with_context - URL verification tool for citations:
src.tools.validate_fastapi_doc_url - Interactive CLI QA bot:
src.rag.initiate_qa_bot - Local loader test:
src.test_load_and_chunking.py
- Retrieval-Augmented Generation (RAG) with embeddings + FAISS
- Vector store operations and similarity search via
src.vector_store.retrieve_similar_documents - Agents, middleware, and tools (see
src.agent.agent,src.middleware.prompt_with_context,src.tools.validate_fastapi_doc_url) - Middleware for summarization & retry:
SummarizationMiddleware,ModelRetryMiddleware(configured insrc.agent) - Streaming responses via the agent (used in
src.rag)
Prerequisites
- Python version (see .python-version)
- Copy
.env.example→.envand set required provider keys: .env.example - Project deps are defined in pyproject.toml
Install & run (using uv package manager as provided)
- Install dependencies:
uv install- Index the docs (creates / updates
./faiss_index):
uv run python -m src.indexingThis runs src.indexing.initiate_indexing_process which loads markdown files and calls src.indexing.vector_store.
- Run the interactive QA bot:
uv run python -m src.ragNotes:
- If you prefer not to use
uv, you can use your systempython(e.g.,python -m src.indexing). - Ensure environment variables for your LLM provider are set in
.envbefore running the agent.
- The project uses LangChain agents and middleware (
src.agent,src.middleware), so it is straightforward to plug into LangSmith for monitoring and run management. - To use LangSmith:
- Configure a LangSmith-compatible LLM or client in
src.agent.agent. - Set
LANGSMITH_API_KEY(and other LangSmith settings) in.env. - Optionally route agent run logs / traces to LangSmith for inspection and debugging.
- Configure a LangSmith-compatible LLM or client in
- Because the project splits retrieval (
src.vector_store) and agent logic (src.agent+src.middleware), swapping to a LangSmith-orchestrated workflow is localized and minimal.
Files of interest:
- src/indexing.py — loader, chunking, and indexing
- src/vector_store.py — vector store access & retrieval
- src/middleware.py — prompt context injection
- src/agent.py — agent setup & middleware
- src/tools.py — URL validation tool
- src/rag.py — interactive CLI QA bot
- pyproject.toml | .env.example