|
Download PHASE_2_INGESTION.md from aimprabu/RAG_Documentation_Assistant: direct link, hf CLI and curl.
- Browser
- Download file 8.51 kB
-
https://huggingface.co/spaces/aimprabu/RAG_Documentation_Assistant/resolve/main/PHASE_2_INGESTION.md
- Command line
-
hf download hf://spaces/aimprabu/RAG_Documentation_Assistant/PHASE_2_INGESTION.md
-
curl -L -o PHASE_2_INGESTION.md https://huggingface.co/spaces/aimprabu/RAG_Documentation_Assistant/resolve/main/PHASE_2_INGESTION.md
8.51 kB
PHASE_2_INGESTION.md — Phase 2: Document Ingestion Pipeline
RAG-Based Technical Documentation Assistant
1. Phase Goal
- Business Goal: Process and store technical source documents so they are available for vector search queries.
- Technical Goal: Create loader utilities for local files and URLs, construct a recursive character text splitter, build local sentence-transformer and ChromaDB vector store wrappers, and implement a CLI seed script.
- Completion Criteria: Running the ingestion script loads all test markdown documents inside the corpus directory, generates embeddings, stores them inside ChromaDB, and registers them in SQLite database.
2. Scope
Included
- Abstract interfaces for loaders, embeddings, and vector stores.
- Local Markdown/PDF/TXT loader and remote URL fetch loader.
- Recursive splitting utility ensuring code-block integrity.
- Embedding model adapter loading
sentence-transformers/all-MiniLM-L6-v2locally. - ChromaDB vector store adapter configured for persistent database operations.
- Document registration repository (
app/repositories/document_repository.py). - Ingestion manager service orchestrating the process.
- Seed script
ingestion/ingest_corpus.py. - Standard markdown corpus documents (
fastapi_tutorial.md,pydantic_v2.md,langgraph_concepts.md,langchain_tools.md).
Excluded
- LangGraph nodes and StateGraph assembly.
- FastAPI endpoints.
- Feedback storage interactions.
3. Dependencies
- Phase 1 completed successfully.
- Database tables initialized.
4. Deliverables
app/infrastructure/vector_store/base.pyapp/infrastructure/vector_store/chroma.pyapp/infrastructure/embeddings/base.pyapp/infrastructure/embeddings/sentence_transformers.pyapp/infrastructure/document_loader/base.pyapp/infrastructure/document_loader/file_loader.pyapp/infrastructure/document_loader/url_loader.pyapp/repositories/document_repository.pyapp/services/ingestion_service.pyapp/utils/chunking.pyapp/utils/hashing.pyingestion/ingest_corpus.pycorpus/(containing target markdown files)
5. Sub-Phases
Phase 2.1: Infrastructure Adapters (Embeddings & Vector Store)
- Goal: Create wrappers around local sentence transformers and ChromaDB.
- Tasks:
- Define base interfaces for embedding model and vector store.
- Write sentence-transformer implementation loading the model locally.
- Write ChromaDB vector store adapter. Configure PersistentClient with similarity metric
cosine.
- Files:
app/infrastructure/embeddings/base.pyapp/infrastructure/embeddings/sentence_transformers.pyapp/infrastructure/vector_store/base.pyapp/infrastructure/vector_store/chroma.py
- Acceptance Criteria: Running a simple python script instantiates the embedding model and performs local cosine similarity searches using ChromaDB.
- Verification: Embed a single text string and verify the resulting vector dimension is 384.
Phase 2.2: Document Loaders & Splitters
- Goal: Extract raw text from files or URLs and partition them into semantically consistent chunks.
- Tasks:
- Define base interface for document loaders.
- Write local file loader that parses
.md,.txt,.html,.pdf. - Write remote URL loader that fetches and parses web content.
- Write
app/utils/chunking.pyutilizingRecursiveCharacterTextSplitterwith separators prioritizing code fences and paragraph boundaries. - Write
app/utils/hashing.pycomputing SHA256 checksums to detect duplicate uploads.
- Files:
app/infrastructure/document_loader/base.pyapp/infrastructure/document_loader/file_loader.pyapp/infrastructure/document_loader/url_loader.pyapp/utils/chunking.pyapp/utils/hashing.py
- Acceptance Criteria: Text chunks respect boundary constraints and do not break code formatting blocks. Duplicate files are identified by their SHA256 hashes.
- Verification: Parse a test file and assert the chunk size and counts match criteria.
Phase 2.3: Ingestion Service & CLI Runner
- Goal: Coordinate loading, chunking, embedding, database storage, and registry transactions.
- Tasks:
- Write document database repository (
app/repositories/document_repository.py). - Write orchestration manager service (
app/services/ingestion_service.py) tracking task states. - Write corpus runner CLI
ingestion/ingest_corpus.pyloading target documents.
- Write document database repository (
- Files:
app/repositories/document_repository.pyapp/services/ingestion_service.pyingestion/ingest_corpus.py
- Acceptance Criteria: CLI execution indexes all markdown docs in the corpus directory, inserts meta records in SQLite, and writes chunks to ChromaDB.
- Verification: Run CLI pipeline and run verification assertions.
6. AI Build Prompt (AI_BUILD_PROMPT.md)
# AI Build Prompt: Phase 2 (Ingestion)
## Goal
Implement the document ingestion pipeline. This includes loading, chunking, embedding, vector store storage, duplicate checking, and catalog registry.
## Files to Create/Modify
- **app/infrastructure/embeddings/base.py**: Abstract class EmbeddingModelBase.
- **app/infrastructure/embeddings/sentence_transformers.py**: Implements EmbeddingModelBase using local `sentence-transformers/all-MiniLM-L6-v2`.
- **app/infrastructure/vector_store/base.py**: Abstract class VectorStoreBase.
- **app/infrastructure/vector_store/chroma.py**: Implements VectorStoreBase using `chromadb.PersistentClient`.
- **app/infrastructure/document_loader/base.py**: Abstract class DocumentLoaderBase.
- **app/infrastructure/document_loader/file_loader.py**: File loader supporting `.md`, `.txt`, `.html` (and optionally simple `.pdf` parsing).
- **app/infrastructure/document_loader/url_loader.py**: URL loader fetching HTML content using `httpx` and stripping tags using `BeautifulSoup` (or regex).
- **app/utils/chunking.py**: Function `split_text(text: str, chunk_size: int, overlap: int) -> List[str]` wrapping `RecursiveCharacterTextSplitter`.
- **app/utils/hashing.py**: Hash helper: `calculate_sha256(content: bytes) -> str`.
- **app/repositories/document_repository.py**: Database operations on `documents` table: `insert_document()`, `get_document_by_hash()`, `list_documents()`, `delete_document()`.
- **app/services/ingestion_service.py**: Ingestion manager coordinating document loaders, splitting, hashing, embedding generations, ChromaDB inserts, and SQLite registrations. Handles duplicate checks.
- **ingestion/ingest_corpus.py**: Python CLI script that loops through the files in `corpus/` and invokes IngestionService to seed the vector store.
## Constraints
- Ensure ChromaDB persistently writes to config property `CHROMA_PERSIST_DIR`.
- Embedding models must load locally without making online network calls during queries.
- Recursive character text splitter should use separators `["\n\n", "\n", "```", ".", " ", ""]` to keep code blocks intact.
## Acceptance Criteria
- Run a verification script verifying indexed files count in SQLite database and vectors count in ChromaDB matches.
7. Verification Package
Manual Verification
- Setup seed corpus files in
corpus/folder. - Run ingestion command:
python ingestion/ingest_corpus.py - Run verification check query:
python -c "import sqlite3; conn = sqlite3.connect('data/registry.db'); print(conn.cursor().execute('SELECT filename, chunk_count, status FROM documents').fetchall())"
Expected Results
- The ingest runner prints indexing status for all documents.
- The check query output displays a list containing filenames, their respective chunk counts, and
indexedstatus. - ChromaDB directory
./chroma_dbis created containing index assets.
Failure Conditions
- ChromaDB query fails with database mismatch errors.
- Duplicate files are ingested twice instead of being skipped.
8. Review Gates
- local sentence-transformer models load without network errors.
- Document hash deduplication handles uploads correctly.
- Markdown files parsed and chunk size remains within limits.
- SQLite registry records track files states.
- Clean log records printed during chunking and vector storage.