This document tracks the setup, planning, and development progress of the Intelligent Dialog System project.
- File Integration & Workflow: Unified
software_developer.mdintoGEMINI.mdto establish a strict, plan-driven development workflow. Createdphases/andfixes/directories to house.jsonplan files. - Phase 1 Completion: Successfully implemented the core logic POC, including data ingestion from local text files and a terminal-based RAG chat interface. Marked
phases/phase_1.jsonas complete. - Git Initialization: Initialized a Git repository and configured
.gitignoreto exclude sensitive files, local data, and IDE settings. - Dependency Management: Refactored
environment.ymlto be the single source of truth for Conda environment setup, pointing torequirements.txtfor pip packages.
To handle external web-based knowledge sources, a sophisticated, three-stage ingestion pipeline was designed and implemented.
-
Stage 1: Metadata-Aware Crawling (
crawler.py):- Problem: Initial attempts to crawl websites failed because they required JavaScript to render content.
- Solution: The crawler was re-implemented using Playwright (a headless browser) to ensure full page rendering.
- Features:
- Reads URLs from
data/data_sources.json. - Infers metadata (jurisdiction, year, doc_type) from the source.
- Saves the fully-rendered HTML in a structured JSON format (
DK-LAW-2023-835.json) todata/crawled/structured/. - Resumable: Tracks progress in
data/crawled/progress.jsonto avoid re-crawling completed URLs.
- Reads URLs from
-
Stage 2: Processing (
processor.py):- Features:
- Reads the structured JSON files produced by the crawler.
- Uses
BeautifulSoupto parse the HTML and extract clean text. - Preserves line breaks to maintain document structure.
- Saves the clean, original-language text to
_dk.txtfiles indata/crawled/processed/. - Resumable: Uses
progress.jsonto skip already-processed files.
- Features:
-
Stage 3: Translation (
translator.py):- Problem: Translation was initially attempted on a per-chunk basis, which was inefficient. A
ModuleNotFoundErroralso blocked progress due to dependency conflicts. - Solution:
- The dependency conflict was resolved by upgrading
langchainandlangchain-google-genaito their latest compatible versions. - The script was re-designed to perform document-level translation for much greater efficiency.
- The dependency conflict was resolved by upgrading
- Features:
- Reads the clean
_dk.txtfiles. - Uses the
gemini-pro-latestLLM to translate the entire document's text to English. - Saves the translated text to
_en.txtfiles indata/crawled/processed/. - Resumable: Uses
progress.jsonto skip already-translated files.
- Reads the clean
- Problem: Translation was initially attempted on a per-chunk basis, which was inefficient. A
The following critical bugs were resolved during development:
- Missing
text_keyArgument: FixedTypeErrorinWeaviateVectorStoreinitialization. NoneEmbedding: Ensured user queries are vectorized before similarity search.gemini-proModel Not Found: Updated to a stable, versioned model name (gemini-1.0-proand latergemini-pro-latest).- Weaviate Connection
ResourceWarning: Refactored client handling to ensure connections are properly closed. - JavaScript Rendering Failure: Replaced
requestswithPlaywrightin the crawler. langchain_coreModuleNotFoundError: Resolved dependency conflicts by upgradinglangchainpackages.
The project successfully migrated its vector store from Weaviate to Qdrant to streamline the setup and improve performance.
-
Rationale:
- Simplified Setup: Qdrant's Docker setup is more straightforward.
- Compatibility: The
langchain-qdrantlibrary is well-maintained and integrates seamlessly with the existing LangChain components.
-
Implementation:
- New Module: Created
src/vector_store/qdrant_db.pyto manage the Qdrant client and retriever, centralizing the connection logic. - Updated Ingestion: Refactored
src/ingestion/ingest.pyto use the new Qdrant module, ensuring documents are correctly chunked and ingested into a Qdrant collection. - Updated RAG Chain: Modified
src/agent/router.pyto use the Qdrant retriever, seamlessly integrating the new vector store into the RAG chain. - Dependency Management: Updated
requirements.txtto includelangchain-qdrantandqdrant-client, and removedweaviate-client.
- New Module: Created
The following critical bugs were resolved during development:
ValueError: models/embedding-001 is not among supported models: Updated the embedding model to a supported version (models/text-embedding-004).AttributeError: 'QdrantClient' object has no attribute 'search': Corrected theQdrantVectorStoreinitialization to use theembeddingparameter instead ofembeddings.TypeError: Client.__init__() got an unexpected keyword argument 'client': Refactored the Qdrant client instantiation to correctly pass the client object.404 Not Found: Collection ... doesn't exist!: Ensured the Qdrant collection is created before documents are added.ModuleNotFoundErroron startup: Corrected the import paths and now run the main script as a module (python -m src.main).- Missing
text_keyArgument: FixedTypeErrorinWeaviateVectorStoreinitialization. NoneEmbedding: Ensured user queries are vectorized before similarity search.gemini-proModel Not Found: Updated to a stable, versioned model name (gemini-1.0-proand latergemini-pro-latest).- Weaviate Connection
ResourceWarning: Refactored client handling to ensure connections are properly closed. - JavaScript Rendering Failure: Replaced
requestswithPlaywrightin the crawler. langchain_coreModuleNotFoundError: Resolved dependency conflicts by upgradinglangchainpackages.
- Moved Gemini model-related files (
GEMINI_MODELS.md,list_gemini_models.py) to a dedicatedsrc/gemini/directory. - Created a
src/vector_store/directory to house the Qdrant database module.