Spaces:
Running
Running
Commit ·
2304e6f
1
Parent(s): e9912bc
add something
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .dockerignore +94 -0
- .env +19 -0
- .env.example +22 -0
- Dockerfile +39 -0
- __init__.py +0 -0
- __pycache__/__init__.cpython-312.pyc +0 -0
- __pycache__/__init__.cpython-314.pyc +0 -0
- __pycache__/agent.cpython-312.pyc +0 -0
- __pycache__/agent.cpython-314.pyc +0 -0
- __pycache__/api.cpython-312.pyc +0 -0
- __pycache__/api.cpython-314.pyc +0 -0
- __pycache__/config.cpython-312.pyc +0 -0
- __pycache__/config.cpython-314.pyc +0 -0
- __pycache__/logging_config.cpython-312.pyc +0 -0
- __pycache__/logging_config.cpython-314.pyc +0 -0
- __pycache__/main.cpython-312.pyc +0 -0
- __pycache__/retrieve.cpython-312.pyc +0 -0
- __pycache__/retrieve.cpython-314.pyc +0 -0
- __pycache__/utils.cpython-312.pyc +0 -0
- __pycache__/utils.cpython-314.pyc +0 -0
- agent +0 -0
- agent.py +361 -0
- agent_direct_run.log +26 -0
- agent_sdk_docs.md +0 -0
- agent_test.log +4 -0
- agent_uvicorn.log +96 -0
- agent_uvicorn_new.log +87 -0
- api.py +194 -0
- check_collection.py +61 -0
- check_detailed.py +36 -0
- config.py +27 -0
- exceptions.py +26 -0
- extract_sitemap.py +32 -0
- history/prompts/frontend-chat-integration/4-implementation.tasks.prompt.md +56 -0
- ingestion.log +0 -0
- local_test.log +23 -0
- logging_config.py +77 -0
- main.py +434 -0
- pyproject.toml +12 -0
- requirements.txt +16 -0
- retrieve.log +577 -0
- retrieve.py +408 -0
- sitemap_urls.txt +40 -0
- test_local.py +118 -0
- test_run.log +32 -0
- test_simple.log +18 -0
- test_urls.txt +3 -0
- tests/fixtures/sample_page.html +30 -0
- utils.py +54 -0
- validate.py +60 -0
.dockerignore
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Python
|
| 2 |
+
__pycache__/
|
| 3 |
+
*.py[cod]
|
| 4 |
+
*$py.class
|
| 5 |
+
*.so
|
| 6 |
+
.Python
|
| 7 |
+
env/
|
| 8 |
+
venv/
|
| 9 |
+
ENV/
|
| 10 |
+
build/
|
| 11 |
+
develop-eggs/
|
| 12 |
+
dist/
|
| 13 |
+
downloads/
|
| 14 |
+
eggs/
|
| 15 |
+
.eggs/
|
| 16 |
+
lib/
|
| 17 |
+
lib64/
|
| 18 |
+
parts/
|
| 19 |
+
sdist/
|
| 20 |
+
var/
|
| 21 |
+
wheels/
|
| 22 |
+
*.egg-info/
|
| 23 |
+
.installed.cfg
|
| 24 |
+
*.egg
|
| 25 |
+
|
| 26 |
+
# Environment
|
| 27 |
+
.env
|
| 28 |
+
.env.local
|
| 29 |
+
.env.*.local
|
| 30 |
+
|
| 31 |
+
# IDE
|
| 32 |
+
.vscode/
|
| 33 |
+
.idea/
|
| 34 |
+
*.swp
|
| 35 |
+
*.swo
|
| 36 |
+
*~
|
| 37 |
+
|
| 38 |
+
# Logs
|
| 39 |
+
*.log
|
| 40 |
+
logs/
|
| 41 |
+
*.log.*
|
| 42 |
+
|
| 43 |
+
# Testing
|
| 44 |
+
.pytest_cache/
|
| 45 |
+
.coverage
|
| 46 |
+
htmlcov/
|
| 47 |
+
.tox/
|
| 48 |
+
|
| 49 |
+
# OS
|
| 50 |
+
.DS_Store
|
| 51 |
+
Thumbs.db
|
| 52 |
+
|
| 53 |
+
# Git
|
| 54 |
+
.git/
|
| 55 |
+
.gitignore
|
| 56 |
+
.gitattributes
|
| 57 |
+
|
| 58 |
+
# Documentation
|
| 59 |
+
README.md
|
| 60 |
+
*.md
|
| 61 |
+
|
| 62 |
+
# Test files
|
| 63 |
+
test_*.py
|
| 64 |
+
*_test.py
|
| 65 |
+
tests/
|
| 66 |
+
test_urls.txt
|
| 67 |
+
|
| 68 |
+
# Agent files (large binary)
|
| 69 |
+
agent
|
| 70 |
+
|
| 71 |
+
# Specific log files
|
| 72 |
+
agent_direct_run.log
|
| 73 |
+
agent_test.log
|
| 74 |
+
agent_uvicorn_new.log
|
| 75 |
+
agent_uvicorn.log
|
| 76 |
+
ingestion.log
|
| 77 |
+
local_test.log
|
| 78 |
+
retrieve.log
|
| 79 |
+
test_run.log
|
| 80 |
+
test_simple.log
|
| 81 |
+
validate_rag.log
|
| 82 |
+
|
| 83 |
+
# Scripts not needed in production
|
| 84 |
+
check_collection.py
|
| 85 |
+
check_detailed.py
|
| 86 |
+
extract_sitemap.py
|
| 87 |
+
test_local.py
|
| 88 |
+
validate_rag.py
|
| 89 |
+
validate.py
|
| 90 |
+
retrieve.py
|
| 91 |
+
main.py
|
| 92 |
+
|
| 93 |
+
# Data files
|
| 94 |
+
sitemap_urls.txt
|
.env
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Cohere API key for embedding generation
|
| 2 |
+
COHERE_API_KEY="fYDA4euHeuxeMn2FmfxGqLqWyG8PN16BjLT0N4O9"
|
| 3 |
+
|
| 4 |
+
# Qdrant Cloud connection details
|
| 5 |
+
QDRANT_URL="https://d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io:6333"
|
| 6 |
+
QDRANT_API_KEY="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhY2Nlc3MiOiJtIn0.xIHDfcROMhK4TPiIr4Q-P5yKHaofGf41M0FmQbxvJdE"
|
| 7 |
+
QDRANT_COLLECTION=book_embeddings
|
| 8 |
+
|
| 9 |
+
# Deployment vercel
|
| 10 |
+
DEPLOY_VERCEL_URL="https://humanoid-ai-robotics-book-1.vercel.app" # /sitemap.xml
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
# ⚠️ IMPORTANT: Replace with your own OpenAI API key with available quota
|
| 14 |
+
# Current key has insufficient quota - get a new key from: https://platform.openai.com/api-keys
|
| 15 |
+
# OPENAI_API_KEY="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"
|
| 16 |
+
# AGENT_MODEL="gpt-4o-mini"
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
# OPENROUTER_API_KEY="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"
|
.env.example
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Cohere API key for embedding generation
|
| 2 |
+
# Get your key from: https://dashboard.cohere.com/api-keys
|
| 3 |
+
COHERE_API_KEY="fYDA4euHeuxeMn2FmfxGqLqWyG8PN16BjLT0N4O9"
|
| 4 |
+
|
| 5 |
+
# Qdrant Cloud connection details
|
| 6 |
+
# Get these from your Qdrant Cloud dashboard
|
| 7 |
+
QDRANT_URL="https://d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io:6333"
|
| 8 |
+
QDRANT_API_KEY="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhY2Nlc3MiOiJtIn0.xIHDfcROMhK4TPiIr4Q-P5yKHaofGf41M0FmQbxvJdE"
|
| 9 |
+
QDRANT_COLLECTION="book_embeddings"
|
| 10 |
+
|
| 11 |
+
# Deployment URL (optional - used for documentation references)
|
| 12 |
+
DEPLOY_VERCEL_URL="https://humanoid-ai-robotics-book-1.vercel.app" # /sitemap.xml
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
# OpenAI API key for the agent
|
| 16 |
+
# Get your key from: https://platform.openai.com/api-keys
|
| 17 |
+
# ⚠️ Ensure your key has available quota (not expired or exhausted)
|
| 18 |
+
# OPENAI_API_KEY="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"
|
| 19 |
+
# AGENT_MODEL="gpt-4o-mini"
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
# OPENROUTER_API_KEY="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"
|
Dockerfile
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Use Python 3.11 slim image for smaller size
|
| 2 |
+
FROM python:3.11-slim
|
| 3 |
+
|
| 4 |
+
# Set working directory
|
| 5 |
+
WORKDIR /app
|
| 6 |
+
|
| 7 |
+
# Set environment variables
|
| 8 |
+
ENV PYTHONUNBUFFERED=1 \
|
| 9 |
+
PYTHONDONTWRITEBYTECODE=1 \
|
| 10 |
+
PIP_NO_CACHE_DIR=1 \
|
| 11 |
+
PIP_DISABLE_PIP_VERSION_CHECK=1
|
| 12 |
+
|
| 13 |
+
# Install system dependencies
|
| 14 |
+
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 15 |
+
build-essential \
|
| 16 |
+
curl \
|
| 17 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 18 |
+
|
| 19 |
+
# Copy requirements first for better caching
|
| 20 |
+
COPY requirements.txt .
|
| 21 |
+
|
| 22 |
+
# Install Python dependencies
|
| 23 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 24 |
+
|
| 25 |
+
# Copy application code
|
| 26 |
+
COPY . .
|
| 27 |
+
|
| 28 |
+
# Create necessary directories
|
| 29 |
+
RUN mkdir -p /app/logs
|
| 30 |
+
|
| 31 |
+
# Expose port 7860 (Hugging Face Spaces default)
|
| 32 |
+
EXPOSE 7860
|
| 33 |
+
|
| 34 |
+
# Health check
|
| 35 |
+
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
|
| 36 |
+
CMD curl -f http://localhost:7860/health || exit 1
|
| 37 |
+
|
| 38 |
+
# Run the FastAPI application
|
| 39 |
+
CMD ["uvicorn", "api:app", "--host", "0.0.0.0", "--port", "7860"]
|
__init__.py
ADDED
|
File without changes
|
__pycache__/__init__.cpython-312.pyc
ADDED
|
Binary file (192 Bytes). View file
|
|
|
__pycache__/__init__.cpython-314.pyc
ADDED
|
Binary file (190 Bytes). View file
|
|
|
__pycache__/agent.cpython-312.pyc
ADDED
|
Binary file (14 kB). View file
|
|
|
__pycache__/agent.cpython-314.pyc
ADDED
|
Binary file (15.9 kB). View file
|
|
|
__pycache__/api.cpython-312.pyc
ADDED
|
Binary file (7.82 kB). View file
|
|
|
__pycache__/api.cpython-314.pyc
ADDED
|
Binary file (9.45 kB). View file
|
|
|
__pycache__/config.cpython-312.pyc
ADDED
|
Binary file (1.51 kB). View file
|
|
|
__pycache__/config.cpython-314.pyc
ADDED
|
Binary file (1.56 kB). View file
|
|
|
__pycache__/logging_config.cpython-312.pyc
ADDED
|
Binary file (3.72 kB). View file
|
|
|
__pycache__/logging_config.cpython-314.pyc
ADDED
|
Binary file (4.03 kB). View file
|
|
|
__pycache__/main.cpython-312.pyc
ADDED
|
Binary file (19.7 kB). View file
|
|
|
__pycache__/retrieve.cpython-312.pyc
ADDED
|
Binary file (17.5 kB). View file
|
|
|
__pycache__/retrieve.cpython-314.pyc
ADDED
|
Binary file (19.8 kB). View file
|
|
|
__pycache__/utils.cpython-312.pyc
ADDED
|
Binary file (2.88 kB). View file
|
|
|
__pycache__/utils.cpython-314.pyc
ADDED
|
Binary file (3.43 kB). View file
|
|
|
agent
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
agent.py
ADDED
|
@@ -0,0 +1,361 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
RAG Agent FastAPI Server using OpenAI Agents SDK
|
| 3 |
+
|
| 4 |
+
Provides POST /chat endpoint for grounded Q&A using OpenAI Agents SDK
|
| 5 |
+
and retrieval from Qdrant via Spec-2's retrieve.py module.
|
| 6 |
+
"""
|
| 7 |
+
|
| 8 |
+
import os
|
| 9 |
+
import sys
|
| 10 |
+
import uuid
|
| 11 |
+
import asyncio
|
| 12 |
+
from datetime import datetime
|
| 13 |
+
from typing import List, Dict, Any, Optional
|
| 14 |
+
|
| 15 |
+
from fastapi import FastAPI, HTTPException
|
| 16 |
+
from fastapi.responses import JSONResponse
|
| 17 |
+
from pydantic import BaseModel, Field, validator
|
| 18 |
+
from dotenv import load_dotenv
|
| 19 |
+
|
| 20 |
+
from agents import OpenAIChatCompletionsModel
|
| 21 |
+
from openai import AsyncOpenAI
|
| 22 |
+
|
| 23 |
+
OPENROUTER_API_KEY = (
|
| 24 |
+
"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"
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
client = AsyncOpenAI(
|
| 28 |
+
api_key=OPENROUTER_API_KEY,
|
| 29 |
+
base_url="https://openrouter.ai/api/v1",
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
third_party_model = OpenAIChatCompletionsModel(
|
| 33 |
+
openai_client=client, model="stepfun/step-3.5-flash:free"
|
| 34 |
+
)
|
| 35 |
+
|
| 36 |
+
# Make backend package importable
|
| 37 |
+
current_dir = os.path.dirname(os.path.abspath(__file__))
|
| 38 |
+
backend_parent = os.path.dirname(current_dir)
|
| 39 |
+
if backend_parent not in sys.path:
|
| 40 |
+
sys.path.insert(0, backend_parent)
|
| 41 |
+
|
| 42 |
+
# Import backend modules (support both module and script execution)
|
| 43 |
+
try:
|
| 44 |
+
from .config import get_config
|
| 45 |
+
from .retrieve import search as retrieve_search
|
| 46 |
+
from .logging_config import setup_logging
|
| 47 |
+
except ImportError as e:
|
| 48 |
+
try:
|
| 49 |
+
from backend.config import get_config
|
| 50 |
+
from backend.retrieve import search as retrieve_search
|
| 51 |
+
from backend.logging_config import setup_logging
|
| 52 |
+
except ImportError as e2:
|
| 53 |
+
raise ImportError(f"Failed to import backend modules: {e2}")
|
| 54 |
+
|
| 55 |
+
# Import OpenAI Agents SDK (must be installed separately)
|
| 56 |
+
try:
|
| 57 |
+
from agents import Agent, Runner, function_tool, ModelSettings, ToolCallOutputItem
|
| 58 |
+
except ImportError:
|
| 59 |
+
raise ImportError(
|
| 60 |
+
"openai-agents package required. Install: pip install openai-agents"
|
| 61 |
+
)
|
| 62 |
+
|
| 63 |
+
# Load environment
|
| 64 |
+
load_dotenv()
|
| 65 |
+
|
| 66 |
+
# Setup logging
|
| 67 |
+
logger = setup_logging("agent")
|
| 68 |
+
|
| 69 |
+
# Initialize FastAPI app
|
| 70 |
+
app = FastAPI(
|
| 71 |
+
title="RAG Book Chatbot API",
|
| 72 |
+
version="1.0.0",
|
| 73 |
+
description="Chatbot for humanoid robotics book using OpenAI Agents SDK",
|
| 74 |
+
)
|
| 75 |
+
|
| 76 |
+
# ============ Pydantic Models ============
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
class ChatRequest(BaseModel):
|
| 80 |
+
question: str = Field(..., min_length=1, max_length=1000)
|
| 81 |
+
|
| 82 |
+
@validator("question")
|
| 83 |
+
def validate_question(cls, v):
|
| 84 |
+
if not v or not v.strip():
|
| 85 |
+
raise ValueError("Question cannot be empty")
|
| 86 |
+
return v.strip()
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
class Source(BaseModel):
|
| 90 |
+
url: str
|
| 91 |
+
chunk_index: int
|
| 92 |
+
text_snippet: str
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
class ChatResponse(BaseModel):
|
| 96 |
+
answer: str
|
| 97 |
+
sources: List[Source]
|
| 98 |
+
tokens_used: int
|
| 99 |
+
agent_trace: Optional[str] = None
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
class HealthStatus(BaseModel):
|
| 103 |
+
status: str
|
| 104 |
+
qdrant: str
|
| 105 |
+
openai: str
|
| 106 |
+
timestamp: str
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
# ============ Retrieval Tool ============
|
| 110 |
+
|
| 111 |
+
|
| 112 |
+
@function_tool
|
| 113 |
+
def retrieve_chunks(query: str, top_k: int = 5) -> List[Dict[str, Any]]:
|
| 114 |
+
"""
|
| 115 |
+
Retrieve relevant book chunks from Qdrant.
|
| 116 |
+
|
| 117 |
+
Args:
|
| 118 |
+
query: User's question
|
| 119 |
+
top_k: Number of chunks to retrieve (default: 5, max: 10)
|
| 120 |
+
|
| 121 |
+
Returns:
|
| 122 |
+
List of chunks with url, chunk_index, text, score, and source_number
|
| 123 |
+
"""
|
| 124 |
+
logger.info(
|
| 125 |
+
f"[Tool] retrieve_chunks called: query='{query[:100]}...', top_k={top_k}"
|
| 126 |
+
)
|
| 127 |
+
|
| 128 |
+
try:
|
| 129 |
+
import cohere
|
| 130 |
+
from qdrant_client import QdrantClient
|
| 131 |
+
|
| 132 |
+
cfg = get_config()
|
| 133 |
+
cohere_client = cohere.ClientV2(api_key=cfg["cohere_api_key"])
|
| 134 |
+
qdrant_client = QdrantClient(
|
| 135 |
+
url=cfg["qdrant_url"], api_key=cfg["qdrant_api_key"]
|
| 136 |
+
)
|
| 137 |
+
collection_name = cfg["qdrant_collection"]
|
| 138 |
+
|
| 139 |
+
results = retrieve_search(
|
| 140 |
+
query_text=query,
|
| 141 |
+
cohere_client=cohere_client,
|
| 142 |
+
qdrant_client=qdrant_client,
|
| 143 |
+
collection_name=collection_name,
|
| 144 |
+
top_k=top_k,
|
| 145 |
+
)
|
| 146 |
+
|
| 147 |
+
chunks = []
|
| 148 |
+
for i, result in enumerate(results):
|
| 149 |
+
payload = result.get("payload", {})
|
| 150 |
+
chunks.append(
|
| 151 |
+
{
|
| 152 |
+
"url": payload.get("url", ""),
|
| 153 |
+
"chunk_index": payload.get("chunk_index", i),
|
| 154 |
+
"text": payload.get("text", ""),
|
| 155 |
+
"score": result.get("score", 0.0),
|
| 156 |
+
"source_number": i + 1,
|
| 157 |
+
}
|
| 158 |
+
)
|
| 159 |
+
|
| 160 |
+
logger.info(f"[Tool] Retrieved {len(chunks)} chunks")
|
| 161 |
+
return chunks
|
| 162 |
+
|
| 163 |
+
except Exception as e:
|
| 164 |
+
logger.error(f"[Tool] Retrieval failed: {e}", exc_info=True)
|
| 165 |
+
raise
|
| 166 |
+
|
| 167 |
+
|
| 168 |
+
# ============ Agent Definition ============
|
| 169 |
+
|
| 170 |
+
|
| 171 |
+
def get_agent_instructions() -> str:
|
| 172 |
+
return """You are a helpful assistant answering questions about a humanoid robotics book.
|
| 173 |
+
|
| 174 |
+
IMPORTANT GROUNDING RULES:
|
| 175 |
+
1. Answer ONLY using the retrieved book content provided by the retrieve_chunks tool.
|
| 176 |
+
2. Do NOT use external knowledge or make up information.
|
| 177 |
+
3. If the retrieved content does not contain relevant information, say "I couldn't find relevant information in the book."
|
| 178 |
+
4. Always cite your sources using the format [Source 1], [Source 2], etc. Each source number corresponds to the chunk number from the tool.
|
| 179 |
+
5. Be concise and accurate.
|
| 180 |
+
|
| 181 |
+
Your responses should be helpful, clear, and grounded exclusively in the provided context."""
|
| 182 |
+
|
| 183 |
+
|
| 184 |
+
def create_agent():
|
| 185 |
+
return Agent(
|
| 186 |
+
name="RAG Book Assistant",
|
| 187 |
+
instructions=get_agent_instructions(),
|
| 188 |
+
tools=[retrieve_chunks],
|
| 189 |
+
model=third_party_model,
|
| 190 |
+
model_settings=ModelSettings(temperature=0.7, max_tokens=500),
|
| 191 |
+
)
|
| 192 |
+
|
| 193 |
+
|
| 194 |
+
_agent_instance = None
|
| 195 |
+
|
| 196 |
+
|
| 197 |
+
def get_agent():
|
| 198 |
+
"""Lazy singleton agent instance."""
|
| 199 |
+
global _agent_instance
|
| 200 |
+
if _agent_instance is None:
|
| 201 |
+
_agent_instance = create_agent()
|
| 202 |
+
return _agent_instance
|
| 203 |
+
|
| 204 |
+
|
| 205 |
+
# ============ Health Checks ============
|
| 206 |
+
|
| 207 |
+
|
| 208 |
+
def check_qdrant_health() -> str:
|
| 209 |
+
try:
|
| 210 |
+
from backend.config import get_config
|
| 211 |
+
from qdrant_client import QdrantClient
|
| 212 |
+
|
| 213 |
+
cfg = get_config()
|
| 214 |
+
client = QdrantClient(url=cfg["qdrant_url"], api_key=cfg["qdrant_api_key"])
|
| 215 |
+
client.get_collection(cfg["qdrant_collection"])
|
| 216 |
+
return "connected"
|
| 217 |
+
except Exception as e:
|
| 218 |
+
logger.warning(f"Qdrant health check failed: {e}")
|
| 219 |
+
return "disconnected"
|
| 220 |
+
|
| 221 |
+
|
| 222 |
+
def check_openai_health() -> str:
|
| 223 |
+
try:
|
| 224 |
+
api_key = os.getenv("OPENAI_API_KEY")
|
| 225 |
+
if not api_key:
|
| 226 |
+
return "disconnected"
|
| 227 |
+
import openai
|
| 228 |
+
|
| 229 |
+
client = openai.OpenAI(api_key=api_key)
|
| 230 |
+
# Simple models.list call to verify API connectivity
|
| 231 |
+
client.models.list()
|
| 232 |
+
return "connected"
|
| 233 |
+
except Exception as e:
|
| 234 |
+
logger.warning(f"OpenAI health check failed: {e}")
|
| 235 |
+
return "disconnected"
|
| 236 |
+
|
| 237 |
+
|
| 238 |
+
# ============ FastAPI Endpoints ============
|
| 239 |
+
|
| 240 |
+
|
| 241 |
+
@app.post("/chat")
|
| 242 |
+
async def chat_endpoint(request: ChatRequest):
|
| 243 |
+
request_id = str(uuid.uuid4())[:8]
|
| 244 |
+
question = request.question.strip()
|
| 245 |
+
|
| 246 |
+
logger.info(f"[{request_id}] Received chat: {question[:100]}...")
|
| 247 |
+
|
| 248 |
+
try:
|
| 249 |
+
agent = get_agent()
|
| 250 |
+
|
| 251 |
+
# Use async Runner.run (native async, no blocking)
|
| 252 |
+
result = await asyncio.wait_for(
|
| 253 |
+
Runner.run(agent, question),
|
| 254 |
+
timeout=20.0, # Increased from 10s to accommodate full workflow
|
| 255 |
+
)
|
| 256 |
+
|
| 257 |
+
# Extract sources from tool call outputs
|
| 258 |
+
sources = []
|
| 259 |
+
if result.new_items:
|
| 260 |
+
for item in result.new_items:
|
| 261 |
+
if isinstance(item, ToolCallOutputItem):
|
| 262 |
+
output = item.output
|
| 263 |
+
if isinstance(output, list):
|
| 264 |
+
for chunk in output:
|
| 265 |
+
sources.append(
|
| 266 |
+
Source(
|
| 267 |
+
url=chunk.get("url", ""),
|
| 268 |
+
chunk_index=chunk.get("chunk_index", 0),
|
| 269 |
+
text_snippet=chunk.get("text", "")[:200],
|
| 270 |
+
)
|
| 271 |
+
)
|
| 272 |
+
|
| 273 |
+
# Get token usage
|
| 274 |
+
tokens_used = 0
|
| 275 |
+
if result.context_wrapper and hasattr(result.context_wrapper, "usage"):
|
| 276 |
+
tokens_used = result.context_wrapper.usage.total_tokens
|
| 277 |
+
|
| 278 |
+
response = ChatResponse(
|
| 279 |
+
answer=result.final_output,
|
| 280 |
+
sources=sources,
|
| 281 |
+
tokens_used=tokens_used,
|
| 282 |
+
agent_trace=f"{request_id}: completed",
|
| 283 |
+
)
|
| 284 |
+
|
| 285 |
+
logger.info(
|
| 286 |
+
f"[{request_id}] Completed: tokens={tokens_used}, sources={len(sources)}"
|
| 287 |
+
)
|
| 288 |
+
return response
|
| 289 |
+
|
| 290 |
+
except asyncio.TimeoutError:
|
| 291 |
+
logger.error(f"[{request_id}] Timeout after 10s")
|
| 292 |
+
return JSONResponse(
|
| 293 |
+
status_code=504,
|
| 294 |
+
content={
|
| 295 |
+
"error": "timeout",
|
| 296 |
+
"message": "Request timed out. Please try again.",
|
| 297 |
+
},
|
| 298 |
+
)
|
| 299 |
+
|
| 300 |
+
except Exception as e:
|
| 301 |
+
logger.error(f"[{request_id}] Error: {e}", exc_info=True)
|
| 302 |
+
status_code = 503 if "openai" in str(e).lower() else 500
|
| 303 |
+
error_code = "openai_failed" if status_code == 503 else "internal_error"
|
| 304 |
+
return JSONResponse(
|
| 305 |
+
status_code=status_code, content={"error": error_code, "message": str(e)}
|
| 306 |
+
)
|
| 307 |
+
|
| 308 |
+
|
| 309 |
+
@app.get("/health", response_model=HealthStatus)
|
| 310 |
+
async def health_check():
|
| 311 |
+
request_id = str(uuid.uuid4())[:8]
|
| 312 |
+
qdrant = check_qdrant_health()
|
| 313 |
+
openai = check_openai_health() # sync call
|
| 314 |
+
status = (
|
| 315 |
+
"healthy" if qdrant == "connected" and openai == "connected" else "degraded"
|
| 316 |
+
)
|
| 317 |
+
return HealthStatus(
|
| 318 |
+
status=status,
|
| 319 |
+
qdrant=qdrant,
|
| 320 |
+
openai=openai,
|
| 321 |
+
timestamp=datetime.utcnow().isoformat() + "Z",
|
| 322 |
+
)
|
| 323 |
+
|
| 324 |
+
|
| 325 |
+
@app.on_event("startup")
|
| 326 |
+
async def startup_event():
|
| 327 |
+
logger.info("=" * 60)
|
| 328 |
+
logger.info("RAG Agent FastAPI Server Starting")
|
| 329 |
+
logger.info("=" * 60)
|
| 330 |
+
|
| 331 |
+
if not os.getenv("OPENAI_API_KEY"):
|
| 332 |
+
logger.warning("OPENAI_API_KEY not set")
|
| 333 |
+
|
| 334 |
+
# Test retrieval
|
| 335 |
+
try:
|
| 336 |
+
import cohere
|
| 337 |
+
from qdrant_client import QdrantClient
|
| 338 |
+
|
| 339 |
+
cfg = get_config()
|
| 340 |
+
cohere_client = cohere.ClientV2(api_key=cfg["cohere_api_key"])
|
| 341 |
+
qdrant_client = QdrantClient(
|
| 342 |
+
url=cfg["qdrant_url"], api_key=cfg["qdrant_api_key"]
|
| 343 |
+
)
|
| 344 |
+
test_result = retrieve_search(
|
| 345 |
+
query_text="test",
|
| 346 |
+
cohere_client=cohere_client,
|
| 347 |
+
qdrant_client=qdrant_client,
|
| 348 |
+
collection_name=cfg["qdrant_collection"],
|
| 349 |
+
top_k=1,
|
| 350 |
+
)
|
| 351 |
+
logger.info(f"Retrieval test OK: {len(test_result)} results")
|
| 352 |
+
except Exception as e:
|
| 353 |
+
logger.error(f"Retrieval test failed: {e}")
|
| 354 |
+
|
| 355 |
+
logger.info("Server startup complete")
|
| 356 |
+
|
| 357 |
+
|
| 358 |
+
if __name__ == "__main__":
|
| 359 |
+
import uvicorn
|
| 360 |
+
|
| 361 |
+
uvicorn.run(app, host="0.0.0.0", port=8000)
|
agent_direct_run.log
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/mnt/e/7. Low Code Agentic AI/Hackathon I/humanoid-ai-robotics-book-chatbot/backend/agent.py:63: PydanticDeprecatedSince20: Pydantic V1 style `@validator` validators are deprecated. You should migrate to Pydantic V2 style `@field_validator` validators, see the migration guide for more details. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.12/migration/
|
| 2 |
+
@validator('question')
|
| 3 |
+
/mnt/e/7. Low Code Agentic AI/Hackathon I/humanoid-ai-robotics-book-chatbot/backend/agent.py:291: DeprecationWarning:
|
| 4 |
+
on_event is deprecated, use lifespan event handlers instead.
|
| 5 |
+
|
| 6 |
+
Read more about it in the
|
| 7 |
+
[FastAPI docs for Lifespan Events](https://fastapi.tiangolo.com/advanced/events/).
|
| 8 |
+
|
| 9 |
+
@app.on_event("startup")
|
| 10 |
+
INFO: Started server process [13533]
|
| 11 |
+
INFO: Waiting for application startup.
|
| 12 |
+
05:10:47 - INFO - root - ============================================================
|
| 13 |
+
05:10:47 - INFO - root - RAG Agent FastAPI Server Starting
|
| 14 |
+
05:10:47 - INFO - root - ============================================================
|
| 15 |
+
05:10:49 - INFO - httpx - HTTP Request: GET https://d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io:6333 "HTTP/1.1 200 OK"
|
| 16 |
+
05:10:49 - INFO - backend.retrieve - Embedding query: 'test...' (top_k=1)
|
| 17 |
+
05:10:49 - INFO - httpx - HTTP Request: POST https://api.cohere.com/v2/embed "HTTP/1.1 200 OK"
|
| 18 |
+
05:10:50 - INFO - httpx - HTTP Request: POST https://d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io:6333/collections/book_embeddings/points/query "HTTP/1.1 200 OK"
|
| 19 |
+
05:10:50 - INFO - backend.retrieve - Search completed in 0.62s, returned 1 results
|
| 20 |
+
05:10:50 - INFO - backend.retrieve - Total query time: 1.05s
|
| 21 |
+
05:10:50 - INFO - root - Retrieval test OK: 1 results
|
| 22 |
+
05:10:50 - INFO - root - Server startup complete
|
| 23 |
+
INFO: Application startup complete.
|
| 24 |
+
ERROR: [Errno 98] error while attempting to bind on address ('0.0.0.0', 8000): address already in use
|
| 25 |
+
INFO: Waiting for application shutdown.
|
| 26 |
+
INFO: Application shutdown complete.
|
agent_sdk_docs.md
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
agent_test.log
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Traceback (most recent call last):
|
| 2 |
+
File "/mnt/e/7. Low Code Agentic AI/Hackathon I/humanoid-ai-robotics-book-chatbot/backend/agent.py", line 22, in <module>
|
| 3 |
+
from .config import get_config
|
| 4 |
+
ImportError: attempted relative import with no known parent package
|
agent_uvicorn.log
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
INFO: Started server process [9071]
|
| 2 |
+
INFO: Waiting for application startup.
|
| 3 |
+
INFO: ============================================================
|
| 4 |
+
INFO: RAG Agent FastAPI Server Starting
|
| 5 |
+
INFO: ============================================================
|
| 6 |
+
INFO: HTTP Request: GET https://d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io:6333 "HTTP/1.1 200 OK"
|
| 7 |
+
INFO: Embedding query: 'test...' (top_k=1)
|
| 8 |
+
INFO: HTTP Request: POST https://api.cohere.com/v2/embed "HTTP/1.1 200 OK"
|
| 9 |
+
INFO: HTTP Request: POST https://d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io:6333/collections/book_embeddings/points/query "HTTP/1.1 200 OK"
|
| 10 |
+
INFO: Search completed in 0.61s, returned 1 results
|
| 11 |
+
INFO: Total query time: 1.14s
|
| 12 |
+
INFO: Retrieval test successful: 1 results
|
| 13 |
+
INFO: Server startup complete
|
| 14 |
+
INFO: Application startup complete.
|
| 15 |
+
INFO: Uvicorn running on http://0.0.0.0:8000 (Press CTRL+C to quit)
|
| 16 |
+
INFO: HTTP Request: GET https://d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io:6333 "HTTP/1.1 200 OK"
|
| 17 |
+
INFO: HTTP Request: GET https://d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io:6333/collections/book_embeddings "HTTP/1.1 200 OK"
|
| 18 |
+
INFO: HTTP Request: GET https://api.openai.com/v1/models "HTTP/1.1 200 OK"
|
| 19 |
+
INFO: 127.0.0.1:46502 - "GET /health HTTP/1.1" 200 OK
|
| 20 |
+
INFO: 127.0.0.1:58298 - "GET /docs HTTP/1.1" 200 OK
|
| 21 |
+
INFO: 127.0.0.1:58298 - "GET /openapi.json HTTP/1.1" 200 OK
|
| 22 |
+
INFO: [e87ec0e7] Received chat request: What is ROS 2?...
|
| 23 |
+
INFO: [e87ec0e7] Starting agent execution for question: What is ROS 2?...
|
| 24 |
+
INFO: Retrieving chunks for query: What is ROS 2?...
|
| 25 |
+
INFO: HTTP Request: GET https://d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io:6333 "HTTP/1.1 200 OK"
|
| 26 |
+
INFO: Embedding query: 'What is ROS 2?...' (top_k=5)
|
| 27 |
+
INFO: HTTP Request: POST https://api.cohere.com/v2/embed "HTTP/1.1 200 OK"
|
| 28 |
+
INFO: HTTP Request: POST https://d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io:6333/collections/book_embeddings/points/query "HTTP/1.1 200 OK"
|
| 29 |
+
INFO: Search completed in 0.63s, returned 5 results
|
| 30 |
+
INFO: Total query time: 1.04s
|
| 31 |
+
INFO: Retrieved 5 chunks
|
| 32 |
+
INFO: HTTP Request: POST https://api.openai.com/v1/chat/completions "HTTP/1.1 429 Too Many Requests"
|
| 33 |
+
INFO: Retrying request to /chat/completions in 0.439727 seconds
|
| 34 |
+
INFO: HTTP Request: POST https://api.openai.com/v1/chat/completions "HTTP/1.1 429 Too Many Requests"
|
| 35 |
+
INFO: Retrying request to /chat/completions in 0.899512 seconds
|
| 36 |
+
INFO: HTTP Request: POST https://api.openai.com/v1/chat/completions "HTTP/1.1 429 Too Many Requests"
|
| 37 |
+
INFO: HTTP Request: POST https://api.openai.com/v1/chat/completions "HTTP/1.1 429 Too Many Requests"
|
| 38 |
+
INFO: Retrying request to /chat/completions in 0.428043 seconds
|
| 39 |
+
INFO: HTTP Request: POST https://api.openai.com/v1/chat/completions "HTTP/1.1 429 Too Many Requests"
|
| 40 |
+
INFO: Retrying request to /chat/completions in 0.881976 seconds
|
| 41 |
+
ERROR: [e87ec0e7] Request timeout after 10s
|
| 42 |
+
INFO: 127.0.0.1:34080 - "POST /chat HTTP/1.1" 504 Gateway Timeout
|
| 43 |
+
INFO: HTTP Request: POST https://api.openai.com/v1/chat/completions "HTTP/1.1 429 Too Many Requests"
|
| 44 |
+
INFO: HTTP Request: POST https://api.openai.com/v1/chat/completions "HTTP/1.1 429 Too Many Requests"
|
| 45 |
+
INFO: Retrying request to /chat/completions in 0.403914 seconds
|
| 46 |
+
INFO: HTTP Request: POST https://api.openai.com/v1/chat/completions "HTTP/1.1 429 Too Many Requests"
|
| 47 |
+
INFO: Retrying request to /chat/completions in 0.922430 seconds
|
| 48 |
+
INFO: HTTP Request: POST https://api.openai.com/v1/chat/completions "HTTP/1.1 429 Too Many Requests"
|
| 49 |
+
ERROR: [e87ec0e7] Agent failed after 12.08s: Error code: 429 - {'error': {'message': 'You exceeded your current quota, please check your plan and billing details. For more information on this error, read the docs: https://platform.openai.com/docs/guides/error-codes/api-errors.', 'type': 'insufficient_quota', 'param': None, 'code': 'insufficient_quota'}}
|
| 50 |
+
Traceback (most recent call last):
|
| 51 |
+
File "/mnt/e/7. Low Code Agentic AI/Hackathon I/humanoid-ai-robotics-book-chatbot/backend/agent.py", line 224, in run
|
| 52 |
+
response = retry_with_backoff(call_openai, max_retries=3)
|
| 53 |
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| 54 |
+
File "/mnt/e/7. Low Code Agentic AI/Hackathon I/humanoid-ai-robotics-book-chatbot/backend/utils.py", line 49, in retry_with_backoff
|
| 55 |
+
return func()
|
| 56 |
+
^^^^^^
|
| 57 |
+
File "/mnt/e/7. Low Code Agentic AI/Hackathon I/humanoid-ai-robotics-book-chatbot/backend/agent.py", line 216, in call_openai
|
| 58 |
+
response = self.client.chat.completions.create(
|
| 59 |
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| 60 |
+
File "/home/m-ahmad-official/venv/lib/python3.12/site-packages/openai/_utils/_utils.py", line 286, in wrapper
|
| 61 |
+
return func(*args, **kwargs)
|
| 62 |
+
^^^^^^^^^^^^^^^^^^^^^
|
| 63 |
+
File "/home/m-ahmad-official/venv/lib/python3.12/site-packages/openai/resources/chat/completions/completions.py", line 1192, in create
|
| 64 |
+
return self._post(
|
| 65 |
+
^^^^^^^^^^^
|
| 66 |
+
File "/home/m-ahmad-official/venv/lib/python3.12/site-packages/openai/_base_client.py", line 1297, in post
|
| 67 |
+
return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))
|
| 68 |
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| 69 |
+
File "/home/m-ahmad-official/venv/lib/python3.12/site-packages/openai/_base_client.py", line 1070, in request
|
| 70 |
+
raise self._make_status_error_from_response(err.response) from None
|
| 71 |
+
openai.RateLimitError: Error code: 429 - {'error': {'message': 'You exceeded your current quota, please check your plan and billing details. For more information on this error, read the docs: https://platform.openai.com/docs/guides/error-codes/api-errors.', 'type': 'insufficient_quota', 'param': None, 'code': 'insufficient_quota'}}
|
| 72 |
+
INFO: 127.0.0.1:48658 - "GET /docs HTTP/1.1" 200 OK
|
| 73 |
+
INFO: 127.0.0.1:48658 - "GET /openapi.json HTTP/1.1" 200 OK
|
| 74 |
+
INFO: HTTP Request: GET https://d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io:6333 "HTTP/1.1 200 OK"
|
| 75 |
+
INFO: HTTP Request: GET https://d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io:6333/collections/book_embeddings "HTTP/1.1 200 OK"
|
| 76 |
+
INFO: HTTP Request: GET https://api.openai.com/v1/models "HTTP/1.1 200 OK"
|
| 77 |
+
INFO: 127.0.0.1:42400 - "GET /health HTTP/1.1" 200 OK
|
| 78 |
+
INFO: [19abeba2] Received chat request: What is ROS 2?...
|
| 79 |
+
INFO: [19abeba2] Starting agent execution for question: What is ROS 2?...
|
| 80 |
+
INFO: Retrieving chunks for query: What is ROS 2?...
|
| 81 |
+
INFO: HTTP Request: GET https://d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io:6333 "HTTP/1.1 200 OK"
|
| 82 |
+
INFO: Embedding query: 'What is ROS 2?...' (top_k=5)
|
| 83 |
+
INFO: HTTP Request: POST https://api.cohere.com/v2/embed "HTTP/1.1 200 OK"
|
| 84 |
+
INFO: HTTP Request: POST https://d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io:6333/collections/book_embeddings/points/query "HTTP/1.1 200 OK"
|
| 85 |
+
INFO: Search completed in 0.60s, returned 5 results
|
| 86 |
+
INFO: Total query time: 1.07s
|
| 87 |
+
INFO: Retrieved 5 chunks
|
| 88 |
+
INFO: HTTP Request: POST https://api.openai.com/v1/chat/completions "HTTP/1.1 200 OK"
|
| 89 |
+
INFO: [19abeba2] Agent completed in 4.17s, tokens=1360, sources=5
|
| 90 |
+
INFO: 127.0.0.1:36912 - "POST /chat HTTP/1.1" 200 OK
|
| 91 |
+
INFO: 127.0.0.1:56750 - "GET /docs HTTP/1.1" 200 OK
|
| 92 |
+
INFO: 127.0.0.1:56750 - "GET /openapi.json HTTP/1.1" 200 OK
|
| 93 |
+
INFO: Shutting down
|
| 94 |
+
INFO: Waiting for application shutdown.
|
| 95 |
+
INFO: Application shutdown complete.
|
| 96 |
+
INFO: Finished server process [9071]
|
agent_uvicorn_new.log
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
INFO: Started server process [13073]
|
| 2 |
+
INFO: Waiting for application startup.
|
| 3 |
+
05:05:21 - INFO - root - ============================================================
|
| 4 |
+
05:05:21 - INFO - root - RAG Agent FastAPI Server Starting
|
| 5 |
+
05:05:21 - INFO - root - ============================================================
|
| 6 |
+
05:05:23 - INFO - httpx - HTTP Request: GET https://d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io:6333 "HTTP/1.1 200 OK"
|
| 7 |
+
05:05:23 - INFO - backend.retrieve - Embedding query: 'test...' (top_k=1)
|
| 8 |
+
05:05:23 - INFO - httpx - HTTP Request: POST https://api.cohere.com/v2/embed "HTTP/1.1 200 OK"
|
| 9 |
+
05:05:24 - INFO - httpx - HTTP Request: POST https://d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io:6333/collections/book_embeddings/points/query "HTTP/1.1 200 OK"
|
| 10 |
+
05:05:24 - INFO - backend.retrieve - Search completed in 0.61s, returned 1 results
|
| 11 |
+
05:05:24 - INFO - backend.retrieve - Total query time: 1.14s
|
| 12 |
+
05:05:24 - INFO - root - Retrieval test OK: 1 results
|
| 13 |
+
05:05:24 - INFO - root - Server startup complete
|
| 14 |
+
INFO: Application startup complete.
|
| 15 |
+
INFO: Uvicorn running on http://0.0.0.0:8000 (Press CTRL+C to quit)
|
| 16 |
+
05:05:53 - INFO - httpx - HTTP Request: GET https://d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io:6333 "HTTP/1.1 200 OK"
|
| 17 |
+
05:05:54 - INFO - httpx - HTTP Request: GET https://d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io:6333/collections/book_embeddings "HTTP/1.1 200 OK"
|
| 18 |
+
05:05:56 - INFO - httpx - HTTP Request: POST https://api.openai.com/v1/responses "HTTP/1.1 200 OK"
|
| 19 |
+
INFO: 127.0.0.1:56784 - "GET /health HTTP/1.1" 200 OK
|
| 20 |
+
05:06:01 - INFO - httpx - HTTP Request: POST https://api.openai.com/v1/traces/ingest "HTTP/1.1 204 No Content"
|
| 21 |
+
05:06:46 - INFO - httpx - HTTP Request: GET https://d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io:6333 "HTTP/1.1 200 OK"
|
| 22 |
+
05:06:46 - INFO - httpx - HTTP Request: GET https://d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io:6333/collections/book_embeddings "HTTP/1.1 200 OK"
|
| 23 |
+
05:06:47 - INFO - httpx - HTTP Request: POST https://api.openai.com/v1/traces/ingest "HTTP/1.1 204 No Content"
|
| 24 |
+
05:06:48 - INFO - httpx - HTTP Request: POST https://api.openai.com/v1/responses "HTTP/1.1 200 OK"
|
| 25 |
+
INFO: 127.0.0.1:60030 - "GET /health HTTP/1.1" 200 OK
|
| 26 |
+
05:06:54 - INFO - httpx - HTTP Request: POST https://api.openai.com/v1/traces/ingest "HTTP/1.1 204 No Content"
|
| 27 |
+
05:07:01 - INFO - root - [c8a20a2e] Received chat: What is ROS 2?...
|
| 28 |
+
05:07:02 - INFO - httpx - HTTP Request: POST https://api.openai.com/v1/responses "HTTP/1.1 200 OK"
|
| 29 |
+
05:07:02 - INFO - root - [Tool] retrieve_chunks called: query='What is ROS 2?...', top_k=5
|
| 30 |
+
05:07:03 - INFO - httpx - HTTP Request: GET https://d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io:6333 "HTTP/1.1 200 OK"
|
| 31 |
+
05:07:03 - INFO - backend.retrieve - Embedding query: 'What is ROS 2?...' (top_k=5)
|
| 32 |
+
05:07:03 - INFO - httpx - HTTP Request: POST https://api.cohere.com/v2/embed "HTTP/1.1 200 OK"
|
| 33 |
+
05:07:04 - INFO - httpx - HTTP Request: POST https://d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io:6333/collections/book_embeddings/points/query "HTTP/1.1 200 OK"
|
| 34 |
+
05:07:04 - INFO - backend.retrieve - Search completed in 0.65s, returned 5 results
|
| 35 |
+
05:07:04 - INFO - backend.retrieve - Total query time: 1.06s
|
| 36 |
+
05:07:04 - INFO - root - [Tool] Retrieved 5 chunks
|
| 37 |
+
05:07:05 - INFO - httpx - HTTP Request: POST https://api.openai.com/v1/traces/ingest "HTTP/1.1 204 No Content"
|
| 38 |
+
05:07:05 - INFO - httpx - HTTP Request: POST https://api.openai.com/v1/traces/ingest "HTTP/1.1 204 No Content"
|
| 39 |
+
05:07:09 - INFO - httpx - HTTP Request: POST https://api.openai.com/v1/responses "HTTP/1.1 200 OK"
|
| 40 |
+
05:07:09 - INFO - root - [c8a20a2e] Completed: tokens=2006, sources=5
|
| 41 |
+
INFO: 127.0.0.1:33240 - "POST /chat HTTP/1.1" 200 OK
|
| 42 |
+
05:07:11 - INFO - httpx - HTTP Request: POST https://api.openai.com/v1/traces/ingest "HTTP/1.1 204 No Content"
|
| 43 |
+
05:07:44 - INFO - httpx - HTTP Request: GET https://d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io:6333 "HTTP/1.1 200 OK"
|
| 44 |
+
05:07:45 - INFO - httpx - HTTP Request: GET https://d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io:6333/collections/book_embeddings "HTTP/1.1 200 OK"
|
| 45 |
+
05:07:46 - INFO - httpx - HTTP Request: POST https://api.openai.com/v1/responses "HTTP/1.1 200 OK"
|
| 46 |
+
INFO: 127.0.0.1:54614 - "GET /health HTTP/1.1" 200 OK
|
| 47 |
+
05:07:47 - INFO - httpx - HTTP Request: POST https://api.openai.com/v1/traces/ingest "HTTP/1.1 204 No Content"
|
| 48 |
+
05:07:58 - INFO - root - [6ad72fe1] Received chat: What is ROS 2?...
|
| 49 |
+
05:07:59 - INFO - httpx - HTTP Request: POST https://api.openai.com/v1/responses "HTTP/1.1 200 OK"
|
| 50 |
+
05:07:59 - INFO - root - [Tool] retrieve_chunks called: query='What is ROS 2?...', top_k=5
|
| 51 |
+
05:08:00 - INFO - httpx - HTTP Request: GET https://d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io:6333 "HTTP/1.1 200 OK"
|
| 52 |
+
05:08:00 - INFO - backend.retrieve - Embedding query: 'What is ROS 2?...' (top_k=5)
|
| 53 |
+
05:08:01 - INFO - httpx - HTTP Request: POST https://api.cohere.com/v2/embed "HTTP/1.1 200 OK"
|
| 54 |
+
05:08:01 - INFO - httpx - HTTP Request: POST https://d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io:6333/collections/book_embeddings/points/query "HTTP/1.1 200 OK"
|
| 55 |
+
05:08:01 - INFO - backend.retrieve - Search completed in 0.65s, returned 5 results
|
| 56 |
+
05:08:01 - INFO - backend.retrieve - Total query time: 1.09s
|
| 57 |
+
05:08:01 - INFO - root - [Tool] Retrieved 5 chunks
|
| 58 |
+
05:08:03 - INFO - httpx - HTTP Request: POST https://api.openai.com/v1/traces/ingest "HTTP/1.1 204 No Content"
|
| 59 |
+
05:08:06 - INFO - httpx - HTTP Request: POST https://api.openai.com/v1/responses "HTTP/1.1 200 OK"
|
| 60 |
+
05:08:06 - INFO - root - [6ad72fe1] Completed: tokens=1957, sources=5
|
| 61 |
+
INFO: 127.0.0.1:51824 - "POST /chat HTTP/1.1" 200 OK
|
| 62 |
+
05:08:08 - INFO - httpx - HTTP Request: POST https://api.openai.com/v1/traces/ingest "HTTP/1.1 204 No Content"
|
| 63 |
+
05:11:23 - INFO - httpx - HTTP Request: GET https://d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io:6333 "HTTP/1.1 200 OK"
|
| 64 |
+
05:11:23 - INFO - httpx - HTTP Request: GET https://d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io:6333/collections/book_embeddings "HTTP/1.1 200 OK"
|
| 65 |
+
05:11:24 - INFO - httpx - HTTP Request: POST https://api.openai.com/v1/responses "HTTP/1.1 200 OK"
|
| 66 |
+
INFO: 127.0.0.1:56880 - "GET /health HTTP/1.1" 200 OK
|
| 67 |
+
05:11:27 - INFO - httpx - HTTP Request: POST https://api.openai.com/v1/traces/ingest "HTTP/1.1 204 No Content"
|
| 68 |
+
05:11:36 - INFO - root - [5177fa40] Received chat: What is ROS 2?...
|
| 69 |
+
05:11:37 - INFO - httpx - HTTP Request: POST https://api.openai.com/v1/traces/ingest "HTTP/1.1 204 No Content"
|
| 70 |
+
05:11:39 - INFO - httpx - HTTP Request: POST https://api.openai.com/v1/responses "HTTP/1.1 200 OK"
|
| 71 |
+
05:11:39 - INFO - root - [Tool] retrieve_chunks called: query='What is ROS 2?...', top_k=5
|
| 72 |
+
05:11:40 - INFO - httpx - HTTP Request: GET https://d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io:6333 "HTTP/1.1 200 OK"
|
| 73 |
+
05:11:40 - INFO - backend.retrieve - Embedding query: 'What is ROS 2?...' (top_k=5)
|
| 74 |
+
05:11:40 - INFO - httpx - HTTP Request: POST https://api.cohere.com/v2/embed "HTTP/1.1 200 OK"
|
| 75 |
+
05:11:38 - INFO - httpx - HTTP Request: POST https://d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io:6333/collections/book_embeddings/points/query "HTTP/1.1 200 OK"
|
| 76 |
+
05:11:38 - INFO - backend.retrieve - Search completed in -1.87s, returned 5 results
|
| 77 |
+
05:11:38 - INFO - backend.retrieve - Total query time: -1.18s
|
| 78 |
+
05:11:38 - INFO - root - [Tool] Retrieved 5 chunks
|
| 79 |
+
05:11:43 - INFO - httpx - HTTP Request: POST https://api.openai.com/v1/traces/ingest "HTTP/1.1 204 No Content"
|
| 80 |
+
05:11:43 - INFO - httpx - HTTP Request: POST https://api.openai.com/v1/responses "HTTP/1.1 200 OK"
|
| 81 |
+
05:11:43 - INFO - root - [5177fa40] Completed: tokens=1979, sources=5
|
| 82 |
+
INFO: 127.0.0.1:54308 - "POST /chat HTTP/1.1" 200 OK
|
| 83 |
+
05:11:49 - INFO - httpx - HTTP Request: POST https://api.openai.com/v1/traces/ingest "HTTP/1.1 204 No Content"
|
| 84 |
+
INFO: Shutting down
|
| 85 |
+
INFO: Waiting for application shutdown.
|
| 86 |
+
INFO: Application shutdown complete.
|
| 87 |
+
INFO: Finished server process [13073]
|
api.py
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
FastAPI wrapper for the RAG Book Assistant agent.
|
| 3 |
+
|
| 4 |
+
This module provides a standalone FastAPI application that exposes the
|
| 5 |
+
/chat endpoint using the agent defined in agent.py. It is separate from
|
| 6 |
+
agent.py to allow independent deployment and testing.
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
import os
|
| 10 |
+
import sys
|
| 11 |
+
import uuid
|
| 12 |
+
import asyncio
|
| 13 |
+
from datetime import datetime
|
| 14 |
+
from typing import List, Dict, Any, Optional
|
| 15 |
+
|
| 16 |
+
from fastapi import FastAPI, HTTPException
|
| 17 |
+
from fastapi.responses import JSONResponse
|
| 18 |
+
from fastapi.middleware.cors import CORSMiddleware
|
| 19 |
+
from pydantic import BaseModel, Field, validator
|
| 20 |
+
from dotenv import load_dotenv
|
| 21 |
+
|
| 22 |
+
# Make backend package importable
|
| 23 |
+
current_dir = os.path.dirname(os.path.abspath(__file__))
|
| 24 |
+
if current_dir not in sys.path:
|
| 25 |
+
sys.path.insert(0, current_dir)
|
| 26 |
+
|
| 27 |
+
# Load environment
|
| 28 |
+
load_dotenv()
|
| 29 |
+
|
| 30 |
+
# Import agent components
|
| 31 |
+
try:
|
| 32 |
+
from agent import get_agent, Runner
|
| 33 |
+
from agent import ToolCallOutputItem, Source as AgentSource
|
| 34 |
+
except ImportError as e:
|
| 35 |
+
raise ImportError(f"Failed to import agent module: {e}")
|
| 36 |
+
|
| 37 |
+
# Initialize FastAPI app
|
| 38 |
+
app = FastAPI(
|
| 39 |
+
title="RAG Chatbot API",
|
| 40 |
+
version="1.0.0",
|
| 41 |
+
description="FastAPI wrapper for RAG Book Assistant"
|
| 42 |
+
)
|
| 43 |
+
|
| 44 |
+
# ============ CORS Configuration ============
|
| 45 |
+
|
| 46 |
+
app.add_middleware(
|
| 47 |
+
CORSMiddleware,
|
| 48 |
+
allow_origins=[
|
| 49 |
+
"http://localhost:3000",
|
| 50 |
+
"http://127.0.0.1:3000",
|
| 51 |
+
"https://hackathon-1-humanoid-ai-robotics.vercel.app",
|
| 52 |
+
"https://*.vercel.app",
|
| 53 |
+
],
|
| 54 |
+
allow_credentials=True,
|
| 55 |
+
allow_methods=["*"],
|
| 56 |
+
allow_headers=["*"],
|
| 57 |
+
)
|
| 58 |
+
|
| 59 |
+
# ============ Pydantic Models ============
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
class ChatRequest(BaseModel):
|
| 63 |
+
question: str = Field(..., min_length=1, max_length=1000)
|
| 64 |
+
|
| 65 |
+
@validator('question')
|
| 66 |
+
def validate_question(cls, v):
|
| 67 |
+
if not v or not v.strip():
|
| 68 |
+
raise ValueError("Question cannot be empty")
|
| 69 |
+
return v.strip()
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
class Source(BaseModel):
|
| 73 |
+
url: str
|
| 74 |
+
chunk_index: int
|
| 75 |
+
text_snippet: str
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
class ChatResponse(BaseModel):
|
| 79 |
+
answer: str
|
| 80 |
+
sources: List[Source]
|
| 81 |
+
tokens_used: int
|
| 82 |
+
agent_trace: Optional[str] = None
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
class HealthStatus(BaseModel):
|
| 86 |
+
status: str
|
| 87 |
+
qdrant: str
|
| 88 |
+
openai: str
|
| 89 |
+
timestamp: str
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
# ============ Health Check ============
|
| 93 |
+
|
| 94 |
+
def check_qdrant_health() -> str:
|
| 95 |
+
try:
|
| 96 |
+
from backend.config import get_config
|
| 97 |
+
from qdrant_client import QdrantClient
|
| 98 |
+
cfg = get_config()
|
| 99 |
+
client = QdrantClient(url=cfg["qdrant_url"], api_key=cfg["qdrant_api_key"])
|
| 100 |
+
client.get_collection(cfg["qdrant_collection"])
|
| 101 |
+
return "connected"
|
| 102 |
+
except Exception as e:
|
| 103 |
+
return "disconnected"
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
def check_openai_health() -> str:
|
| 107 |
+
try:
|
| 108 |
+
api_key = os.getenv("OPENAI_API_KEY")
|
| 109 |
+
if not api_key:
|
| 110 |
+
return "disconnected"
|
| 111 |
+
import openai
|
| 112 |
+
client = openai.OpenAI(api_key=api_key)
|
| 113 |
+
client.models.list()
|
| 114 |
+
return "connected"
|
| 115 |
+
except Exception:
|
| 116 |
+
return "disconnected"
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
@app.get("/health", response_model=HealthStatus)
|
| 120 |
+
async def health_check():
|
| 121 |
+
qdrant = check_qdrant_health()
|
| 122 |
+
openai = check_openai_health()
|
| 123 |
+
status = "healthy" if qdrant == "connected" and openai == "connected" else "degraded"
|
| 124 |
+
return HealthStatus(
|
| 125 |
+
status=status,
|
| 126 |
+
qdrant=qdrant,
|
| 127 |
+
openai=openai,
|
| 128 |
+
timestamp=datetime.utcnow().isoformat() + "Z"
|
| 129 |
+
)
|
| 130 |
+
|
| 131 |
+
|
| 132 |
+
# ============ Chat Endpoint ============
|
| 133 |
+
|
| 134 |
+
@app.post("/chat")
|
| 135 |
+
async def chat_endpoint(request: ChatRequest):
|
| 136 |
+
request_id = str(uuid.uuid4())[:8]
|
| 137 |
+
question = request.question.strip()
|
| 138 |
+
|
| 139 |
+
try:
|
| 140 |
+
agent = get_agent()
|
| 141 |
+
|
| 142 |
+
# Run agent with timeout (20s to accommodate full workflow)
|
| 143 |
+
result = await asyncio.wait_for(
|
| 144 |
+
Runner.run(agent, question),
|
| 145 |
+
timeout=20.0
|
| 146 |
+
)
|
| 147 |
+
|
| 148 |
+
# Extract sources from tool call outputs
|
| 149 |
+
sources = []
|
| 150 |
+
if result.new_items:
|
| 151 |
+
for item in result.new_items:
|
| 152 |
+
if isinstance(item, ToolCallOutputItem):
|
| 153 |
+
output = item.output
|
| 154 |
+
if isinstance(output, list):
|
| 155 |
+
for chunk in output:
|
| 156 |
+
sources.append(Source(
|
| 157 |
+
url=chunk.get("url", ""),
|
| 158 |
+
chunk_index=chunk.get("chunk_index", 0),
|
| 159 |
+
text_snippet=chunk.get("text", "")[:200]
|
| 160 |
+
))
|
| 161 |
+
|
| 162 |
+
# Get token usage
|
| 163 |
+
tokens_used = 0
|
| 164 |
+
if result.context_wrapper and hasattr(result.context_wrapper, 'usage'):
|
| 165 |
+
tokens_used = result.context_wrapper.usage.total_tokens
|
| 166 |
+
|
| 167 |
+
return ChatResponse(
|
| 168 |
+
answer=result.final_output,
|
| 169 |
+
sources=sources,
|
| 170 |
+
tokens_used=tokens_used,
|
| 171 |
+
agent_trace=f"{request_id}: completed"
|
| 172 |
+
)
|
| 173 |
+
|
| 174 |
+
except asyncio.TimeoutError:
|
| 175 |
+
return JSONResponse(
|
| 176 |
+
status_code=504,
|
| 177 |
+
content={"error": "timeout", "message": "The chatbot is taking too long to respond. Please try a shorter question."}
|
| 178 |
+
)
|
| 179 |
+
|
| 180 |
+
except Exception as e:
|
| 181 |
+
if "openai" in str(e).lower() or "rate limit" in str(e).lower():
|
| 182 |
+
return JSONResponse(
|
| 183 |
+
status_code=503,
|
| 184 |
+
content={"error": "openai_failed", "message": "The AI service is currently unavailable. Please try again in a few minutes."}
|
| 185 |
+
)
|
| 186 |
+
return JSONResponse(
|
| 187 |
+
status_code=500,
|
| 188 |
+
content={"error": "internal_error", "message": "An unexpected error occurred. Please refresh the page and try again."}
|
| 189 |
+
)
|
| 190 |
+
|
| 191 |
+
|
| 192 |
+
if __name__ == "__main__":
|
| 193 |
+
import uvicorn
|
| 194 |
+
uvicorn.run(app, host="0.0.0.0", port=8000)
|
check_collection.py
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Check contents of the Qdrant collection.
|
| 3 |
+
"""
|
| 4 |
+
import sys
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
sys.path.insert(0, str(Path(__file__).parent))
|
| 7 |
+
|
| 8 |
+
import config
|
| 9 |
+
from qdrant_client import QdrantClient
|
| 10 |
+
|
| 11 |
+
cfg = config.get_config()
|
| 12 |
+
client = QdrantClient(url=cfg['qdrant_url'], api_key=cfg['qdrant_api_key'])
|
| 13 |
+
|
| 14 |
+
# Get collection info
|
| 15 |
+
info = client.get_collection(cfg['qdrant_collection'])
|
| 16 |
+
print(f"Collection: {cfg['qdrant_collection']}")
|
| 17 |
+
print(f"Total points: {info.points_count}")
|
| 18 |
+
print(f"Vector size: {info.config.params.vectors.size}")
|
| 19 |
+
print()
|
| 20 |
+
|
| 21 |
+
# Scroll through all points
|
| 22 |
+
if info.points_count > 0:
|
| 23 |
+
records = client.scroll(
|
| 24 |
+
collection_name=cfg['qdrant_collection'],
|
| 25 |
+
limit=min(10, info.points_count),
|
| 26 |
+
with_payload=True,
|
| 27 |
+
with_vectors=False
|
| 28 |
+
)[0]
|
| 29 |
+
|
| 30 |
+
print(f"Showing {len(records)} sample points:")
|
| 31 |
+
print("=" * 80)
|
| 32 |
+
|
| 33 |
+
for i, record in enumerate(records, 1):
|
| 34 |
+
print(f"\nPoint {i}:")
|
| 35 |
+
print(f" ID: {record.id}")
|
| 36 |
+
payload = record.payload or {}
|
| 37 |
+
print(f" URL: {payload.get('url', 'N/A')}")
|
| 38 |
+
print(f" Title: {payload.get('title', 'N/A')}")
|
| 39 |
+
print(f" Chunk index: {payload.get('chunk_index', 'N/A')}")
|
| 40 |
+
text = payload.get('text', '')
|
| 41 |
+
print(f" Text length: {len(text)} chars")
|
| 42 |
+
print(f" Text preview: {text[:200]}...")
|
| 43 |
+
|
| 44 |
+
print("\n" + "=" * 80)
|
| 45 |
+
|
| 46 |
+
# Check for unique URLs
|
| 47 |
+
all_records = client.scroll(
|
| 48 |
+
collection_name=cfg['qdrant_collection'],
|
| 49 |
+
limit=1000,
|
| 50 |
+
with_payload=True,
|
| 51 |
+
with_vectors=False
|
| 52 |
+
)[0]
|
| 53 |
+
|
| 54 |
+
unique_urls = set()
|
| 55 |
+
for rec in all_records:
|
| 56 |
+
if rec.payload and 'url' in rec.payload:
|
| 57 |
+
unique_urls.add(rec.payload['url'])
|
| 58 |
+
|
| 59 |
+
print(f"Unique URLs in collection: {len(unique_urls)}")
|
| 60 |
+
for url in unique_urls:
|
| 61 |
+
print(f" - {url}")
|
check_detailed.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Detailed check of all points in the collection.
|
| 3 |
+
"""
|
| 4 |
+
import sys
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
sys.path.insert(0, str(Path(__file__).parent))
|
| 7 |
+
|
| 8 |
+
import config
|
| 9 |
+
from qdrant_client import QdrantClient
|
| 10 |
+
|
| 11 |
+
cfg = config.get_config()
|
| 12 |
+
client = QdrantClient(url=cfg['qdrant_url'], api_key=cfg['qdrant_api_key'])
|
| 13 |
+
|
| 14 |
+
# Scroll through all points with full details
|
| 15 |
+
all_points = client.scroll(
|
| 16 |
+
collection_name=cfg['qdrant_collection'],
|
| 17 |
+
limit=1000,
|
| 18 |
+
with_payload=True,
|
| 19 |
+
with_vectors=False
|
| 20 |
+
)[0]
|
| 21 |
+
|
| 22 |
+
print(f"Total points in collection: {len(all_points)}")
|
| 23 |
+
print("=" * 100)
|
| 24 |
+
|
| 25 |
+
for i, point in enumerate(all_points, 1):
|
| 26 |
+
print(f"\nPoint {i}:")
|
| 27 |
+
print(f" ID: {point.id}")
|
| 28 |
+
payload = point.payload or {}
|
| 29 |
+
print(f" URL: {payload.get('url', 'N/A')}")
|
| 30 |
+
print(f" Title: {payload.get('title', 'N/A')}")
|
| 31 |
+
print(f" Section: {payload.get('section', 'N/A')}")
|
| 32 |
+
print(f" Chunk index: {payload.get('chunk_index', 'N/A')}")
|
| 33 |
+
text = payload.get('text', '')
|
| 34 |
+
print(f" Text length: {len(text)} chars")
|
| 35 |
+
print(f" Text (full):\n{text}")
|
| 36 |
+
print("-" * 100)
|
config.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Configuration loader for the ingestion pipeline.
|
| 3 |
+
Reads environment variables with .env support.
|
| 4 |
+
"""
|
| 5 |
+
import os
|
| 6 |
+
from dotenv import load_dotenv
|
| 7 |
+
|
| 8 |
+
# Load .env file if present
|
| 9 |
+
load_dotenv()
|
| 10 |
+
|
| 11 |
+
def get_config():
|
| 12 |
+
"""Get configuration from environment variables."""
|
| 13 |
+
return {
|
| 14 |
+
"cohere_api_key": os.getenv("COHERE_API_KEY"),
|
| 15 |
+
"qdrant_url": os.getenv("QDRANT_URL"),
|
| 16 |
+
"qdrant_api_key": os.getenv("QDRANT_API_KEY"),
|
| 17 |
+
"qdrant_collection": os.getenv("QDRANT_COLLECTION", "book_embeddings"),
|
| 18 |
+
"openai_api_key": os.getenv("OPENAI_API_KEY"),
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
def validate_config(config):
|
| 22 |
+
"""Validate that all required config values are set."""
|
| 23 |
+
required = ["cohere_api_key", "qdrant_url", "qdrant_api_key"]
|
| 24 |
+
missing = [key for key in required if not config.get(key)]
|
| 25 |
+
if missing:
|
| 26 |
+
raise ValueError(f"Missing required environment variables: {', '.join(missing)}")
|
| 27 |
+
return True
|
exceptions.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Custom exceptions for the RAG retrieval pipeline.
|
| 3 |
+
"""
|
| 4 |
+
from typing import Optional
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class ConfigurationError(Exception):
|
| 8 |
+
"""Raised when required configuration is missing or invalid."""
|
| 9 |
+
pass
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
class CollectionNotFoundError(Exception):
|
| 13 |
+
"""Raised when the specified Qdrant collection does not exist."""
|
| 14 |
+
pass
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
class DimensionMismatchError(Exception):
|
| 18 |
+
"""Raised when embedding dimension doesn't match collection vector size."""
|
| 19 |
+
pass
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
class APIError(Exception):
|
| 23 |
+
"""Raised when an external API (Cohere or Qdrant) call fails after retries."""
|
| 24 |
+
def __init__(self, message: str, original_exception: Optional[Exception] = None):
|
| 25 |
+
super().__init__(message)
|
| 26 |
+
self.original_exception = original_exception
|
extract_sitemap.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Fetch sitemap.xml and extract all page URLs.
|
| 3 |
+
"""
|
| 4 |
+
import sys
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
import httpx
|
| 7 |
+
import re
|
| 8 |
+
|
| 9 |
+
sys.path.insert(0, str(Path(__file__).parent))
|
| 10 |
+
|
| 11 |
+
sitemap_url = "https://humanoid-ai-robotics-book-1.vercel.app/sitemap.xml"
|
| 12 |
+
|
| 13 |
+
print(f"Fetching sitemap from: {sitemap_url}")
|
| 14 |
+
response = httpx.get(sitemap_url, timeout=30.0)
|
| 15 |
+
response.raise_for_status()
|
| 16 |
+
|
| 17 |
+
# Use regex to extract <loc> URLs from XML
|
| 18 |
+
content = response.text
|
| 19 |
+
urls = re.findall(r'<loc[^>]*>(.*?)</loc>', content, re.DOTALL)
|
| 20 |
+
urls = [url.strip() for url in urls if url.strip()]
|
| 21 |
+
|
| 22 |
+
print(f"Found {len(urls)} URLs in sitemap:")
|
| 23 |
+
for url in urls:
|
| 24 |
+
print(f" - {url}")
|
| 25 |
+
|
| 26 |
+
# Save to file
|
| 27 |
+
output_file = Path(__file__).parent / 'sitemap_urls.txt'
|
| 28 |
+
with open(output_file, 'w') as f:
|
| 29 |
+
for url in urls:
|
| 30 |
+
f.write(url + '\n')
|
| 31 |
+
|
| 32 |
+
print(f"\nSaved to: {output_file}")
|
history/prompts/frontend-chat-integration/4-implementation.tasks.prompt.md
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
id: 4
|
| 3 |
+
title: Implement frontend-backend chat integration
|
| 4 |
+
stage: tasks
|
| 5 |
+
date: 2025-02-18
|
| 6 |
+
surface: agent
|
| 7 |
+
model: claude-sonnet-4-5-20250929
|
| 8 |
+
feature: frontend-chat-integration
|
| 9 |
+
branch: 8-frontend-chat-integration
|
| 10 |
+
user: m-ahmad-official
|
| 11 |
+
command: /sp.implement
|
| 12 |
+
labels: [implementation, backend, frontend, fastapi, react, docusaurus]
|
| 13 |
+
links:
|
| 14 |
+
spec: specs/8-frontend-chat-integration/spec.md
|
| 15 |
+
plan: specs/8-frontend-chat-integration/plan.md
|
| 16 |
+
tasks: specs/8-frontend-chat-integration/tasks.md
|
| 17 |
+
adr: null
|
| 18 |
+
pr: null
|
| 19 |
+
files:
|
| 20 |
+
- backend/api.py
|
| 21 |
+
- frontend_book/src/components/ChatBot.tsx
|
| 22 |
+
- frontend_book/src/components/ChatBot.module.css
|
| 23 |
+
- frontend_book/src/theme/Root.tsx
|
| 24 |
+
- frontend_book/.env
|
| 25 |
+
tests: []
|
| 26 |
+
---
|
| 27 |
+
|
| 28 |
+
## Prompt
|
| 29 |
+
|
| 30 |
+
/sp.implement (execute all tasks)
|
| 31 |
+
|
| 32 |
+
## Response snapshot
|
| 33 |
+
|
| 34 |
+
Executed all 28 tasks from tasks.md across 6 phases:
|
| 35 |
+
|
| 36 |
+
**Phase 1 (Setup)**: Verified backend agent.py, frontend_book structure, created .env with VITE_API_BASE_URL, installed npm dependencies
|
| 37 |
+
**Phase 2 (Foundational)**: Created backend/api.py with FastAPI app, CORS middleware, health check
|
| 38 |
+
**Phase 3 (US1-P1)**: Implemented POST /chat with agent invocation, 20s timeout, source extraction, token tracking, error handling; tested with curl (success)
|
| 39 |
+
**Phase 4 (US2-P2)**: Created ChatBot.module.css with responsive styles: desktop (380px fixed panel) and mobile (full-screen overlay)
|
| 40 |
+
**Phase 5 (US3-P3)**: Implemented localStorage persistence in ChatBot.tsx with versioned schema
|
| 41 |
+
**Phase 6 (Polish)**: Integrated globally via src/theme/Root.tsx, added character count (FR-015) and Clear Chat button
|
| 42 |
+
|
| 43 |
+
All files created and validated.
|
| 44 |
+
|
| 45 |
+
## Outcome
|
| 46 |
+
|
| 47 |
+
- ✅ Impact: Complete implementation; backend/frontend integrated and ready for testing
|
| 48 |
+
- 🧪 Tests: End-to-end manual testing recommended; /chat endpoint verified
|
| 49 |
+
- 📁 Files: api.py, ChatBot.tsx, ChatBot.module.css, Root.tsx, .env created
|
| 50 |
+
- 🔁 Next prompts: Manual integration testing; consider /sp.test if applicable
|
| 51 |
+
- 🧠 Reflection: Minimal, isolated changes respect implementation boundaries. Backend wrapper cleanly reuses agent.py; frontend component self-contained.
|
| 52 |
+
|
| 53 |
+
## Evaluation notes (flywheel)
|
| 54 |
+
|
| 55 |
+
- Failure modes: None
|
| 56 |
+
- Next experiment: N/A
|
ingestion.log
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
local_test.log
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
INFO: Extracted 781 characters from fixture
|
| 2 |
+
Text preview: Sample Book Page - Introduction
|
| 3 |
+
Chapter 1: Introduction
|
| 4 |
+
This is the first paragraph of the introduction. It provides an overview of the topic.
|
| 5 |
+
The second paragraph discusses the background and context...
|
| 6 |
+
INFO: Chunked into 2 segments
|
| 7 |
+
First chunk: Sample Book Page - Introduction
|
| 8 |
+
Chapter 1: Introduction
|
| 9 |
+
This is the first paragraph of the introduct...
|
| 10 |
+
INFO: HTTP Request: POST https://api.cohere.com/v2/embed "HTTP/1.1 200 OK"
|
| 11 |
+
INFO: Generated 6 embeddings
|
| 12 |
+
Embedding dimension: 2
|
| 13 |
+
INFO: HTTP Request: GET https://d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io:6333 "HTTP/1.1 200 OK"
|
| 14 |
+
INFO: HTTP Request: GET https://d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io:6333/collections "HTTP/1.1 200 OK"
|
| 15 |
+
INFO: Collection 'book_embeddings' already exists
|
| 16 |
+
ERROR: Test failed: 'PosixPath' object has no attribute 'path'
|
| 17 |
+
Traceback (most recent call last):
|
| 18 |
+
File "/mnt/e/7. Low Code Agentic AI/Hackathon I/humanoid-ai-robotics-book-chatbot/backend/test_local.py", line 93, in <module>
|
| 19 |
+
test_with_fixture()
|
| 20 |
+
File "/mnt/e/7. Low Code Agentic AI/Hackathon I/humanoid-ai-robotics-book-chatbot/backend/test_local.py", line 67, in test_with_fixture
|
| 21 |
+
'title': Path(url).path,
|
| 22 |
+
^^^^^^^^^^^^^^
|
| 23 |
+
AttributeError: 'PosixPath' object has no attribute 'path'
|
logging_config.py
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Logging configuration for the ingestion pipeline.
|
| 3 |
+
"""
|
| 4 |
+
import logging
|
| 5 |
+
import sys
|
| 6 |
+
import json
|
| 7 |
+
from pathlib import Path
|
| 8 |
+
from datetime import datetime
|
| 9 |
+
|
| 10 |
+
def setup_logging(log_file: str = "agent.log", console_level: str = None):
|
| 11 |
+
"""
|
| 12 |
+
Configure logging to both file (JSON structured) and console (human-readable).
|
| 13 |
+
|
| 14 |
+
Args:
|
| 15 |
+
log_file: Path to log file (default: agent.log)
|
| 16 |
+
console_level: Log level for console output (defaults to LOG_LEVEL env var or INFO)
|
| 17 |
+
"""
|
| 18 |
+
import os
|
| 19 |
+
|
| 20 |
+
logger = logging.getLogger()
|
| 21 |
+
logger.setLevel(logging.DEBUG)
|
| 22 |
+
|
| 23 |
+
# Clear any existing handlers
|
| 24 |
+
logger.handlers = []
|
| 25 |
+
|
| 26 |
+
# Determine log level from environment or default
|
| 27 |
+
log_level_env = os.getenv("LOG_LEVEL", "INFO").upper()
|
| 28 |
+
console_level = console_level or log_level_env
|
| 29 |
+
|
| 30 |
+
# Validate log level
|
| 31 |
+
valid_levels = ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"]
|
| 32 |
+
if console_level not in valid_levels:
|
| 33 |
+
console_level = "INFO"
|
| 34 |
+
|
| 35 |
+
# ============ File Handler - JSON Structured Format ============
|
| 36 |
+
file_handler = logging.FileHandler(log_file, mode='a', encoding='utf-8')
|
| 37 |
+
file_handler.setLevel(logging.DEBUG)
|
| 38 |
+
|
| 39 |
+
class JSONFormatter(logging.Formatter):
|
| 40 |
+
"""Format log records as JSON for structured logging."""
|
| 41 |
+
def format(self, record):
|
| 42 |
+
log_object = {
|
| 43 |
+
"timestamp": datetime.utcfromtimestamp(record.created).isoformat() + "Z",
|
| 44 |
+
"level": record.levelname,
|
| 45 |
+
"name": record.name,
|
| 46 |
+
"message": record.getMessage(),
|
| 47 |
+
"module": record.module,
|
| 48 |
+
"lineno": record.lineno,
|
| 49 |
+
}
|
| 50 |
+
# Include exception info if present
|
| 51 |
+
if record.exc_info:
|
| 52 |
+
log_object["exc_info"] = self.formatException(record.exc_info)
|
| 53 |
+
if record.stack_info:
|
| 54 |
+
log_object["stack_info"] = record.stack_info
|
| 55 |
+
# Include extra fields
|
| 56 |
+
for key, value in record.__dict__.items():
|
| 57 |
+
if key not in ['name', 'msg', 'args', 'created', 'filename', 'module',
|
| 58 |
+
'levelno', 'levelname', 'lineno', 'funcName', 'relativeCreated',
|
| 59 |
+
'msecs', 'abs_path', 'exc_info', 'exc_text', 'stack_info',
|
| 60 |
+
'message']:
|
| 61 |
+
log_object[key] = value
|
| 62 |
+
return json.dumps(log_object)
|
| 63 |
+
|
| 64 |
+
file_formatter = JSONFormatter()
|
| 65 |
+
file_handler.setFormatter(file_formatter)
|
| 66 |
+
|
| 67 |
+
# ============ Console Handler - Human-Readable ============
|
| 68 |
+
console_handler = logging.StreamHandler(sys.stdout)
|
| 69 |
+
console_handler.setLevel(getattr(logging, console_level))
|
| 70 |
+
console_formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(name)s - %(message)s',
|
| 71 |
+
datefmt='%H:%M:%S')
|
| 72 |
+
console_handler.setFormatter(console_formatter)
|
| 73 |
+
|
| 74 |
+
logger.addHandler(file_handler)
|
| 75 |
+
logger.addHandler(console_handler)
|
| 76 |
+
|
| 77 |
+
return logger
|
main.py
ADDED
|
@@ -0,0 +1,434 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Vector Data Ingestion Pipeline
|
| 3 |
+
|
| 4 |
+
Fetches book content from URLs, extracts text, chunks, generates embeddings with Cohere,
|
| 5 |
+
and stores in Qdrant Cloud.
|
| 6 |
+
"""
|
| 7 |
+
import argparse
|
| 8 |
+
import sys
|
| 9 |
+
import os
|
| 10 |
+
import time
|
| 11 |
+
from pathlib import Path
|
| 12 |
+
from typing import List, Dict, Any
|
| 13 |
+
|
| 14 |
+
import httpx
|
| 15 |
+
from bs4 import BeautifulSoup
|
| 16 |
+
import cohere
|
| 17 |
+
from qdrant_client import QdrantClient
|
| 18 |
+
from qdrant_client.models import Distance, VectorParams, PointStruct
|
| 19 |
+
from dotenv import load_dotenv
|
| 20 |
+
|
| 21 |
+
import config
|
| 22 |
+
import utils
|
| 23 |
+
from logging_config import setup_logging
|
| 24 |
+
|
| 25 |
+
# Initialize logging
|
| 26 |
+
logger = setup_logging()
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def fetch_url(url: str, client: httpx.Client, max_retries: int = 5) -> str:
|
| 30 |
+
"""
|
| 31 |
+
Fetch HTML content from a URL with retry logic.
|
| 32 |
+
Returns HTML string or raises after max retries.
|
| 33 |
+
"""
|
| 34 |
+
logger.info(f"Fetching {url}...")
|
| 35 |
+
for attempt in range(max_retries):
|
| 36 |
+
try:
|
| 37 |
+
response = client.get(url, timeout=30.0)
|
| 38 |
+
response.raise_for_status()
|
| 39 |
+
logger.debug(f"Successfully fetched {url} (status: {response.status_code})")
|
| 40 |
+
return response.text
|
| 41 |
+
except httpx.HTTPError as e:
|
| 42 |
+
if attempt == max_retries - 1:
|
| 43 |
+
logger.error(f"Failed to fetch {url} after {max_retries} attempts: {e}")
|
| 44 |
+
raise
|
| 45 |
+
delay = 2 ** attempt # Simple backoff
|
| 46 |
+
time.sleep(delay)
|
| 47 |
+
return ""
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
def extract_text(html: str, url: str) -> str:
|
| 51 |
+
"""
|
| 52 |
+
Extract clean text from HTML.
|
| 53 |
+
Removes scripts, styles, nav, footer, etc.
|
| 54 |
+
Preserves paragraph structure.
|
| 55 |
+
"""
|
| 56 |
+
soup = BeautifulSoup(html, 'html.parser')
|
| 57 |
+
|
| 58 |
+
# Remove non-content elements
|
| 59 |
+
for selector in ['script', 'style', 'nav', 'footer', 'header', 'aside']:
|
| 60 |
+
for element in soup.find_all(selector):
|
| 61 |
+
element.decompose()
|
| 62 |
+
|
| 63 |
+
# Get text with newlines between elements
|
| 64 |
+
text = soup.get_text(separator='\n', strip=True)
|
| 65 |
+
|
| 66 |
+
# Normalize whitespace
|
| 67 |
+
lines = [line.strip() for line in text.split('\n') if line.strip()]
|
| 68 |
+
clean_text = '\n'.join(lines)
|
| 69 |
+
|
| 70 |
+
return clean_text
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
def chunk_text(text: str, chunk_size: int = 1000, overlap: int = 100) -> List[Dict[str, Any]]:
|
| 74 |
+
"""
|
| 75 |
+
Split text into overlapping chunks.
|
| 76 |
+
Returns list of dicts with text and char_start/end.
|
| 77 |
+
"""
|
| 78 |
+
if len(text) <= chunk_size:
|
| 79 |
+
return [{'text': text, 'char_start': 0, 'char_end': len(text)}]
|
| 80 |
+
|
| 81 |
+
chunks = []
|
| 82 |
+
start = 0
|
| 83 |
+
text_len = len(text)
|
| 84 |
+
|
| 85 |
+
while start < text_len:
|
| 86 |
+
end = min(start + chunk_size, text_len)
|
| 87 |
+
|
| 88 |
+
# If not first chunk, include overlap from previous chunk's tail
|
| 89 |
+
if start > 0:
|
| 90 |
+
start -= overlap
|
| 91 |
+
if start < 0:
|
| 92 |
+
start = 0
|
| 93 |
+
|
| 94 |
+
chunk_text = text[start:end]
|
| 95 |
+
chunks.append({
|
| 96 |
+
'text': chunk_text,
|
| 97 |
+
'char_start': start,
|
| 98 |
+
'char_end': end
|
| 99 |
+
})
|
| 100 |
+
|
| 101 |
+
# Move to next chunk (exclusive end becomes new start)
|
| 102 |
+
start = end
|
| 103 |
+
|
| 104 |
+
# If we're at the end, break
|
| 105 |
+
if end >= text_len:
|
| 106 |
+
break
|
| 107 |
+
|
| 108 |
+
return chunks
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
def generate_embeddings(texts: List[str], cohere_client: cohere.ClientV2, batch_size: int = 96) -> List[List[float]]:
|
| 112 |
+
"""
|
| 113 |
+
Generate embeddings for a list of texts using Cohere.
|
| 114 |
+
Batches requests to optimize throughput.
|
| 115 |
+
"""
|
| 116 |
+
all_embeddings = []
|
| 117 |
+
|
| 118 |
+
for i in range(0, len(texts), batch_size):
|
| 119 |
+
batch = texts[i:i+batch_size]
|
| 120 |
+
try:
|
| 121 |
+
response = cohere_client.embed(
|
| 122 |
+
texts=batch,
|
| 123 |
+
model="embed-english-v3.0",
|
| 124 |
+
input_type="search_document"
|
| 125 |
+
)
|
| 126 |
+
# Cohere SDK v2 returns EmbedByTypeResponse with embeddings.float_ containing the vectors
|
| 127 |
+
embeddings_list = response.embeddings.float_
|
| 128 |
+
|
| 129 |
+
# Log the dimension from the first embedding
|
| 130 |
+
if embeddings_list and len(all_embeddings) == 0:
|
| 131 |
+
first_embed = embeddings_list[0]
|
| 132 |
+
if hasattr(first_embed, '__len__') and not isinstance(first_embed, str):
|
| 133 |
+
dim = len(first_embed)
|
| 134 |
+
logger.info(f"Cohere returned embeddings with dimension: {dim}")
|
| 135 |
+
else:
|
| 136 |
+
logger.info(f"Cohere returned embedding type: {type(first_embed)}")
|
| 137 |
+
|
| 138 |
+
# embeddings_list is already a list of vectors (list of floats)
|
| 139 |
+
all_embeddings.extend(embeddings_list)
|
| 140 |
+
|
| 141 |
+
logger.debug(f"Generated embeddings for batch {i//batch_size + 1}/{(len(texts)-1)//batch_size + 1}")
|
| 142 |
+
except Exception as e:
|
| 143 |
+
logger.error(f"Failed to generate embeddings for batch starting at index {i}: {e}")
|
| 144 |
+
raise
|
| 145 |
+
|
| 146 |
+
if not all_embeddings:
|
| 147 |
+
raise ValueError("No embeddings generated")
|
| 148 |
+
|
| 149 |
+
# Validate dimension - should be 1024 for embed-english-v3.0
|
| 150 |
+
actual_dim = len(all_embeddings[0]) if hasattr(all_embeddings[0], '__len__') else len(all_embeddings[0])
|
| 151 |
+
if actual_dim != 1024:
|
| 152 |
+
logger.warning(f"Unexpected embedding dimension: {actual_dim} (expected 1024). Proceeding anyway.")
|
| 153 |
+
|
| 154 |
+
return all_embeddings
|
| 155 |
+
|
| 156 |
+
|
| 157 |
+
def ensure_collection(client: QdrantClient, collection_name: str, vector_size: int = 1024):
|
| 158 |
+
"""
|
| 159 |
+
Create collection if it doesn't exist.
|
| 160 |
+
"""
|
| 161 |
+
try:
|
| 162 |
+
collections = client.get_collections().collections
|
| 163 |
+
collection_names = [c.name for c in collections]
|
| 164 |
+
if collection_name not in collection_names:
|
| 165 |
+
logger.info(f"Creating collection '{collection_name}'")
|
| 166 |
+
client.create_collection(
|
| 167 |
+
collection_name=collection_name,
|
| 168 |
+
vectors_config=VectorParams(size=vector_size, distance=Distance.COSINE)
|
| 169 |
+
)
|
| 170 |
+
logger.info(f"Collection '{collection_name}' created with vector size {vector_size}")
|
| 171 |
+
else:
|
| 172 |
+
logger.info(f"Collection '{collection_name}' already exists")
|
| 173 |
+
except Exception as e:
|
| 174 |
+
logger.error(f"Failed to ensure collection: {e}")
|
| 175 |
+
raise
|
| 176 |
+
|
| 177 |
+
|
| 178 |
+
def upsert_chunks(
|
| 179 |
+
client: QdrantClient,
|
| 180 |
+
collection_name: str,
|
| 181 |
+
records: List[Dict[str, Any]],
|
| 182 |
+
deterministic_id_func,
|
| 183 |
+
track_changes: bool = False
|
| 184 |
+
) -> Dict[str, int]:
|
| 185 |
+
"""
|
| 186 |
+
Upsert chunk records to Qdrant.
|
| 187 |
+
Uses deterministic IDs for idempotency.
|
| 188 |
+
Returns statistics: {'new': X, 'updated': Y, 'total': Z}
|
| 189 |
+
"""
|
| 190 |
+
points = []
|
| 191 |
+
for record in records:
|
| 192 |
+
point_id = deterministic_id_func(record['url'], record['chunk_index'])
|
| 193 |
+
# Verify ID is consistent (US2 - idempotency check)
|
| 194 |
+
verify_id = utils.verify_deterministic_id(record['url'], record['chunk_index'], point_id)
|
| 195 |
+
assert verify_id == point_id, "Deterministic ID verification failed"
|
| 196 |
+
|
| 197 |
+
point = PointStruct(
|
| 198 |
+
id=point_id,
|
| 199 |
+
vector=record['embedding'],
|
| 200 |
+
payload={
|
| 201 |
+
'url': record['url'],
|
| 202 |
+
'title': record.get('title', ''),
|
| 203 |
+
'section': record.get('section', ''),
|
| 204 |
+
'chunk_index': record['chunk_index'],
|
| 205 |
+
'text': record['text']
|
| 206 |
+
}
|
| 207 |
+
)
|
| 208 |
+
points.append(point)
|
| 209 |
+
|
| 210 |
+
# Batch upsert (Qdrant client handles batching internally if needed)
|
| 211 |
+
try:
|
| 212 |
+
# For now, we don't distinguish new vs updated without a pre-query
|
| 213 |
+
# But we can report total upserted
|
| 214 |
+
client.upsert(collection_name=collection_name, points=points)
|
| 215 |
+
logger.info(f"Upserted {len(points)} points to collection '{collection_name}'")
|
| 216 |
+
# In future, could check which points already existed by doing a scroll before upsert
|
| 217 |
+
return {'new': len(points), 'updated': 0, 'total': len(points)}
|
| 218 |
+
except Exception as e:
|
| 219 |
+
logger.error(f"Failed to upsert points: {e}")
|
| 220 |
+
raise
|
| 221 |
+
|
| 222 |
+
|
| 223 |
+
def main():
|
| 224 |
+
"""Main orchestration function."""
|
| 225 |
+
parser = argparse.ArgumentParser(description="Ingest book content into Qdrant")
|
| 226 |
+
parser.add_argument('--urls', nargs='+', help='List of URLs to ingest')
|
| 227 |
+
parser.add_argument('--urls-file', help='File containing one URL per line')
|
| 228 |
+
parser.add_argument('--chunk-size', type=int, default=1000, help='Chunk size in characters')
|
| 229 |
+
parser.add_argument('--overlap', type=int, default=100, help='Overlap between chunks in characters')
|
| 230 |
+
parser.add_argument('--batch-size', type=int, default=96, help='Embedding API batch size (max 96 for Cohere trial)')
|
| 231 |
+
parser.add_argument('--max-retries', type=int, default=5, help='Max retries for API calls')
|
| 232 |
+
parser.add_argument('--validate', action='store_true', help='Run validation only (no ingestion)')
|
| 233 |
+
parser.add_argument('--validate-sample', type=int, default=100, help='Number of sample points to check during validation')
|
| 234 |
+
args = parser.parse_args()
|
| 235 |
+
|
| 236 |
+
# Load and validate config
|
| 237 |
+
cfg = config.get_config()
|
| 238 |
+
config.validate_config(cfg)
|
| 239 |
+
|
| 240 |
+
# Initialize Qdrant client
|
| 241 |
+
qdrant_client = QdrantClient(
|
| 242 |
+
url=cfg['qdrant_url'],
|
| 243 |
+
api_key=cfg['qdrant_api_key']
|
| 244 |
+
)
|
| 245 |
+
ensure_collection(qdrant_client, cfg['qdrant_collection'])
|
| 246 |
+
|
| 247 |
+
# Validation-only mode
|
| 248 |
+
if args.validate:
|
| 249 |
+
run_validation(qdrant_client, cfg['qdrant_collection'], args.validate_sample)
|
| 250 |
+
sys.exit(0)
|
| 251 |
+
|
| 252 |
+
# Ingestion mode
|
| 253 |
+
cohere_client = cohere.ClientV2(api_key=cfg['cohere_api_key'])
|
| 254 |
+
|
| 255 |
+
# Get URLs
|
| 256 |
+
urls = []
|
| 257 |
+
if args.urls:
|
| 258 |
+
urls.extend(args.urls)
|
| 259 |
+
if args.urls_file:
|
| 260 |
+
with open(args.urls_file, 'r') as f:
|
| 261 |
+
urls.extend([line.strip() for line in f if line.strip()])
|
| 262 |
+
|
| 263 |
+
if not urls:
|
| 264 |
+
logger.error("No URLs provided. Use --urls or --urls-file")
|
| 265 |
+
sys.exit(1)
|
| 266 |
+
|
| 267 |
+
logger.info(f"Starting ingestion: {len(urls)} URLs")
|
| 268 |
+
logger.info(f"Chunk size: {args.chunk_size}, overlap: {args.overlap}")
|
| 269 |
+
|
| 270 |
+
total_chunks = 0
|
| 271 |
+
total_pages = 0
|
| 272 |
+
errors = []
|
| 273 |
+
|
| 274 |
+
# Process each URL
|
| 275 |
+
with httpx.Client() as http_client:
|
| 276 |
+
for url in urls:
|
| 277 |
+
try:
|
| 278 |
+
html = fetch_url(url, http_client, max_retries=args.max_retries)
|
| 279 |
+
text = extract_text(html, url)
|
| 280 |
+
|
| 281 |
+
if not text or len(text) < 10:
|
| 282 |
+
logger.warning(f"Page {url} has insufficient text content, skipping")
|
| 283 |
+
continue
|
| 284 |
+
|
| 285 |
+
chunks_data = chunk_text(text, chunk_size=args.chunk_size, overlap=args.overlap)
|
| 286 |
+
logger.info(f"Extracted {len(text)} characters from {url}, chunked into {len(chunks_data)} segments")
|
| 287 |
+
|
| 288 |
+
# Prepare texts for embedding
|
| 289 |
+
texts = [chunk['text'] for chunk in chunks_data]
|
| 290 |
+
embeddings = generate_embeddings(texts, cohere_client, batch_size=args.batch_size)
|
| 291 |
+
|
| 292 |
+
# Validate dimensions
|
| 293 |
+
if embeddings:
|
| 294 |
+
actual_dim = len(embeddings[0]) if hasattr(embeddings[0], '__len__') else len(embeddings[0])
|
| 295 |
+
if actual_dim != 1024:
|
| 296 |
+
logger.warning(f"Embedding dimension {actual_dim} != 1024. Check Cohere model. Proceeding anyway.")
|
| 297 |
+
|
| 298 |
+
# Prepare records for Qdrant
|
| 299 |
+
records = []
|
| 300 |
+
for i, (chunk, embedding) in enumerate(zip(chunks_data, embeddings)):
|
| 301 |
+
record = {
|
| 302 |
+
'url': url,
|
| 303 |
+
'title': url, # Use full URL as title
|
| 304 |
+
'section': '', # TODO: extract from headings
|
| 305 |
+
'chunk_index': i,
|
| 306 |
+
'text': chunk['text'],
|
| 307 |
+
'embedding': embedding
|
| 308 |
+
}
|
| 309 |
+
records.append(record)
|
| 310 |
+
|
| 311 |
+
# Upsert to Qdrant
|
| 312 |
+
stats = upsert_chunks(qdrant_client, cfg['qdrant_collection'], records, utils.deterministic_id)
|
| 313 |
+
total_chunks += stats['total']
|
| 314 |
+
total_pages += 1
|
| 315 |
+
logger.info(f"Successfully processed {url}")
|
| 316 |
+
|
| 317 |
+
except Exception as e:
|
| 318 |
+
logger.error(f"Failed to process {url}: {e}")
|
| 319 |
+
errors.append(url)
|
| 320 |
+
continue
|
| 321 |
+
|
| 322 |
+
# Summary
|
| 323 |
+
logger.info("=" * 50)
|
| 324 |
+
logger.info(f"Ingestion complete!")
|
| 325 |
+
logger.info(f"Total pages processed: {total_pages}")
|
| 326 |
+
logger.info(f"Total chunks stored: {total_chunks}")
|
| 327 |
+
if errors:
|
| 328 |
+
logger.warning(f"Failed URLs ({len(errors)}): {', '.join(errors)}")
|
| 329 |
+
logger.info("=" * 50)
|
| 330 |
+
|
| 331 |
+
# Verify collection
|
| 332 |
+
try:
|
| 333 |
+
info = qdrant_client.get_collection(cfg['qdrant_collection'])
|
| 334 |
+
logger.info(f"Qdrant collection '{cfg['qdrant_collection']}' now has {info.points_count} points")
|
| 335 |
+
except Exception as e:
|
| 336 |
+
logger.error(f"Could not verify collection: {e}")
|
| 337 |
+
|
| 338 |
+
sys.exit(0 if not errors else 1)
|
| 339 |
+
|
| 340 |
+
|
| 341 |
+
def run_validation(client: QdrantClient, collection_name: str, sample_size: int = 100):
|
| 342 |
+
"""
|
| 343 |
+
Run validation checks on the Qdrant collection.
|
| 344 |
+
Checks: dimensions, metadata completeness, sampling.
|
| 345 |
+
"""
|
| 346 |
+
logger.info("=" * 50)
|
| 347 |
+
logger.info("Running validation mode...")
|
| 348 |
+
logger.info("=" * 50)
|
| 349 |
+
|
| 350 |
+
try:
|
| 351 |
+
# Get collection info
|
| 352 |
+
info = client.get_collection(collection_name)
|
| 353 |
+
total_points = info.points_count
|
| 354 |
+
vector_size = info.config.params.vectors.size
|
| 355 |
+
|
| 356 |
+
logger.info(f"Collection: {collection_name}")
|
| 357 |
+
logger.info(f"Total points: {total_points}")
|
| 358 |
+
logger.info(f"Vector size: {vector_size}")
|
| 359 |
+
|
| 360 |
+
# Validate dimension
|
| 361 |
+
if vector_size != 1024:
|
| 362 |
+
logger.error(f"❌ Invalid vector size: {vector_size} (expected 1024)")
|
| 363 |
+
else:
|
| 364 |
+
logger.info("✅ Vector dimension correct (1024)")
|
| 365 |
+
|
| 366 |
+
# Sample points to check metadata and text
|
| 367 |
+
if total_points > 0:
|
| 368 |
+
sample_count = min(sample_size, total_points)
|
| 369 |
+
logger.info(f"Sampling {sample_count} points for validation...")
|
| 370 |
+
|
| 371 |
+
# Scroll through some points
|
| 372 |
+
records = client.scroll(
|
| 373 |
+
collection_name=collection_name,
|
| 374 |
+
limit=sample_count,
|
| 375 |
+
with_payload=True,
|
| 376 |
+
with_vectors=False
|
| 377 |
+
)[0]
|
| 378 |
+
|
| 379 |
+
url_ok = 0
|
| 380 |
+
title_section_ok = 0
|
| 381 |
+
text_nonempty = 0
|
| 382 |
+
dimension_checks = 0
|
| 383 |
+
|
| 384 |
+
for record in records:
|
| 385 |
+
payload = record.payload or {}
|
| 386 |
+
|
| 387 |
+
# Check URL presence
|
| 388 |
+
if payload.get('url'):
|
| 389 |
+
url_ok += 1
|
| 390 |
+
|
| 391 |
+
# Check title or section presence
|
| 392 |
+
if payload.get('title') or payload.get('section'):
|
| 393 |
+
title_section_ok += 1
|
| 394 |
+
|
| 395 |
+
# Check text non-empty
|
| 396 |
+
if payload.get('text') and len(payload['text']) >= 10:
|
| 397 |
+
text_nonempty += 1
|
| 398 |
+
|
| 399 |
+
# Calculate percentages
|
| 400 |
+
url_pct = (url_ok / sample_count) * 100
|
| 401 |
+
title_section_pct = (title_section_ok / sample_count) * 100
|
| 402 |
+
text_pct = (text_nonempty / sample_count) * 100
|
| 403 |
+
|
| 404 |
+
logger.info(f"Metadata completeness:")
|
| 405 |
+
logger.info(f" URL present: {url_ok}/{sample_count} ({url_pct:.1f}%)")
|
| 406 |
+
logger.info(f" Title/Section present: {title_section_ok}/{sample_count} ({title_section_pct:.1f}%)")
|
| 407 |
+
logger.info(f" Text non-empty (≥10 chars): {text_nonempty}/{sample_count} ({text_pct:.1f}%)")
|
| 408 |
+
|
| 409 |
+
# Validation thresholds
|
| 410 |
+
if url_pct >= 99:
|
| 411 |
+
logger.info("✅ URL completeness excellent (≥99%)")
|
| 412 |
+
else:
|
| 413 |
+
logger.warning(f"⚠️ URL completeness below 99%: {url_pct:.1f}%")
|
| 414 |
+
|
| 415 |
+
if title_section_pct >= 95:
|
| 416 |
+
logger.info("✅ Title/Section completeness good (≥95%)")
|
| 417 |
+
else:
|
| 418 |
+
logger.warning(f"⚠️ Title/Section completeness below 95%: {title_section_pct:.1f}%")
|
| 419 |
+
|
| 420 |
+
if text_pct >= 98:
|
| 421 |
+
logger.info("✅ Text quality excellent (≥98%)")
|
| 422 |
+
else:
|
| 423 |
+
logger.warning(f"⚠️ Text quality below 98%: {text_pct:.1f}%")
|
| 424 |
+
|
| 425 |
+
logger.info("=" * 50)
|
| 426 |
+
logger.info("Validation complete!")
|
| 427 |
+
|
| 428 |
+
except Exception as e:
|
| 429 |
+
logger.error(f"Validation failed: {e}")
|
| 430 |
+
raise
|
| 431 |
+
|
| 432 |
+
|
| 433 |
+
if __name__ == "__main__":
|
| 434 |
+
main()
|
pyproject.toml
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[project]
|
| 2 |
+
name = "vector-data-ingest"
|
| 3 |
+
version = "0.1.0"
|
| 4 |
+
description = "Vector data ingestion pipeline for book RAG system"
|
| 5 |
+
requires-python = ">=3.11"
|
| 6 |
+
dependencies = [
|
| 7 |
+
"httpx>=0.27.0",
|
| 8 |
+
"beautifulsoup4>=4.12.0",
|
| 9 |
+
"cohere>=5.0.0",
|
| 10 |
+
"qdrant-client>=1.7.0",
|
| 11 |
+
"python-dotenv>=1.0.0",
|
| 12 |
+
]
|
requirements.txt
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Core dependencies
|
| 2 |
+
httpx>=0.27.0
|
| 3 |
+
beautifulsoup4>=4.12.0
|
| 4 |
+
cohere>=5.0.0
|
| 5 |
+
qdrant-client>=1.7.0
|
| 6 |
+
python-dotenv>=1.0.0
|
| 7 |
+
fastapi>=0.104.0
|
| 8 |
+
uvicorn[standard]>=0.24.0
|
| 9 |
+
openai>=1.0.0
|
| 10 |
+
pydantic>=2.0.0
|
| 11 |
+
openai-agents>=0.8.0
|
| 12 |
+
|
| 13 |
+
# Additional dependencies for production
|
| 14 |
+
lxml>=4.9.0
|
| 15 |
+
aiofiles>=23.0.0
|
| 16 |
+
python-multipart>=0.0.6
|
retrieve.log
ADDED
|
@@ -0,0 +1,577 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
2026-02-17 02:36:58 - INFO - retrieve.py:224 - === Retrieval Pipeline Started ===
|
| 2 |
+
2026-02-17 02:36:58 - INFO - retrieve.py:228 - Loading config from .env
|
| 3 |
+
2026-02-17 02:36:58 - INFO - retrieve.py:233 - Initializing Cohere and Qdrant clients
|
| 4 |
+
2026-02-17 02:37:00 - DEBUG - _trace.py:47 - connect_tcp.started host='d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io' port=6333 local_address=None timeout=5.0 socket_options=None
|
| 5 |
+
2026-02-17 02:37:00 - DEBUG - _trace.py:47 - connect_tcp.complete return_value=<httpcore._backends.sync.SyncStream object at 0x7082a6032cc0>
|
| 6 |
+
2026-02-17 02:37:00 - DEBUG - _trace.py:47 - start_tls.started ssl_context=<ssl.SSLContext object at 0x7082a6013850> server_hostname='d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io' timeout=5.0
|
| 7 |
+
2026-02-17 02:37:01 - DEBUG - _trace.py:47 - start_tls.complete return_value=<httpcore._backends.sync.SyncStream object at 0x7082a6413c50>
|
| 8 |
+
2026-02-17 02:37:01 - DEBUG - _trace.py:47 - send_request_headers.started request=<Request [b'GET']>
|
| 9 |
+
2026-02-17 02:37:01 - DEBUG - _trace.py:47 - send_request_headers.complete
|
| 10 |
+
2026-02-17 02:37:01 - DEBUG - _trace.py:47 - send_request_body.started request=<Request [b'GET']>
|
| 11 |
+
2026-02-17 02:37:01 - DEBUG - _trace.py:47 - send_request_body.complete
|
| 12 |
+
2026-02-17 02:37:01 - DEBUG - _trace.py:47 - receive_response_headers.started request=<Request [b'GET']>
|
| 13 |
+
2026-02-17 02:37:01 - DEBUG - _trace.py:47 - receive_response_headers.complete return_value=(b'HTTP/1.1', 200, b'OK', [(b'Content-Encoding', b'gzip'), (b'Content-Type', b'application/json'), (b'Date', b'Mon, 16 Feb 2026 21:37:00 GMT'), (b'Vary', b'accept-encoding, Origin, Access-Control-Request-Method, Access-Control-Request-Headers'), (b'Transfer-Encoding', b'chunked')])
|
| 14 |
+
2026-02-17 02:37:01 - INFO - _client.py:1025 - HTTP Request: GET https://d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io:6333 "HTTP/1.1 200 OK"
|
| 15 |
+
2026-02-17 02:37:01 - DEBUG - _trace.py:47 - receive_response_body.started request=<Request [b'GET']>
|
| 16 |
+
2026-02-17 02:37:01 - DEBUG - _trace.py:47 - receive_response_body.complete
|
| 17 |
+
2026-02-17 02:37:01 - DEBUG - _trace.py:47 - response_closed.started
|
| 18 |
+
2026-02-17 02:37:01 - DEBUG - _trace.py:47 - response_closed.complete
|
| 19 |
+
2026-02-17 02:37:01 - DEBUG - _trace.py:47 - close.started
|
| 20 |
+
2026-02-17 02:37:01 - DEBUG - _trace.py:47 - close.complete
|
| 21 |
+
2026-02-17 02:37:01 - INFO - retrieve.py:238 - Checking collection 'book_embeddings'
|
| 22 |
+
2026-02-17 02:37:01 - DEBUG - _trace.py:47 - connect_tcp.started host='d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io' port=6333 local_address=None timeout=5.0 socket_options=None
|
| 23 |
+
2026-02-17 02:37:01 - DEBUG - _trace.py:47 - connect_tcp.complete return_value=<httpcore._backends.sync.SyncStream object at 0x7082a6033f50>
|
| 24 |
+
2026-02-17 02:37:01 - DEBUG - _trace.py:47 - start_tls.started ssl_context=<ssl.SSLContext object at 0x7082a6013650> server_hostname='d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io' timeout=5.0
|
| 25 |
+
2026-02-17 02:37:01 - DEBUG - _trace.py:47 - start_tls.complete return_value=<httpcore._backends.sync.SyncStream object at 0x7082a6033e60>
|
| 26 |
+
2026-02-17 02:37:01 - DEBUG - _trace.py:47 - send_request_headers.started request=<Request [b'GET']>
|
| 27 |
+
2026-02-17 02:37:01 - DEBUG - _trace.py:47 - send_request_headers.complete
|
| 28 |
+
2026-02-17 02:37:01 - DEBUG - _trace.py:47 - send_request_body.started request=<Request [b'GET']>
|
| 29 |
+
2026-02-17 02:37:01 - DEBUG - _trace.py:47 - send_request_body.complete
|
| 30 |
+
2026-02-17 02:37:01 - DEBUG - _trace.py:47 - receive_response_headers.started request=<Request [b'GET']>
|
| 31 |
+
2026-02-17 02:37:01 - DEBUG - _trace.py:47 - receive_response_headers.complete return_value=(b'HTTP/1.1', 200, b'OK', [(b'Content-Encoding', b'gzip'), (b'Content-Type', b'application/json'), (b'Date', b'Mon, 16 Feb 2026 21:37:00 GMT'), (b'Vary', b'accept-encoding, Origin, Access-Control-Request-Method, Access-Control-Request-Headers'), (b'Transfer-Encoding', b'chunked')])
|
| 32 |
+
2026-02-17 02:37:01 - INFO - _client.py:1025 - HTTP Request: GET https://d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io:6333/collections/book_embeddings "HTTP/1.1 200 OK"
|
| 33 |
+
2026-02-17 02:37:01 - DEBUG - _trace.py:47 - receive_response_body.started request=<Request [b'GET']>
|
| 34 |
+
2026-02-17 02:37:01 - DEBUG - _trace.py:47 - receive_response_body.complete
|
| 35 |
+
2026-02-17 02:37:01 - DEBUG - _trace.py:47 - response_closed.started
|
| 36 |
+
2026-02-17 02:37:01 - DEBUG - _trace.py:47 - response_closed.complete
|
| 37 |
+
2026-02-17 02:37:01 - INFO - retrieve.py:240 - Collection OK: vector_size=1024, points=277
|
| 38 |
+
2026-02-17 02:37:01 - INFO - retrieve.py:121 - Embedding query: 'ROS 2...' (top_k=5)
|
| 39 |
+
2026-02-17 02:37:01 - DEBUG - _trace.py:47 - connect_tcp.started host='api.cohere.com' port=443 local_address=None timeout=300 socket_options=None
|
| 40 |
+
2026-02-17 02:37:01 - DEBUG - _trace.py:47 - connect_tcp.complete return_value=<httpcore._backends.sync.SyncStream object at 0x7082a5ef0e30>
|
| 41 |
+
2026-02-17 02:37:01 - DEBUG - _trace.py:47 - start_tls.started ssl_context=<ssl.SSLContext object at 0x7082a6012f50> server_hostname='api.cohere.com' timeout=300
|
| 42 |
+
2026-02-17 02:37:01 - DEBUG - _trace.py:47 - start_tls.complete return_value=<httpcore._backends.sync.SyncStream object at 0x7082a5ef0d40>
|
| 43 |
+
2026-02-17 02:37:01 - DEBUG - _trace.py:47 - send_request_headers.started request=<Request [b'POST']>
|
| 44 |
+
2026-02-17 02:37:01 - DEBUG - _trace.py:47 - send_request_headers.complete
|
| 45 |
+
2026-02-17 02:37:01 - DEBUG - _trace.py:47 - send_request_body.started request=<Request [b'POST']>
|
| 46 |
+
2026-02-17 02:37:01 - DEBUG - _trace.py:47 - send_request_body.complete
|
| 47 |
+
2026-02-17 02:37:01 - DEBUG - _trace.py:47 - receive_response_headers.started request=<Request [b'POST']>
|
| 48 |
+
2026-02-17 02:37:02 - DEBUG - _trace.py:47 - receive_response_headers.complete return_value=(b'HTTP/1.1', 200, b'OK', [(b'access-control-expose-headers', b'X-Debug-Trace-ID'), (b'cache-control', b'no-cache, no-store, no-transform, must-revalidate, private, max-age=0'), (b'content-encoding', b'gzip'), (b'content-type', b'application/json'), (b'expires', b'Thu, 01 Jan 1970 00:00:00 GMT'), (b'num_chars', b'5'), (b'num_tokens', b'3'), (b'pragma', b'no-cache'), (b'vary', b'Origin,Accept-Encoding'), (b'x-accel-expires', b'0'), (b'x-debug-trace-id', b'3aff3ef949954c94990bb515bf13453d'), (b'x-endpoint-monthly-call-limit', b'1000'), (b'x-trial-endpoint-call-limit', b'100'), (b'x-trial-endpoint-call-remaining', b'99'), (b'date', b'Mon, 16 Feb 2026 21:37:01 GMT'), (b'x-envoy-upstream-service-time', b'44'), (b'server', b'envoy'), (b'Via', b'1.1 google'), (b'Alt-Svc', b'h3=":443"; ma=2592000,h3-29=":443"; ma=2592000'), (b'Transfer-Encoding', b'chunked')])
|
| 49 |
+
2026-02-17 02:37:02 - INFO - _client.py:1025 - HTTP Request: POST https://api.cohere.com/v2/embed "HTTP/1.1 200 OK"
|
| 50 |
+
2026-02-17 02:37:02 - DEBUG - _trace.py:47 - receive_response_body.started request=<Request [b'POST']>
|
| 51 |
+
2026-02-17 02:37:02 - DEBUG - _trace.py:47 - receive_response_body.complete
|
| 52 |
+
2026-02-17 02:37:02 - DEBUG - _trace.py:47 - response_closed.started
|
| 53 |
+
2026-02-17 02:37:02 - DEBUG - _trace.py:47 - response_closed.complete
|
| 54 |
+
2026-02-17 02:37:02 - DEBUG - retrieve.py:133 - Generated embedding in 0.45s, dimension: 1024
|
| 55 |
+
2026-02-17 02:37:05 - ERROR - retrieve.py:156 - Search failed: 'QdrantClient' object has no attribute 'search'
|
| 56 |
+
2026-02-17 02:37:05 - ERROR - retrieve.py:298 - API error: Qdrant search failed: 'QdrantClient' object has no attribute 'search'
|
| 57 |
+
2026-02-17 02:37:05 - DEBUG - _trace.py:47 - close.started
|
| 58 |
+
2026-02-17 02:37:05 - DEBUG - _trace.py:47 - close.complete
|
| 59 |
+
2026-02-17 02:39:25 - INFO - retrieve.py:225 - === Retrieval Pipeline Started ===
|
| 60 |
+
2026-02-17 02:39:25 - INFO - retrieve.py:229 - Loading config from .env
|
| 61 |
+
2026-02-17 02:39:25 - INFO - retrieve.py:234 - Initializing Cohere and Qdrant clients
|
| 62 |
+
2026-02-17 02:39:25 - DEBUG - _trace.py:47 - connect_tcp.started host='d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io' port=6333 local_address=None timeout=5.0 socket_options=None
|
| 63 |
+
2026-02-17 02:39:25 - DEBUG - _trace.py:47 - connect_tcp.complete return_value=<httpcore._backends.sync.SyncStream object at 0x7a573c568380>
|
| 64 |
+
2026-02-17 02:39:25 - DEBUG - _trace.py:47 - start_tls.started ssl_context=<ssl.SSLContext object at 0x7a573c40f8d0> server_hostname='d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io' timeout=5.0
|
| 65 |
+
2026-02-17 02:39:26 - DEBUG - _trace.py:47 - start_tls.complete return_value=<httpcore._backends.sync.SyncStream object at 0x7a573c8138f0>
|
| 66 |
+
2026-02-17 02:39:26 - DEBUG - _trace.py:47 - send_request_headers.started request=<Request [b'GET']>
|
| 67 |
+
2026-02-17 02:39:26 - DEBUG - _trace.py:47 - send_request_headers.complete
|
| 68 |
+
2026-02-17 02:39:26 - DEBUG - _trace.py:47 - send_request_body.started request=<Request [b'GET']>
|
| 69 |
+
2026-02-17 02:39:26 - DEBUG - _trace.py:47 - send_request_body.complete
|
| 70 |
+
2026-02-17 02:39:26 - DEBUG - _trace.py:47 - receive_response_headers.started request=<Request [b'GET']>
|
| 71 |
+
2026-02-17 02:39:26 - DEBUG - _trace.py:47 - receive_response_headers.complete return_value=(b'HTTP/1.1', 200, b'OK', [(b'Content-Encoding', b'gzip'), (b'Content-Type', b'application/json'), (b'Date', b'Mon, 16 Feb 2026 21:39:25 GMT'), (b'Vary', b'accept-encoding, Origin, Access-Control-Request-Method, Access-Control-Request-Headers'), (b'Transfer-Encoding', b'chunked')])
|
| 72 |
+
2026-02-17 02:39:26 - INFO - _client.py:1025 - HTTP Request: GET https://d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io:6333 "HTTP/1.1 200 OK"
|
| 73 |
+
2026-02-17 02:39:26 - DEBUG - _trace.py:47 - receive_response_body.started request=<Request [b'GET']>
|
| 74 |
+
2026-02-17 02:39:26 - DEBUG - _trace.py:47 - receive_response_body.complete
|
| 75 |
+
2026-02-17 02:39:26 - DEBUG - _trace.py:47 - response_closed.started
|
| 76 |
+
2026-02-17 02:39:26 - DEBUG - _trace.py:47 - response_closed.complete
|
| 77 |
+
2026-02-17 02:39:26 - DEBUG - _trace.py:47 - close.started
|
| 78 |
+
2026-02-17 02:39:26 - DEBUG - _trace.py:47 - close.complete
|
| 79 |
+
2026-02-17 02:39:26 - INFO - retrieve.py:239 - Checking collection 'book_embeddings'
|
| 80 |
+
2026-02-17 02:39:26 - DEBUG - _trace.py:47 - connect_tcp.started host='d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io' port=6333 local_address=None timeout=5.0 socket_options=None
|
| 81 |
+
2026-02-17 02:39:26 - DEBUG - _trace.py:47 - connect_tcp.complete return_value=<httpcore._backends.sync.SyncStream object at 0x7a573c433d40>
|
| 82 |
+
2026-02-17 02:39:26 - DEBUG - _trace.py:47 - start_tls.started ssl_context=<ssl.SSLContext object at 0x7a573c40f6d0> server_hostname='d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io' timeout=5.0
|
| 83 |
+
2026-02-17 02:39:26 - DEBUG - _trace.py:47 - start_tls.complete return_value=<httpcore._backends.sync.SyncStream object at 0x7a573c433c50>
|
| 84 |
+
2026-02-17 02:39:26 - DEBUG - _trace.py:47 - send_request_headers.started request=<Request [b'GET']>
|
| 85 |
+
2026-02-17 02:39:26 - DEBUG - _trace.py:47 - send_request_headers.complete
|
| 86 |
+
2026-02-17 02:39:26 - DEBUG - _trace.py:47 - send_request_body.started request=<Request [b'GET']>
|
| 87 |
+
2026-02-17 02:39:26 - DEBUG - _trace.py:47 - send_request_body.complete
|
| 88 |
+
2026-02-17 02:39:26 - DEBUG - _trace.py:47 - receive_response_headers.started request=<Request [b'GET']>
|
| 89 |
+
2026-02-17 02:39:26 - DEBUG - _trace.py:47 - receive_response_headers.complete return_value=(b'HTTP/1.1', 200, b'OK', [(b'Content-Encoding', b'gzip'), (b'Content-Type', b'application/json'), (b'Date', b'Mon, 16 Feb 2026 21:39:25 GMT'), (b'Vary', b'accept-encoding, Origin, Access-Control-Request-Method, Access-Control-Request-Headers'), (b'Transfer-Encoding', b'chunked')])
|
| 90 |
+
2026-02-17 02:39:26 - INFO - _client.py:1025 - HTTP Request: GET https://d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io:6333/collections/book_embeddings "HTTP/1.1 200 OK"
|
| 91 |
+
2026-02-17 02:39:26 - DEBUG - _trace.py:47 - receive_response_body.started request=<Request [b'GET']>
|
| 92 |
+
2026-02-17 02:39:26 - DEBUG - _trace.py:47 - receive_response_body.complete
|
| 93 |
+
2026-02-17 02:39:26 - DEBUG - _trace.py:47 - response_closed.started
|
| 94 |
+
2026-02-17 02:39:26 - DEBUG - _trace.py:47 - response_closed.complete
|
| 95 |
+
2026-02-17 02:39:26 - INFO - retrieve.py:241 - Collection OK: vector_size=1024, points=277
|
| 96 |
+
2026-02-17 02:39:26 - INFO - retrieve.py:121 - Embedding query: 'ROS 2...' (top_k=5)
|
| 97 |
+
2026-02-17 02:39:26 - DEBUG - _trace.py:47 - connect_tcp.started host='api.cohere.com' port=443 local_address=None timeout=300 socket_options=None
|
| 98 |
+
2026-02-17 02:39:26 - DEBUG - _trace.py:47 - connect_tcp.complete return_value=<httpcore._backends.sync.SyncStream object at 0x7a573c2f0c50>
|
| 99 |
+
2026-02-17 02:39:26 - DEBUG - _trace.py:47 - start_tls.started ssl_context=<ssl.SSLContext object at 0x7a573c40efd0> server_hostname='api.cohere.com' timeout=300
|
| 100 |
+
2026-02-17 02:39:26 - DEBUG - _trace.py:47 - start_tls.complete return_value=<httpcore._backends.sync.SyncStream object at 0x7a573c2f0b60>
|
| 101 |
+
2026-02-17 02:39:26 - DEBUG - _trace.py:47 - send_request_headers.started request=<Request [b'POST']>
|
| 102 |
+
2026-02-17 02:39:26 - DEBUG - _trace.py:47 - send_request_headers.complete
|
| 103 |
+
2026-02-17 02:39:26 - DEBUG - _trace.py:47 - send_request_body.started request=<Request [b'POST']>
|
| 104 |
+
2026-02-17 02:39:26 - DEBUG - _trace.py:47 - send_request_body.complete
|
| 105 |
+
2026-02-17 02:39:26 - DEBUG - _trace.py:47 - receive_response_headers.started request=<Request [b'POST']>
|
| 106 |
+
2026-02-17 02:39:27 - DEBUG - _trace.py:47 - receive_response_headers.complete return_value=(b'HTTP/1.1', 200, b'OK', [(b'access-control-expose-headers', b'X-Debug-Trace-ID'), (b'cache-control', b'no-cache, no-store, no-transform, must-revalidate, private, max-age=0'), (b'content-encoding', b'gzip'), (b'content-type', b'application/json'), (b'expires', b'Thu, 01 Jan 1970 00:00:00 GMT'), (b'num_chars', b'5'), (b'num_tokens', b'3'), (b'pragma', b'no-cache'), (b'vary', b'Origin,Accept-Encoding'), (b'x-accel-expires', b'0'), (b'x-debug-trace-id', b'9cfafd18a8c68f9fc1f1e0d937c5508a'), (b'x-endpoint-monthly-call-limit', b'1000'), (b'x-trial-endpoint-call-limit', b'100'), (b'x-trial-endpoint-call-remaining', b'99'), (b'date', b'Mon, 16 Feb 2026 21:39:26 GMT'), (b'x-envoy-upstream-service-time', b'48'), (b'server', b'envoy'), (b'Via', b'1.1 google'), (b'Alt-Svc', b'h3=":443"; ma=2592000,h3-29=":443"; ma=2592000'), (b'Transfer-Encoding', b'chunked')])
|
| 107 |
+
2026-02-17 02:39:27 - INFO - _client.py:1025 - HTTP Request: POST https://api.cohere.com/v2/embed "HTTP/1.1 200 OK"
|
| 108 |
+
2026-02-17 02:39:27 - DEBUG - _trace.py:47 - receive_response_body.started request=<Request [b'POST']>
|
| 109 |
+
2026-02-17 02:39:27 - DEBUG - _trace.py:47 - receive_response_body.complete
|
| 110 |
+
2026-02-17 02:39:27 - DEBUG - _trace.py:47 - response_closed.started
|
| 111 |
+
2026-02-17 02:39:27 - DEBUG - _trace.py:47 - response_closed.complete
|
| 112 |
+
2026-02-17 02:39:27 - DEBUG - retrieve.py:133 - Generated embedding in 0.46s, dimension: 1024
|
| 113 |
+
2026-02-17 02:39:27 - DEBUG - _trace.py:47 - send_request_headers.started request=<Request [b'POST']>
|
| 114 |
+
2026-02-17 02:39:27 - DEBUG - _trace.py:47 - send_request_headers.complete
|
| 115 |
+
2026-02-17 02:39:27 - DEBUG - _trace.py:47 - send_request_body.started request=<Request [b'POST']>
|
| 116 |
+
2026-02-17 02:39:27 - DEBUG - _trace.py:47 - send_request_body.complete
|
| 117 |
+
2026-02-17 02:39:27 - DEBUG - _trace.py:47 - receive_response_headers.started request=<Request [b'POST']>
|
| 118 |
+
2026-02-17 02:39:27 - DEBUG - _trace.py:47 - receive_response_headers.complete return_value=(b'HTTP/1.1', 200, b'OK', [(b'Content-Encoding', b'gzip'), (b'Content-Type', b'application/json'), (b'Date', b'Mon, 16 Feb 2026 21:39:26 GMT'), (b'Vary', b'accept-encoding, Origin, Access-Control-Request-Method, Access-Control-Request-Headers'), (b'Transfer-Encoding', b'chunked')])
|
| 119 |
+
2026-02-17 02:39:27 - INFO - _client.py:1025 - HTTP Request: POST https://d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io:6333/collections/book_embeddings/points/query "HTTP/1.1 200 OK"
|
| 120 |
+
2026-02-17 02:39:27 - DEBUG - _trace.py:47 - receive_response_body.started request=<Request [b'POST']>
|
| 121 |
+
2026-02-17 02:39:27 - DEBUG - _trace.py:47 - receive_response_body.complete
|
| 122 |
+
2026-02-17 02:39:27 - DEBUG - _trace.py:47 - response_closed.started
|
| 123 |
+
2026-02-17 02:39:27 - DEBUG - _trace.py:47 - response_closed.complete
|
| 124 |
+
2026-02-17 02:39:27 - INFO - retrieve.py:155 - Search completed in 0.31s, returned 5 results
|
| 125 |
+
2026-02-17 02:39:27 - INFO - retrieve.py:170 - Total query time: 0.78s
|
| 126 |
+
2026-02-17 02:39:27 - INFO - retrieve.py:279 - === Retrieval Pipeline Completed Successfully ===
|
| 127 |
+
2026-02-17 02:39:27 - DEBUG - _trace.py:47 - close.started
|
| 128 |
+
2026-02-17 02:39:27 - DEBUG - _trace.py:47 - close.complete
|
| 129 |
+
2026-02-17 02:41:01 - INFO - retrieve.py:299 - === Retrieval Pipeline Started ===
|
| 130 |
+
2026-02-17 02:41:01 - INFO - retrieve.py:303 - Loading config from .env
|
| 131 |
+
2026-02-17 02:41:01 - INFO - retrieve.py:308 - Initializing Cohere and Qdrant clients
|
| 132 |
+
2026-02-17 02:41:02 - DEBUG - _trace.py:47 - connect_tcp.started host='d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io' port=6333 local_address=None timeout=5.0 socket_options=None
|
| 133 |
+
2026-02-17 02:41:03 - DEBUG - _trace.py:47 - connect_tcp.complete return_value=<httpcore._backends.sync.SyncStream object at 0x72e5e492f170>
|
| 134 |
+
2026-02-17 02:41:03 - DEBUG - _trace.py:47 - start_tls.started ssl_context=<ssl.SSLContext object at 0x72e5e4823e50> server_hostname='d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io' timeout=5.0
|
| 135 |
+
2026-02-17 02:41:03 - DEBUG - _trace.py:47 - start_tls.complete return_value=<httpcore._backends.sync.SyncStream object at 0x72e5e492fce0>
|
| 136 |
+
2026-02-17 02:41:03 - DEBUG - _trace.py:47 - send_request_headers.started request=<Request [b'GET']>
|
| 137 |
+
2026-02-17 02:41:03 - DEBUG - _trace.py:47 - send_request_headers.complete
|
| 138 |
+
2026-02-17 02:41:04 - DEBUG - _trace.py:47 - send_request_body.started request=<Request [b'GET']>
|
| 139 |
+
2026-02-17 02:41:04 - DEBUG - _trace.py:47 - send_request_body.complete
|
| 140 |
+
2026-02-17 02:41:04 - DEBUG - _trace.py:47 - receive_response_headers.started request=<Request [b'GET']>
|
| 141 |
+
2026-02-17 02:41:04 - DEBUG - _trace.py:47 - receive_response_headers.complete return_value=(b'HTTP/1.1', 200, b'OK', [(b'Content-Encoding', b'gzip'), (b'Content-Type', b'application/json'), (b'Date', b'Mon, 16 Feb 2026 21:41:02 GMT'), (b'Vary', b'accept-encoding, Origin, Access-Control-Request-Method, Access-Control-Request-Headers'), (b'Transfer-Encoding', b'chunked')])
|
| 142 |
+
2026-02-17 02:41:04 - INFO - _client.py:1025 - HTTP Request: GET https://d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io:6333 "HTTP/1.1 200 OK"
|
| 143 |
+
2026-02-17 02:41:04 - DEBUG - _trace.py:47 - receive_response_body.started request=<Request [b'GET']>
|
| 144 |
+
2026-02-17 02:41:04 - DEBUG - _trace.py:47 - receive_response_body.complete
|
| 145 |
+
2026-02-17 02:41:04 - DEBUG - _trace.py:47 - response_closed.started
|
| 146 |
+
2026-02-17 02:41:04 - DEBUG - _trace.py:47 - response_closed.complete
|
| 147 |
+
2026-02-17 02:41:04 - DEBUG - _trace.py:47 - close.started
|
| 148 |
+
2026-02-17 02:41:04 - DEBUG - _trace.py:47 - close.complete
|
| 149 |
+
2026-02-17 02:41:04 - INFO - retrieve.py:313 - Checking collection 'book_embeddings'
|
| 150 |
+
2026-02-17 02:41:04 - DEBUG - _trace.py:47 - connect_tcp.started host='d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io' port=6333 local_address=None timeout=5.0 socket_options=None
|
| 151 |
+
2026-02-17 02:41:04 - DEBUG - _trace.py:47 - connect_tcp.complete return_value=<httpcore._backends.sync.SyncStream object at 0x72e5e485dee0>
|
| 152 |
+
2026-02-17 02:41:04 - DEBUG - _trace.py:47 - start_tls.started ssl_context=<ssl.SSLContext object at 0x72e5e4823c50> server_hostname='d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io' timeout=5.0
|
| 153 |
+
2026-02-17 02:41:04 - DEBUG - _trace.py:47 - start_tls.complete return_value=<httpcore._backends.sync.SyncStream object at 0x72e5e485dc10>
|
| 154 |
+
2026-02-17 02:41:04 - DEBUG - _trace.py:47 - send_request_headers.started request=<Request [b'GET']>
|
| 155 |
+
2026-02-17 02:41:04 - DEBUG - _trace.py:47 - send_request_headers.complete
|
| 156 |
+
2026-02-17 02:41:04 - DEBUG - _trace.py:47 - send_request_body.started request=<Request [b'GET']>
|
| 157 |
+
2026-02-17 02:41:04 - DEBUG - _trace.py:47 - send_request_body.complete
|
| 158 |
+
2026-02-17 02:41:04 - DEBUG - _trace.py:47 - receive_response_headers.started request=<Request [b'GET']>
|
| 159 |
+
2026-02-17 02:41:05 - DEBUG - _trace.py:47 - receive_response_headers.complete return_value=(b'HTTP/1.1', 200, b'OK', [(b'Content-Encoding', b'gzip'), (b'Content-Type', b'application/json'), (b'Date', b'Mon, 16 Feb 2026 21:41:03 GMT'), (b'Vary', b'accept-encoding, Origin, Access-Control-Request-Method, Access-Control-Request-Headers'), (b'Transfer-Encoding', b'chunked')])
|
| 160 |
+
2026-02-17 02:41:05 - INFO - _client.py:1025 - HTTP Request: GET https://d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io:6333/collections/book_embeddings "HTTP/1.1 200 OK"
|
| 161 |
+
2026-02-17 02:41:05 - DEBUG - _trace.py:47 - receive_response_body.started request=<Request [b'GET']>
|
| 162 |
+
2026-02-17 02:41:05 - DEBUG - _trace.py:47 - receive_response_body.complete
|
| 163 |
+
2026-02-17 02:41:05 - DEBUG - _trace.py:47 - response_closed.started
|
| 164 |
+
2026-02-17 02:41:05 - DEBUG - _trace.py:47 - response_closed.complete
|
| 165 |
+
2026-02-17 02:41:05 - INFO - retrieve.py:315 - Collection OK: vector_size=1024, points=277
|
| 166 |
+
2026-02-17 02:41:05 - INFO - retrieve.py:190 - Embedding query: 'ROS 2...' (top_k=5)
|
| 167 |
+
2026-02-17 02:41:05 - DEBUG - _trace.py:47 - connect_tcp.started host='api.cohere.com' port=443 local_address=None timeout=300 socket_options=None
|
| 168 |
+
2026-02-17 02:41:05 - DEBUG - _trace.py:47 - connect_tcp.complete return_value=<httpcore._backends.sync.SyncStream object at 0x72e5e485ede0>
|
| 169 |
+
2026-02-17 02:41:05 - DEBUG - _trace.py:47 - start_tls.started ssl_context=<ssl.SSLContext object at 0x72e5e4823550> server_hostname='api.cohere.com' timeout=300
|
| 170 |
+
2026-02-17 02:41:05 - DEBUG - _trace.py:47 - start_tls.complete return_value=<httpcore._backends.sync.SyncStream object at 0x72e5e485ecf0>
|
| 171 |
+
2026-02-17 02:41:05 - DEBUG - _trace.py:47 - send_request_headers.started request=<Request [b'POST']>
|
| 172 |
+
2026-02-17 02:41:05 - DEBUG - _trace.py:47 - send_request_headers.complete
|
| 173 |
+
2026-02-17 02:41:05 - DEBUG - _trace.py:47 - send_request_body.started request=<Request [b'POST']>
|
| 174 |
+
2026-02-17 02:41:05 - DEBUG - _trace.py:47 - send_request_body.complete
|
| 175 |
+
2026-02-17 02:41:05 - DEBUG - _trace.py:47 - receive_response_headers.started request=<Request [b'POST']>
|
| 176 |
+
2026-02-17 02:41:05 - DEBUG - _trace.py:47 - receive_response_headers.complete return_value=(b'HTTP/1.1', 200, b'OK', [(b'access-control-expose-headers', b'X-Debug-Trace-ID'), (b'cache-control', b'no-cache, no-store, no-transform, must-revalidate, private, max-age=0'), (b'content-encoding', b'gzip'), (b'content-type', b'application/json'), (b'expires', b'Thu, 01 Jan 1970 00:00:00 GMT'), (b'num_chars', b'5'), (b'num_tokens', b'3'), (b'pragma', b'no-cache'), (b'vary', b'Origin,Accept-Encoding'), (b'x-accel-expires', b'0'), (b'x-debug-trace-id', b'7eab84de888d9426719d5f02fbc98608'), (b'x-endpoint-monthly-call-limit', b'1000'), (b'x-trial-endpoint-call-limit', b'100'), (b'x-trial-endpoint-call-remaining', b'99'), (b'date', b'Mon, 16 Feb 2026 21:41:04 GMT'), (b'x-envoy-upstream-service-time', b'49'), (b'server', b'envoy'), (b'Via', b'1.1 google'), (b'Alt-Svc', b'h3=":443"; ma=2592000,h3-29=":443"; ma=2592000'), (b'Transfer-Encoding', b'chunked')])
|
| 177 |
+
2026-02-17 02:41:05 - INFO - _client.py:1025 - HTTP Request: POST https://api.cohere.com/v2/embed "HTTP/1.1 200 OK"
|
| 178 |
+
2026-02-17 02:41:05 - DEBUG - _trace.py:47 - receive_response_body.started request=<Request [b'POST']>
|
| 179 |
+
2026-02-17 02:41:05 - DEBUG - _trace.py:47 - receive_response_body.complete
|
| 180 |
+
2026-02-17 02:41:05 - DEBUG - _trace.py:47 - response_closed.started
|
| 181 |
+
2026-02-17 02:41:05 - DEBUG - _trace.py:47 - response_closed.complete
|
| 182 |
+
2026-02-17 02:41:05 - DEBUG - retrieve.py:202 - Generated embedding in 0.44s, dimension: 1024
|
| 183 |
+
2026-02-17 02:41:05 - DEBUG - _trace.py:47 - send_request_headers.started request=<Request [b'POST']>
|
| 184 |
+
2026-02-17 02:41:05 - DEBUG - _trace.py:47 - send_request_headers.complete
|
| 185 |
+
2026-02-17 02:41:05 - DEBUG - _trace.py:47 - send_request_body.started request=<Request [b'POST']>
|
| 186 |
+
2026-02-17 02:41:05 - DEBUG - _trace.py:47 - send_request_body.complete
|
| 187 |
+
2026-02-17 02:41:05 - DEBUG - _trace.py:47 - receive_response_headers.started request=<Request [b'POST']>
|
| 188 |
+
2026-02-17 02:41:05 - DEBUG - _trace.py:47 - receive_response_headers.complete return_value=(b'HTTP/1.1', 200, b'OK', [(b'Content-Encoding', b'gzip'), (b'Content-Type', b'application/json'), (b'Date', b'Mon, 16 Feb 2026 21:41:04 GMT'), (b'Vary', b'accept-encoding, Origin, Access-Control-Request-Method, Access-Control-Request-Headers'), (b'Transfer-Encoding', b'chunked')])
|
| 189 |
+
2026-02-17 02:41:05 - INFO - _client.py:1025 - HTTP Request: POST https://d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io:6333/collections/book_embeddings/points/query "HTTP/1.1 200 OK"
|
| 190 |
+
2026-02-17 02:41:05 - DEBUG - _trace.py:47 - receive_response_body.started request=<Request [b'POST']>
|
| 191 |
+
2026-02-17 02:41:05 - DEBUG - _trace.py:47 - receive_response_body.complete
|
| 192 |
+
2026-02-17 02:41:05 - DEBUG - _trace.py:47 - response_closed.started
|
| 193 |
+
2026-02-17 02:41:05 - DEBUG - _trace.py:47 - response_closed.complete
|
| 194 |
+
2026-02-17 02:41:05 - INFO - retrieve.py:224 - Search completed in 0.30s, returned 5 results
|
| 195 |
+
2026-02-17 02:41:05 - INFO - retrieve.py:239 - Total query time: 0.75s
|
| 196 |
+
2026-02-17 02:41:05 - DEBUG - retrieve.py:127 - Metadata completeness: 5/5 = 100.0%
|
| 197 |
+
2026-02-17 02:41:05 - DEBUG - retrieve.py:157 - Chunk sequencing invalid for https://humanoid-ai-robotics-book-1.vercel.app/docs/module-1/intro-to-ros2: expected [0, 1, 2, 3], got [0, 2, 4, 5]
|
| 198 |
+
2026-02-17 02:41:05 - INFO - retrieve.py:340 - Metadata completeness: 100.0%
|
| 199 |
+
2026-02-17 02:41:05 - INFO - retrieve.py:341 - Chunk sequencing: INVALID
|
| 200 |
+
2026-02-17 02:41:05 - INFO - retrieve.py:342 - Validation result: FAIL
|
| 201 |
+
2026-02-17 02:41:05 - INFO - retrieve.py:369 - === Retrieval Pipeline Completed Successfully ===
|
| 202 |
+
2026-02-17 02:41:05 - DEBUG - _trace.py:47 - close.started
|
| 203 |
+
2026-02-17 02:41:05 - DEBUG - _trace.py:47 - close.complete
|
| 204 |
+
2026-02-17 02:42:10 - INFO - retrieve.py:309 - === Retrieval Pipeline Started ===
|
| 205 |
+
2026-02-17 02:42:10 - INFO - retrieve.py:313 - Loading config from .env
|
| 206 |
+
2026-02-17 02:42:10 - INFO - retrieve.py:318 - Initializing Cohere and Qdrant clients
|
| 207 |
+
2026-02-17 02:42:10 - DEBUG - _trace.py:47 - connect_tcp.started host='d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io' port=6333 local_address=None timeout=5.0 socket_options=None
|
| 208 |
+
2026-02-17 02:42:11 - DEBUG - _trace.py:47 - connect_tcp.complete return_value=<httpcore._backends.sync.SyncStream object at 0x79f99627efc0>
|
| 209 |
+
2026-02-17 02:42:11 - DEBUG - _trace.py:47 - start_tls.started ssl_context=<ssl.SSLContext object at 0x79f995c178d0> server_hostname='d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io' timeout=5.0
|
| 210 |
+
2026-02-17 02:42:11 - DEBUG - _trace.py:47 - start_tls.complete return_value=<httpcore._backends.sync.SyncStream object at 0x79f995ee2090>
|
| 211 |
+
2026-02-17 02:42:11 - DEBUG - _trace.py:47 - send_request_headers.started request=<Request [b'GET']>
|
| 212 |
+
2026-02-17 02:42:11 - DEBUG - _trace.py:47 - send_request_headers.complete
|
| 213 |
+
2026-02-17 02:42:11 - DEBUG - _trace.py:47 - send_request_body.started request=<Request [b'GET']>
|
| 214 |
+
2026-02-17 02:42:11 - DEBUG - _trace.py:47 - send_request_body.complete
|
| 215 |
+
2026-02-17 02:42:11 - DEBUG - _trace.py:47 - receive_response_headers.started request=<Request [b'GET']>
|
| 216 |
+
2026-02-17 02:42:11 - DEBUG - _trace.py:47 - receive_response_headers.complete return_value=(b'HTTP/1.1', 200, b'OK', [(b'Content-Encoding', b'gzip'), (b'Content-Type', b'application/json'), (b'Date', b'Mon, 16 Feb 2026 21:42:09 GMT'), (b'Vary', b'accept-encoding, Origin, Access-Control-Request-Method, Access-Control-Request-Headers'), (b'Transfer-Encoding', b'chunked')])
|
| 217 |
+
2026-02-17 02:42:11 - INFO - _client.py:1025 - HTTP Request: GET https://d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io:6333 "HTTP/1.1 200 OK"
|
| 218 |
+
2026-02-17 02:42:11 - DEBUG - _trace.py:47 - receive_response_body.started request=<Request [b'GET']>
|
| 219 |
+
2026-02-17 02:42:11 - DEBUG - _trace.py:47 - receive_response_body.complete
|
| 220 |
+
2026-02-17 02:42:11 - DEBUG - _trace.py:47 - response_closed.started
|
| 221 |
+
2026-02-17 02:42:11 - DEBUG - _trace.py:47 - response_closed.complete
|
| 222 |
+
2026-02-17 02:42:11 - DEBUG - _trace.py:47 - close.started
|
| 223 |
+
2026-02-17 02:42:11 - DEBUG - _trace.py:47 - close.complete
|
| 224 |
+
2026-02-17 02:42:11 - INFO - retrieve.py:323 - Checking collection 'book_embeddings'
|
| 225 |
+
2026-02-17 02:42:11 - DEBUG - _trace.py:47 - connect_tcp.started host='d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io' port=6333 local_address=None timeout=5.0 socket_options=None
|
| 226 |
+
2026-02-17 02:42:11 - DEBUG - _trace.py:47 - connect_tcp.complete return_value=<httpcore._backends.sync.SyncStream object at 0x79f995c41ee0>
|
| 227 |
+
2026-02-17 02:42:11 - DEBUG - _trace.py:47 - start_tls.started ssl_context=<ssl.SSLContext object at 0x79f995c176d0> server_hostname='d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io' timeout=5.0
|
| 228 |
+
2026-02-17 02:42:12 - DEBUG - _trace.py:47 - start_tls.complete return_value=<httpcore._backends.sync.SyncStream object at 0x79f995c41e20>
|
| 229 |
+
2026-02-17 02:42:12 - DEBUG - _trace.py:47 - send_request_headers.started request=<Request [b'GET']>
|
| 230 |
+
2026-02-17 02:42:12 - DEBUG - _trace.py:47 - send_request_headers.complete
|
| 231 |
+
2026-02-17 02:42:12 - DEBUG - _trace.py:47 - send_request_body.started request=<Request [b'GET']>
|
| 232 |
+
2026-02-17 02:42:12 - DEBUG - _trace.py:47 - send_request_body.complete
|
| 233 |
+
2026-02-17 02:42:12 - DEBUG - _trace.py:47 - receive_response_headers.started request=<Request [b'GET']>
|
| 234 |
+
2026-02-17 02:42:12 - DEBUG - _trace.py:47 - receive_response_headers.complete return_value=(b'HTTP/1.1', 200, b'OK', [(b'Content-Encoding', b'gzip'), (b'Content-Type', b'application/json'), (b'Date', b'Mon, 16 Feb 2026 21:42:09 GMT'), (b'Vary', b'accept-encoding, Origin, Access-Control-Request-Method, Access-Control-Request-Headers'), (b'Transfer-Encoding', b'chunked')])
|
| 235 |
+
2026-02-17 02:42:12 - INFO - _client.py:1025 - HTTP Request: GET https://d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io:6333/collections/book_embeddings "HTTP/1.1 200 OK"
|
| 236 |
+
2026-02-17 02:42:12 - DEBUG - _trace.py:47 - receive_response_body.started request=<Request [b'GET']>
|
| 237 |
+
2026-02-17 02:42:12 - DEBUG - _trace.py:47 - receive_response_body.complete
|
| 238 |
+
2026-02-17 02:42:12 - DEBUG - _trace.py:47 - response_closed.started
|
| 239 |
+
2026-02-17 02:42:12 - DEBUG - _trace.py:47 - response_closed.complete
|
| 240 |
+
2026-02-17 02:42:12 - INFO - retrieve.py:325 - Collection OK: vector_size=1024, points=277
|
| 241 |
+
2026-02-17 02:42:12 - INFO - retrieve.py:200 - Embedding query: 'ROS 2...' (top_k=5)
|
| 242 |
+
2026-02-17 02:42:12 - DEBUG - _trace.py:47 - connect_tcp.started host='api.cohere.com' port=443 local_address=None timeout=300 socket_options=None
|
| 243 |
+
2026-02-17 02:42:12 - DEBUG - _trace.py:47 - connect_tcp.complete return_value=<httpcore._backends.sync.SyncStream object at 0x79f995c42d50>
|
| 244 |
+
2026-02-17 02:42:12 - DEBUG - _trace.py:47 - start_tls.started ssl_context=<ssl.SSLContext object at 0x79f995c16fd0> server_hostname='api.cohere.com' timeout=300
|
| 245 |
+
2026-02-17 02:42:12 - DEBUG - _trace.py:47 - start_tls.complete return_value=<httpcore._backends.sync.SyncStream object at 0x79f995c42c60>
|
| 246 |
+
2026-02-17 02:42:12 - DEBUG - _trace.py:47 - send_request_headers.started request=<Request [b'POST']>
|
| 247 |
+
2026-02-17 02:42:12 - DEBUG - _trace.py:47 - send_request_headers.complete
|
| 248 |
+
2026-02-17 02:42:12 - DEBUG - _trace.py:47 - send_request_body.started request=<Request [b'POST']>
|
| 249 |
+
2026-02-17 02:42:12 - DEBUG - _trace.py:47 - send_request_body.complete
|
| 250 |
+
2026-02-17 02:42:12 - DEBUG - _trace.py:47 - receive_response_headers.started request=<Request [b'POST']>
|
| 251 |
+
2026-02-17 02:42:12 - DEBUG - _trace.py:47 - receive_response_headers.complete return_value=(b'HTTP/1.1', 200, b'OK', [(b'access-control-expose-headers', b'X-Debug-Trace-ID'), (b'cache-control', b'no-cache, no-store, no-transform, must-revalidate, private, max-age=0'), (b'content-encoding', b'gzip'), (b'content-type', b'application/json'), (b'expires', b'Thu, 01 Jan 1970 00:00:00 GMT'), (b'num_chars', b'5'), (b'num_tokens', b'3'), (b'pragma', b'no-cache'), (b'vary', b'Origin,Accept-Encoding'), (b'x-accel-expires', b'0'), (b'x-debug-trace-id', b'd004675c4a251ca57146bf895e986d52'), (b'x-endpoint-monthly-call-limit', b'1000'), (b'x-trial-endpoint-call-limit', b'100'), (b'x-trial-endpoint-call-remaining', b'99'), (b'date', b'Mon, 16 Feb 2026 21:42:10 GMT'), (b'x-envoy-upstream-service-time', b'41'), (b'server', b'envoy'), (b'Via', b'1.1 google'), (b'Alt-Svc', b'h3=":443"; ma=2592000,h3-29=":443"; ma=2592000'), (b'Transfer-Encoding', b'chunked')])
|
| 252 |
+
2026-02-17 02:42:12 - INFO - _client.py:1025 - HTTP Request: POST https://api.cohere.com/v2/embed "HTTP/1.1 200 OK"
|
| 253 |
+
2026-02-17 02:42:12 - DEBUG - _trace.py:47 - receive_response_body.started request=<Request [b'POST']>
|
| 254 |
+
2026-02-17 02:42:12 - DEBUG - _trace.py:47 - receive_response_body.complete
|
| 255 |
+
2026-02-17 02:42:12 - DEBUG - _trace.py:47 - response_closed.started
|
| 256 |
+
2026-02-17 02:42:12 - DEBUG - _trace.py:47 - response_closed.complete
|
| 257 |
+
2026-02-17 02:42:12 - DEBUG - retrieve.py:212 - Generated embedding in 0.42s, dimension: 1024
|
| 258 |
+
2026-02-17 02:42:12 - DEBUG - _trace.py:47 - send_request_headers.started request=<Request [b'POST']>
|
| 259 |
+
2026-02-17 02:42:12 - DEBUG - _trace.py:47 - send_request_headers.complete
|
| 260 |
+
2026-02-17 02:42:12 - DEBUG - _trace.py:47 - send_request_body.started request=<Request [b'POST']>
|
| 261 |
+
2026-02-17 02:42:12 - DEBUG - _trace.py:47 - send_request_body.complete
|
| 262 |
+
2026-02-17 02:42:12 - DEBUG - _trace.py:47 - receive_response_headers.started request=<Request [b'POST']>
|
| 263 |
+
2026-02-17 02:42:12 - DEBUG - _trace.py:47 - receive_response_headers.complete return_value=(b'HTTP/1.1', 200, b'OK', [(b'Content-Encoding', b'gzip'), (b'Content-Type', b'application/json'), (b'Date', b'Mon, 16 Feb 2026 21:42:10 GMT'), (b'Vary', b'accept-encoding, Origin, Access-Control-Request-Method, Access-Control-Request-Headers'), (b'Transfer-Encoding', b'chunked')])
|
| 264 |
+
2026-02-17 02:42:12 - INFO - _client.py:1025 - HTTP Request: POST https://d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io:6333/collections/book_embeddings/points/query "HTTP/1.1 200 OK"
|
| 265 |
+
2026-02-17 02:42:12 - DEBUG - _trace.py:47 - receive_response_body.started request=<Request [b'POST']>
|
| 266 |
+
2026-02-17 02:42:12 - DEBUG - _trace.py:47 - receive_response_body.complete
|
| 267 |
+
2026-02-17 02:42:12 - DEBUG - _trace.py:47 - response_closed.started
|
| 268 |
+
2026-02-17 02:42:12 - DEBUG - _trace.py:47 - response_closed.complete
|
| 269 |
+
2026-02-17 02:42:12 - INFO - retrieve.py:234 - Search completed in 0.31s, returned 5 results
|
| 270 |
+
2026-02-17 02:42:12 - INFO - retrieve.py:249 - Total query time: 0.74s
|
| 271 |
+
2026-02-17 02:42:12 - DEBUG - retrieve.py:127 - Metadata completeness: 5/5 = 100.0%
|
| 272 |
+
2026-02-17 02:42:12 - DEBUG - retrieve.py:170 - Chunk indexing valid for 2 URLs
|
| 273 |
+
2026-02-17 02:42:12 - INFO - retrieve.py:350 - Metadata completeness: 100.0%
|
| 274 |
+
2026-02-17 02:42:12 - INFO - retrieve.py:351 - Chunk sequencing: VALID
|
| 275 |
+
2026-02-17 02:42:12 - INFO - retrieve.py:352 - Validation result: PASS
|
| 276 |
+
2026-02-17 02:42:12 - INFO - retrieve.py:379 - === Retrieval Pipeline Completed Successfully ===
|
| 277 |
+
2026-02-17 02:42:12 - DEBUG - _trace.py:47 - close.started
|
| 278 |
+
2026-02-17 02:42:12 - DEBUG - _trace.py:47 - close.complete
|
| 279 |
+
2026-02-17 02:45:35 - INFO - retrieve.py:309 - === Retrieval Pipeline Started ===
|
| 280 |
+
2026-02-17 02:45:35 - INFO - retrieve.py:313 - Loading config from .env
|
| 281 |
+
2026-02-17 02:45:35 - INFO - retrieve.py:318 - Initializing Cohere and Qdrant clients
|
| 282 |
+
2026-02-17 02:45:36 - DEBUG - _trace.py:47 - connect_tcp.started host='d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io' port=6333 local_address=None timeout=5.0 socket_options=None
|
| 283 |
+
2026-02-17 02:45:36 - DEBUG - _trace.py:47 - connect_tcp.complete return_value=<httpcore._backends.sync.SyncStream object at 0x7b345d46efc0>
|
| 284 |
+
2026-02-17 02:45:36 - DEBUG - _trace.py:47 - start_tls.started ssl_context=<ssl.SSLContext object at 0x7b345d2438d0> server_hostname='d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io' timeout=5.0
|
| 285 |
+
2026-02-17 02:45:36 - DEBUG - _trace.py:47 - start_tls.complete return_value=<httpcore._backends.sync.SyncStream object at 0x7b345d632570>
|
| 286 |
+
2026-02-17 02:45:36 - DEBUG - _trace.py:47 - send_request_headers.started request=<Request [b'GET']>
|
| 287 |
+
2026-02-17 02:45:36 - DEBUG - _trace.py:47 - send_request_headers.complete
|
| 288 |
+
2026-02-17 02:45:36 - DEBUG - _trace.py:47 - send_request_body.started request=<Request [b'GET']>
|
| 289 |
+
2026-02-17 02:45:36 - DEBUG - _trace.py:47 - send_request_body.complete
|
| 290 |
+
2026-02-17 02:45:36 - DEBUG - _trace.py:47 - receive_response_headers.started request=<Request [b'GET']>
|
| 291 |
+
2026-02-17 02:45:36 - DEBUG - _trace.py:47 - receive_response_headers.complete return_value=(b'HTTP/1.1', 200, b'OK', [(b'Content-Encoding', b'gzip'), (b'Content-Type', b'application/json'), (b'Date', b'Mon, 16 Feb 2026 21:45:34 GMT'), (b'Vary', b'accept-encoding, Origin, Access-Control-Request-Method, Access-Control-Request-Headers'), (b'Transfer-Encoding', b'chunked')])
|
| 292 |
+
2026-02-17 02:45:36 - INFO - _client.py:1025 - HTTP Request: GET https://d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io:6333 "HTTP/1.1 200 OK"
|
| 293 |
+
2026-02-17 02:45:36 - DEBUG - _trace.py:47 - receive_response_body.started request=<Request [b'GET']>
|
| 294 |
+
2026-02-17 02:45:36 - DEBUG - _trace.py:47 - receive_response_body.complete
|
| 295 |
+
2026-02-17 02:45:36 - DEBUG - _trace.py:47 - response_closed.started
|
| 296 |
+
2026-02-17 02:45:36 - DEBUG - _trace.py:47 - response_closed.complete
|
| 297 |
+
2026-02-17 02:45:36 - DEBUG - _trace.py:47 - close.started
|
| 298 |
+
2026-02-17 02:45:36 - DEBUG - _trace.py:47 - close.complete
|
| 299 |
+
2026-02-17 02:45:36 - INFO - retrieve.py:323 - Checking collection 'book_embeddings'
|
| 300 |
+
2026-02-17 02:45:36 - DEBUG - _trace.py:47 - connect_tcp.started host='d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io' port=6333 local_address=None timeout=5.0 socket_options=None
|
| 301 |
+
2026-02-17 02:45:36 - DEBUG - _trace.py:47 - connect_tcp.complete return_value=<httpcore._backends.sync.SyncStream object at 0x7b345d26e000>
|
| 302 |
+
2026-02-17 02:45:36 - DEBUG - _trace.py:47 - start_tls.started ssl_context=<ssl.SSLContext object at 0x7b345d2436d0> server_hostname='d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io' timeout=5.0
|
| 303 |
+
2026-02-17 02:45:36 - DEBUG - _trace.py:47 - start_tls.complete return_value=<httpcore._backends.sync.SyncStream object at 0x7b345d26dee0>
|
| 304 |
+
2026-02-17 02:45:36 - DEBUG - _trace.py:47 - send_request_headers.started request=<Request [b'GET']>
|
| 305 |
+
2026-02-17 02:45:36 - DEBUG - _trace.py:47 - send_request_headers.complete
|
| 306 |
+
2026-02-17 02:45:36 - DEBUG - _trace.py:47 - send_request_body.started request=<Request [b'GET']>
|
| 307 |
+
2026-02-17 02:45:36 - DEBUG - _trace.py:47 - send_request_body.complete
|
| 308 |
+
2026-02-17 02:45:36 - DEBUG - _trace.py:47 - receive_response_headers.started request=<Request [b'GET']>
|
| 309 |
+
2026-02-17 02:45:37 - DEBUG - _trace.py:47 - receive_response_headers.complete return_value=(b'HTTP/1.1', 200, b'OK', [(b'Content-Encoding', b'gzip'), (b'Content-Type', b'application/json'), (b'Date', b'Mon, 16 Feb 2026 21:45:35 GMT'), (b'Vary', b'accept-encoding, Origin, Access-Control-Request-Method, Access-Control-Request-Headers'), (b'Transfer-Encoding', b'chunked')])
|
| 310 |
+
2026-02-17 02:45:37 - INFO - _client.py:1025 - HTTP Request: GET https://d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io:6333/collections/book_embeddings "HTTP/1.1 200 OK"
|
| 311 |
+
2026-02-17 02:45:37 - DEBUG - _trace.py:47 - receive_response_body.started request=<Request [b'GET']>
|
| 312 |
+
2026-02-17 02:45:37 - DEBUG - _trace.py:47 - receive_response_body.complete
|
| 313 |
+
2026-02-17 02:45:37 - DEBUG - _trace.py:47 - response_closed.started
|
| 314 |
+
2026-02-17 02:45:37 - DEBUG - _trace.py:47 - response_closed.complete
|
| 315 |
+
2026-02-17 02:45:37 - INFO - retrieve.py:325 - Collection OK: vector_size=1024, points=277
|
| 316 |
+
2026-02-17 02:45:37 - DEBUG - _trace.py:47 - close.started
|
| 317 |
+
2026-02-17 02:45:37 - DEBUG - _trace.py:47 - close.complete
|
| 318 |
+
2026-02-17 02:45:53 - INFO - retrieve.py:309 - === Retrieval Pipeline Started ===
|
| 319 |
+
2026-02-17 02:45:53 - INFO - retrieve.py:313 - Loading config from .env
|
| 320 |
+
2026-02-17 02:45:53 - INFO - retrieve.py:318 - Initializing Cohere and Qdrant clients
|
| 321 |
+
2026-02-17 02:45:54 - DEBUG - _trace.py:47 - connect_tcp.started host='d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io' port=6333 local_address=None timeout=5.0 socket_options=None
|
| 322 |
+
2026-02-17 02:45:54 - DEBUG - _trace.py:47 - connect_tcp.complete return_value=<httpcore._backends.sync.SyncStream object at 0x77effa835ee0>
|
| 323 |
+
2026-02-17 02:45:54 - DEBUG - _trace.py:47 - start_tls.started ssl_context=<ssl.SSLContext object at 0x77effa73b8d0> server_hostname='d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io' timeout=5.0
|
| 324 |
+
2026-02-17 02:45:54 - DEBUG - _trace.py:47 - start_tls.complete return_value=<httpcore._backends.sync.SyncStream object at 0x77effab2a5d0>
|
| 325 |
+
2026-02-17 02:45:54 - DEBUG - _trace.py:47 - send_request_headers.started request=<Request [b'GET']>
|
| 326 |
+
2026-02-17 02:45:54 - DEBUG - _trace.py:47 - send_request_headers.complete
|
| 327 |
+
2026-02-17 02:45:54 - DEBUG - _trace.py:47 - send_request_body.started request=<Request [b'GET']>
|
| 328 |
+
2026-02-17 02:45:54 - DEBUG - _trace.py:47 - send_request_body.complete
|
| 329 |
+
2026-02-17 02:45:54 - DEBUG - _trace.py:47 - receive_response_headers.started request=<Request [b'GET']>
|
| 330 |
+
2026-02-17 02:45:54 - DEBUG - _trace.py:47 - receive_response_headers.complete return_value=(b'HTTP/1.1', 200, b'OK', [(b'Content-Encoding', b'gzip'), (b'Content-Type', b'application/json'), (b'Date', b'Mon, 16 Feb 2026 21:45:53 GMT'), (b'Vary', b'accept-encoding, Origin, Access-Control-Request-Method, Access-Control-Request-Headers'), (b'Transfer-Encoding', b'chunked')])
|
| 331 |
+
2026-02-17 02:45:54 - INFO - _client.py:1025 - HTTP Request: GET https://d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io:6333 "HTTP/1.1 200 OK"
|
| 332 |
+
2026-02-17 02:45:54 - DEBUG - _trace.py:47 - receive_response_body.started request=<Request [b'GET']>
|
| 333 |
+
2026-02-17 02:45:54 - DEBUG - _trace.py:47 - receive_response_body.complete
|
| 334 |
+
2026-02-17 02:45:54 - DEBUG - _trace.py:47 - response_closed.started
|
| 335 |
+
2026-02-17 02:45:54 - DEBUG - _trace.py:47 - response_closed.complete
|
| 336 |
+
2026-02-17 02:45:54 - DEBUG - _trace.py:47 - close.started
|
| 337 |
+
2026-02-17 02:45:54 - DEBUG - _trace.py:47 - close.complete
|
| 338 |
+
2026-02-17 02:45:54 - INFO - retrieve.py:323 - Checking collection 'book_embeddings'
|
| 339 |
+
2026-02-17 02:45:54 - DEBUG - _trace.py:47 - connect_tcp.started host='d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io' port=6333 local_address=None timeout=5.0 socket_options=None
|
| 340 |
+
2026-02-17 02:45:54 - DEBUG - _trace.py:47 - connect_tcp.complete return_value=<httpcore._backends.sync.SyncStream object at 0x77effa765fa0>
|
| 341 |
+
2026-02-17 02:45:54 - DEBUG - _trace.py:47 - start_tls.started ssl_context=<ssl.SSLContext object at 0x77effa73b6d0> server_hostname='d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io' timeout=5.0
|
| 342 |
+
2026-02-17 02:45:55 - DEBUG - _trace.py:47 - start_tls.complete return_value=<httpcore._backends.sync.SyncStream object at 0x77effa765ee0>
|
| 343 |
+
2026-02-17 02:45:55 - DEBUG - _trace.py:47 - send_request_headers.started request=<Request [b'GET']>
|
| 344 |
+
2026-02-17 02:45:55 - DEBUG - _trace.py:47 - send_request_headers.complete
|
| 345 |
+
2026-02-17 02:45:55 - DEBUG - _trace.py:47 - send_request_body.started request=<Request [b'GET']>
|
| 346 |
+
2026-02-17 02:45:55 - DEBUG - _trace.py:47 - send_request_body.complete
|
| 347 |
+
2026-02-17 02:45:55 - DEBUG - _trace.py:47 - receive_response_headers.started request=<Request [b'GET']>
|
| 348 |
+
2026-02-17 02:45:55 - DEBUG - _trace.py:47 - receive_response_headers.complete return_value=(b'HTTP/1.1', 200, b'OK', [(b'Content-Encoding', b'gzip'), (b'Content-Type', b'application/json'), (b'Date', b'Mon, 16 Feb 2026 21:45:54 GMT'), (b'Vary', b'accept-encoding, Origin, Access-Control-Request-Method, Access-Control-Request-Headers'), (b'Transfer-Encoding', b'chunked')])
|
| 349 |
+
2026-02-17 02:45:55 - INFO - _client.py:1025 - HTTP Request: GET https://d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io:6333/collections/book_embeddings "HTTP/1.1 200 OK"
|
| 350 |
+
2026-02-17 02:45:55 - DEBUG - _trace.py:47 - receive_response_body.started request=<Request [b'GET']>
|
| 351 |
+
2026-02-17 02:45:55 - DEBUG - _trace.py:47 - receive_response_body.complete
|
| 352 |
+
2026-02-17 02:45:55 - DEBUG - _trace.py:47 - response_closed.started
|
| 353 |
+
2026-02-17 02:45:55 - DEBUG - _trace.py:47 - response_closed.complete
|
| 354 |
+
2026-02-17 02:45:55 - INFO - retrieve.py:325 - Collection OK: vector_size=1024, points=277
|
| 355 |
+
2026-02-17 02:45:55 - ERROR - retrieve.py:383 - Validation error: Query text must be non-empty
|
| 356 |
+
2026-02-17 02:45:55 - DEBUG - _trace.py:47 - close.started
|
| 357 |
+
2026-02-17 02:45:55 - DEBUG - _trace.py:47 - close.complete
|
| 358 |
+
2026-02-17 02:46:17 - INFO - retrieve.py:309 - === Retrieval Pipeline Started ===
|
| 359 |
+
2026-02-17 02:46:17 - INFO - retrieve.py:313 - Loading config from .env
|
| 360 |
+
2026-02-17 02:46:17 - INFO - retrieve.py:318 - Initializing Cohere and Qdrant clients
|
| 361 |
+
2026-02-17 02:46:17 - DEBUG - _trace.py:47 - connect_tcp.started host='d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io' port=6333 local_address=None timeout=5.0 socket_options=None
|
| 362 |
+
2026-02-17 02:46:17 - DEBUG - _trace.py:47 - connect_tcp.complete return_value=<httpcore._backends.sync.SyncStream object at 0x7523b47f0380>
|
| 363 |
+
2026-02-17 02:46:17 - DEBUG - _trace.py:47 - start_tls.started ssl_context=<ssl.SSLContext object at 0x7523b45938d0> server_hostname='d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io' timeout=5.0
|
| 364 |
+
2026-02-17 02:46:17 - DEBUG - _trace.py:47 - start_tls.complete return_value=<httpcore._backends.sync.SyncStream object at 0x7523b45bd790>
|
| 365 |
+
2026-02-17 02:46:17 - DEBUG - _trace.py:47 - send_request_headers.started request=<Request [b'GET']>
|
| 366 |
+
2026-02-17 02:46:17 - DEBUG - _trace.py:47 - send_request_headers.complete
|
| 367 |
+
2026-02-17 02:46:17 - DEBUG - _trace.py:47 - send_request_body.started request=<Request [b'GET']>
|
| 368 |
+
2026-02-17 02:46:17 - DEBUG - _trace.py:47 - send_request_body.complete
|
| 369 |
+
2026-02-17 02:46:17 - DEBUG - _trace.py:47 - receive_response_headers.started request=<Request [b'GET']>
|
| 370 |
+
2026-02-17 02:46:18 - DEBUG - _trace.py:47 - receive_response_headers.complete return_value=(b'HTTP/1.1', 200, b'OK', [(b'Content-Encoding', b'gzip'), (b'Content-Type', b'application/json'), (b'Date', b'Mon, 16 Feb 2026 21:46:15 GMT'), (b'Vary', b'accept-encoding, Origin, Access-Control-Request-Method, Access-Control-Request-Headers'), (b'Transfer-Encoding', b'chunked')])
|
| 371 |
+
2026-02-17 02:46:18 - INFO - _client.py:1025 - HTTP Request: GET https://d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io:6333 "HTTP/1.1 200 OK"
|
| 372 |
+
2026-02-17 02:46:18 - DEBUG - _trace.py:47 - receive_response_body.started request=<Request [b'GET']>
|
| 373 |
+
2026-02-17 02:46:18 - DEBUG - _trace.py:47 - receive_response_body.complete
|
| 374 |
+
2026-02-17 02:46:18 - DEBUG - _trace.py:47 - response_closed.started
|
| 375 |
+
2026-02-17 02:46:18 - DEBUG - _trace.py:47 - response_closed.complete
|
| 376 |
+
2026-02-17 02:46:18 - DEBUG - _trace.py:47 - close.started
|
| 377 |
+
2026-02-17 02:46:18 - DEBUG - _trace.py:47 - close.complete
|
| 378 |
+
2026-02-17 02:46:18 - INFO - retrieve.py:323 - Checking collection 'book_embeddings'
|
| 379 |
+
2026-02-17 02:46:18 - DEBUG - _trace.py:47 - connect_tcp.started host='d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io' port=6333 local_address=None timeout=5.0 socket_options=None
|
| 380 |
+
2026-02-17 02:46:18 - DEBUG - _trace.py:47 - connect_tcp.complete return_value=<httpcore._backends.sync.SyncStream object at 0x7523b45bdf40>
|
| 381 |
+
2026-02-17 02:46:18 - DEBUG - _trace.py:47 - start_tls.started ssl_context=<ssl.SSLContext object at 0x7523b45936d0> server_hostname='d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io' timeout=5.0
|
| 382 |
+
2026-02-17 02:46:18 - DEBUG - _trace.py:47 - start_tls.complete return_value=<httpcore._backends.sync.SyncStream object at 0x7523b45bde80>
|
| 383 |
+
2026-02-17 02:46:18 - DEBUG - _trace.py:47 - send_request_headers.started request=<Request [b'GET']>
|
| 384 |
+
2026-02-17 02:46:18 - DEBUG - _trace.py:47 - send_request_headers.complete
|
| 385 |
+
2026-02-17 02:46:18 - DEBUG - _trace.py:47 - send_request_body.started request=<Request [b'GET']>
|
| 386 |
+
2026-02-17 02:46:18 - DEBUG - _trace.py:47 - send_request_body.complete
|
| 387 |
+
2026-02-17 02:46:18 - DEBUG - _trace.py:47 - receive_response_headers.started request=<Request [b'GET']>
|
| 388 |
+
2026-02-17 02:46:18 - DEBUG - _trace.py:47 - receive_response_headers.complete return_value=(b'HTTP/1.1', 200, b'OK', [(b'Content-Encoding', b'gzip'), (b'Content-Type', b'application/json'), (b'Date', b'Mon, 16 Feb 2026 21:46:15 GMT'), (b'Vary', b'accept-encoding, Origin, Access-Control-Request-Method, Access-Control-Request-Headers'), (b'Transfer-Encoding', b'chunked')])
|
| 389 |
+
2026-02-17 02:46:18 - INFO - _client.py:1025 - HTTP Request: GET https://d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io:6333/collections/book_embeddings "HTTP/1.1 200 OK"
|
| 390 |
+
2026-02-17 02:46:18 - DEBUG - _trace.py:47 - receive_response_body.started request=<Request [b'GET']>
|
| 391 |
+
2026-02-17 02:46:18 - DEBUG - _trace.py:47 - receive_response_body.complete
|
| 392 |
+
2026-02-17 02:46:18 - DEBUG - _trace.py:47 - response_closed.started
|
| 393 |
+
2026-02-17 02:46:18 - DEBUG - _trace.py:47 - response_closed.complete
|
| 394 |
+
2026-02-17 02:46:18 - INFO - retrieve.py:325 - Collection OK: vector_size=1024, points=277
|
| 395 |
+
2026-02-17 02:46:18 - ERROR - retrieve.py:383 - Validation error: top_k must be between 1 and 100
|
| 396 |
+
2026-02-17 02:46:18 - DEBUG - _trace.py:47 - close.started
|
| 397 |
+
2026-02-17 02:46:18 - DEBUG - _trace.py:47 - close.complete
|
| 398 |
+
2026-02-17 02:46:34 - INFO - retrieve.py:309 - === Retrieval Pipeline Started ===
|
| 399 |
+
2026-02-17 02:46:34 - INFO - retrieve.py:313 - Loading config from .env
|
| 400 |
+
2026-02-17 02:46:34 - INFO - retrieve.py:318 - Initializing Cohere and Qdrant clients
|
| 401 |
+
2026-02-17 02:46:35 - DEBUG - _trace.py:47 - connect_tcp.started host='d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io' port=6333 local_address=None timeout=5.0 socket_options=None
|
| 402 |
+
2026-02-17 02:46:35 - DEBUG - _trace.py:47 - connect_tcp.complete return_value=<httpcore._backends.sync.SyncStream object at 0x7dc43c5a6240>
|
| 403 |
+
2026-02-17 02:46:35 - DEBUG - _trace.py:47 - start_tls.started ssl_context=<ssl.SSLContext object at 0x7dc43c22be50> server_hostname='d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io' timeout=5.0
|
| 404 |
+
2026-02-17 02:46:35 - DEBUG - _trace.py:47 - start_tls.complete return_value=<httpcore._backends.sync.SyncStream object at 0x7dc43c2659a0>
|
| 405 |
+
2026-02-17 02:46:35 - DEBUG - _trace.py:47 - send_request_headers.started request=<Request [b'GET']>
|
| 406 |
+
2026-02-17 02:46:35 - DEBUG - _trace.py:47 - send_request_headers.complete
|
| 407 |
+
2026-02-17 02:46:35 - DEBUG - _trace.py:47 - send_request_body.started request=<Request [b'GET']>
|
| 408 |
+
2026-02-17 02:46:35 - DEBUG - _trace.py:47 - send_request_body.complete
|
| 409 |
+
2026-02-17 02:46:35 - DEBUG - _trace.py:47 - receive_response_headers.started request=<Request [b'GET']>
|
| 410 |
+
2026-02-17 02:46:35 - DEBUG - _trace.py:47 - receive_response_headers.complete return_value=(b'HTTP/1.1', 200, b'OK', [(b'Content-Encoding', b'gzip'), (b'Content-Type', b'application/json'), (b'Date', b'Mon, 16 Feb 2026 21:46:33 GMT'), (b'Vary', b'accept-encoding, Origin, Access-Control-Request-Method, Access-Control-Request-Headers'), (b'Transfer-Encoding', b'chunked')])
|
| 411 |
+
2026-02-17 02:46:35 - INFO - _client.py:1025 - HTTP Request: GET https://d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io:6333 "HTTP/1.1 200 OK"
|
| 412 |
+
2026-02-17 02:46:35 - DEBUG - _trace.py:47 - receive_response_body.started request=<Request [b'GET']>
|
| 413 |
+
2026-02-17 02:46:35 - DEBUG - _trace.py:47 - receive_response_body.complete
|
| 414 |
+
2026-02-17 02:46:35 - DEBUG - _trace.py:47 - response_closed.started
|
| 415 |
+
2026-02-17 02:46:35 - DEBUG - _trace.py:47 - response_closed.complete
|
| 416 |
+
2026-02-17 02:46:35 - DEBUG - _trace.py:47 - close.started
|
| 417 |
+
2026-02-17 02:46:35 - DEBUG - _trace.py:47 - close.complete
|
| 418 |
+
2026-02-17 02:46:35 - INFO - retrieve.py:323 - Checking collection 'book_embeddings'
|
| 419 |
+
2026-02-17 02:46:35 - DEBUG - _trace.py:47 - connect_tcp.started host='d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io' port=6333 local_address=None timeout=5.0 socket_options=None
|
| 420 |
+
2026-02-17 02:46:35 - DEBUG - _trace.py:47 - connect_tcp.complete return_value=<httpcore._backends.sync.SyncStream object at 0x7dc43c2661b0>
|
| 421 |
+
2026-02-17 02:46:35 - DEBUG - _trace.py:47 - start_tls.started ssl_context=<ssl.SSLContext object at 0x7dc43c22bc50> server_hostname='d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io' timeout=5.0
|
| 422 |
+
2026-02-17 02:46:35 - DEBUG - _trace.py:47 - start_tls.complete return_value=<httpcore._backends.sync.SyncStream object at 0x7dc43c266090>
|
| 423 |
+
2026-02-17 02:46:35 - DEBUG - _trace.py:47 - send_request_headers.started request=<Request [b'GET']>
|
| 424 |
+
2026-02-17 02:46:35 - DEBUG - _trace.py:47 - send_request_headers.complete
|
| 425 |
+
2026-02-17 02:46:35 - DEBUG - _trace.py:47 - send_request_body.started request=<Request [b'GET']>
|
| 426 |
+
2026-02-17 02:46:35 - DEBUG - _trace.py:47 - send_request_body.complete
|
| 427 |
+
2026-02-17 02:46:35 - DEBUG - _trace.py:47 - receive_response_headers.started request=<Request [b'GET']>
|
| 428 |
+
2026-02-17 02:46:36 - DEBUG - _trace.py:47 - receive_response_headers.complete return_value=(b'HTTP/1.1', 200, b'OK', [(b'Content-Encoding', b'gzip'), (b'Content-Type', b'application/json'), (b'Date', b'Mon, 16 Feb 2026 21:46:34 GMT'), (b'Vary', b'accept-encoding, Origin, Access-Control-Request-Method, Access-Control-Request-Headers'), (b'Transfer-Encoding', b'chunked')])
|
| 429 |
+
2026-02-17 02:46:36 - INFO - _client.py:1025 - HTTP Request: GET https://d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io:6333/collections/book_embeddings "HTTP/1.1 200 OK"
|
| 430 |
+
2026-02-17 02:46:36 - DEBUG - _trace.py:47 - receive_response_body.started request=<Request [b'GET']>
|
| 431 |
+
2026-02-17 02:46:36 - DEBUG - _trace.py:47 - receive_response_body.complete
|
| 432 |
+
2026-02-17 02:46:36 - DEBUG - _trace.py:47 - response_closed.started
|
| 433 |
+
2026-02-17 02:46:36 - DEBUG - _trace.py:47 - response_closed.complete
|
| 434 |
+
2026-02-17 02:46:36 - INFO - retrieve.py:325 - Collection OK: vector_size=1024, points=277
|
| 435 |
+
2026-02-17 02:46:36 - ERROR - retrieve.py:383 - Validation error: top_k must be between 1 and 100
|
| 436 |
+
2026-02-17 02:46:36 - DEBUG - _trace.py:47 - close.started
|
| 437 |
+
2026-02-17 02:46:36 - DEBUG - _trace.py:47 - close.complete
|
| 438 |
+
2026-02-17 02:46:56 - INFO - retrieve.py:309 - === Retrieval Pipeline Started ===
|
| 439 |
+
2026-02-17 02:46:56 - INFO - retrieve.py:313 - Loading config from .env
|
| 440 |
+
2026-02-17 02:46:56 - INFO - retrieve.py:318 - Initializing Cohere and Qdrant clients
|
| 441 |
+
2026-02-17 02:46:57 - DEBUG - _trace.py:47 - connect_tcp.started host='d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io' port=6333 local_address=None timeout=5.0 socket_options=None
|
| 442 |
+
2026-02-17 02:46:57 - DEBUG - _trace.py:47 - connect_tcp.complete return_value=<httpcore._backends.sync.SyncStream object at 0x7608387a20c0>
|
| 443 |
+
2026-02-17 02:46:57 - DEBUG - _trace.py:47 - start_tls.started ssl_context=<ssl.SSLContext object at 0x7608384335d0> server_hostname='d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io' timeout=5.0
|
| 444 |
+
2026-02-17 02:46:57 - DEBUG - _trace.py:47 - start_tls.complete return_value=<httpcore._backends.sync.SyncStream object at 0x76083845da00>
|
| 445 |
+
2026-02-17 02:46:57 - DEBUG - _trace.py:47 - send_request_headers.started request=<Request [b'GET']>
|
| 446 |
+
2026-02-17 02:46:57 - DEBUG - _trace.py:47 - send_request_headers.complete
|
| 447 |
+
2026-02-17 02:46:57 - DEBUG - _trace.py:47 - send_request_body.started request=<Request [b'GET']>
|
| 448 |
+
2026-02-17 02:46:57 - DEBUG - _trace.py:47 - send_request_body.complete
|
| 449 |
+
2026-02-17 02:46:57 - DEBUG - _trace.py:47 - receive_response_headers.started request=<Request [b'GET']>
|
| 450 |
+
2026-02-17 02:46:57 - DEBUG - _trace.py:47 - receive_response_headers.complete return_value=(b'HTTP/1.1', 200, b'OK', [(b'Content-Encoding', b'gzip'), (b'Content-Type', b'application/json'), (b'Date', b'Mon, 16 Feb 2026 21:46:56 GMT'), (b'Vary', b'accept-encoding, Origin, Access-Control-Request-Method, Access-Control-Request-Headers'), (b'Transfer-Encoding', b'chunked')])
|
| 451 |
+
2026-02-17 02:46:57 - INFO - _client.py:1025 - HTTP Request: GET https://d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io:6333 "HTTP/1.1 200 OK"
|
| 452 |
+
2026-02-17 02:46:57 - DEBUG - _trace.py:47 - receive_response_body.started request=<Request [b'GET']>
|
| 453 |
+
2026-02-17 02:46:57 - DEBUG - _trace.py:47 - receive_response_body.complete
|
| 454 |
+
2026-02-17 02:46:57 - DEBUG - _trace.py:47 - response_closed.started
|
| 455 |
+
2026-02-17 02:46:57 - DEBUG - _trace.py:47 - response_closed.complete
|
| 456 |
+
2026-02-17 02:46:57 - DEBUG - _trace.py:47 - close.started
|
| 457 |
+
2026-02-17 02:46:57 - DEBUG - _trace.py:47 - close.complete
|
| 458 |
+
2026-02-17 02:46:57 - INFO - retrieve.py:323 - Checking collection 'book_embeddings'
|
| 459 |
+
2026-02-17 02:46:57 - DEBUG - _trace.py:47 - connect_tcp.started host='d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io' port=6333 local_address=None timeout=5.0 socket_options=None
|
| 460 |
+
2026-02-17 02:46:57 - DEBUG - _trace.py:47 - connect_tcp.complete return_value=<httpcore._backends.sync.SyncStream object at 0x76083845e2a0>
|
| 461 |
+
2026-02-17 02:46:58 - DEBUG - _trace.py:47 - start_tls.started ssl_context=<ssl.SSLContext object at 0x7608384333d0> server_hostname='d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io' timeout=5.0
|
| 462 |
+
2026-02-17 02:46:58 - DEBUG - _trace.py:47 - start_tls.complete return_value=<httpcore._backends.sync.SyncStream object at 0x76083845e180>
|
| 463 |
+
2026-02-17 02:46:58 - DEBUG - _trace.py:47 - send_request_headers.started request=<Request [b'GET']>
|
| 464 |
+
2026-02-17 02:46:58 - DEBUG - _trace.py:47 - send_request_headers.complete
|
| 465 |
+
2026-02-17 02:46:58 - DEBUG - _trace.py:47 - send_request_body.started request=<Request [b'GET']>
|
| 466 |
+
2026-02-17 02:46:58 - DEBUG - _trace.py:47 - send_request_body.complete
|
| 467 |
+
2026-02-17 02:46:58 - DEBUG - _trace.py:47 - receive_response_headers.started request=<Request [b'GET']>
|
| 468 |
+
2026-02-17 02:46:58 - DEBUG - _trace.py:47 - receive_response_headers.complete return_value=(b'HTTP/1.1', 200, b'OK', [(b'Content-Encoding', b'gzip'), (b'Content-Type', b'application/json'), (b'Date', b'Mon, 16 Feb 2026 21:46:57 GMT'), (b'Vary', b'accept-encoding, Origin, Access-Control-Request-Method, Access-Control-Request-Headers'), (b'Transfer-Encoding', b'chunked')])
|
| 469 |
+
2026-02-17 02:46:58 - INFO - _client.py:1025 - HTTP Request: GET https://d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io:6333/collections/book_embeddings "HTTP/1.1 200 OK"
|
| 470 |
+
2026-02-17 02:46:58 - DEBUG - _trace.py:47 - receive_response_body.started request=<Request [b'GET']>
|
| 471 |
+
2026-02-17 02:46:58 - DEBUG - _trace.py:47 - receive_response_body.complete
|
| 472 |
+
2026-02-17 02:46:58 - DEBUG - _trace.py:47 - response_closed.started
|
| 473 |
+
2026-02-17 02:46:58 - DEBUG - _trace.py:47 - response_closed.complete
|
| 474 |
+
2026-02-17 02:46:58 - INFO - retrieve.py:325 - Collection OK: vector_size=1024, points=277
|
| 475 |
+
2026-02-17 02:46:58 - INFO - retrieve.py:200 - Embedding query: 'asdfghjkl1234567890xyz_nonexistent_query_should_return_zero_results...' (top_k=5)
|
| 476 |
+
2026-02-17 02:46:58 - DEBUG - _trace.py:47 - connect_tcp.started host='api.cohere.com' port=443 local_address=None timeout=300 socket_options=None
|
| 477 |
+
2026-02-17 02:46:58 - DEBUG - _trace.py:47 - connect_tcp.complete return_value=<httpcore._backends.sync.SyncStream object at 0x76083845f230>
|
| 478 |
+
2026-02-17 02:46:58 - DEBUG - _trace.py:47 - start_tls.started ssl_context=<ssl.SSLContext object at 0x760838432cd0> server_hostname='api.cohere.com' timeout=300
|
| 479 |
+
2026-02-17 02:46:58 - DEBUG - _trace.py:47 - start_tls.complete return_value=<httpcore._backends.sync.SyncStream object at 0x76083845f140>
|
| 480 |
+
2026-02-17 02:46:58 - DEBUG - _trace.py:47 - send_request_headers.started request=<Request [b'POST']>
|
| 481 |
+
2026-02-17 02:46:58 - DEBUG - _trace.py:47 - send_request_headers.complete
|
| 482 |
+
2026-02-17 02:46:58 - DEBUG - _trace.py:47 - send_request_body.started request=<Request [b'POST']>
|
| 483 |
+
2026-02-17 02:46:58 - DEBUG - _trace.py:47 - send_request_body.complete
|
| 484 |
+
2026-02-17 02:46:58 - DEBUG - _trace.py:47 - receive_response_headers.started request=<Request [b'POST']>
|
| 485 |
+
2026-02-17 02:46:58 - DEBUG - _trace.py:47 - receive_response_headers.complete return_value=(b'HTTP/1.1', 200, b'OK', [(b'access-control-expose-headers', b'X-Debug-Trace-ID'), (b'cache-control', b'no-cache, no-store, no-transform, must-revalidate, private, max-age=0'), (b'content-encoding', b'gzip'), (b'content-type', b'application/json'), (b'expires', b'Thu, 01 Jan 1970 00:00:00 GMT'), (b'num_chars', b'67'), (b'num_tokens', b'28'), (b'pragma', b'no-cache'), (b'vary', b'Origin,Accept-Encoding'), (b'x-accel-expires', b'0'), (b'x-debug-trace-id', b'fd1019b199609124264ce2207ddc1acf'), (b'x-endpoint-monthly-call-limit', b'1000'), (b'x-trial-endpoint-call-limit', b'100'), (b'x-trial-endpoint-call-remaining', b'99'), (b'date', b'Mon, 16 Feb 2026 21:46:57 GMT'), (b'x-envoy-upstream-service-time', b'56'), (b'server', b'envoy'), (b'Via', b'1.1 google'), (b'Alt-Svc', b'h3=":443"; ma=2592000,h3-29=":443"; ma=2592000'), (b'Transfer-Encoding', b'chunked')])
|
| 486 |
+
2026-02-17 02:46:58 - INFO - _client.py:1025 - HTTP Request: POST https://api.cohere.com/v2/embed "HTTP/1.1 200 OK"
|
| 487 |
+
2026-02-17 02:46:58 - DEBUG - _trace.py:47 - receive_response_body.started request=<Request [b'POST']>
|
| 488 |
+
2026-02-17 02:46:58 - DEBUG - _trace.py:47 - receive_response_body.complete
|
| 489 |
+
2026-02-17 02:46:58 - DEBUG - _trace.py:47 - response_closed.started
|
| 490 |
+
2026-02-17 02:46:58 - DEBUG - _trace.py:47 - response_closed.complete
|
| 491 |
+
2026-02-17 02:46:58 - DEBUG - retrieve.py:212 - Generated embedding in 0.46s, dimension: 1024
|
| 492 |
+
2026-02-17 02:46:58 - DEBUG - _trace.py:47 - send_request_headers.started request=<Request [b'POST']>
|
| 493 |
+
2026-02-17 02:46:58 - DEBUG - _trace.py:47 - send_request_headers.complete
|
| 494 |
+
2026-02-17 02:46:58 - DEBUG - _trace.py:47 - send_request_body.started request=<Request [b'POST']>
|
| 495 |
+
2026-02-17 02:46:58 - DEBUG - _trace.py:47 - send_request_body.complete
|
| 496 |
+
2026-02-17 02:46:58 - DEBUG - _trace.py:47 - receive_response_headers.started request=<Request [b'POST']>
|
| 497 |
+
2026-02-17 02:46:59 - DEBUG - _trace.py:47 - receive_response_headers.complete return_value=(b'HTTP/1.1', 200, b'OK', [(b'Content-Encoding', b'gzip'), (b'Content-Type', b'application/json'), (b'Date', b'Mon, 16 Feb 2026 21:46:57 GMT'), (b'Vary', b'accept-encoding, Origin, Access-Control-Request-Method, Access-Control-Request-Headers'), (b'Transfer-Encoding', b'chunked')])
|
| 498 |
+
2026-02-17 02:46:59 - INFO - _client.py:1025 - HTTP Request: POST https://d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io:6333/collections/book_embeddings/points/query "HTTP/1.1 200 OK"
|
| 499 |
+
2026-02-17 02:46:59 - DEBUG - _trace.py:47 - receive_response_body.started request=<Request [b'POST']>
|
| 500 |
+
2026-02-17 02:46:59 - DEBUG - _trace.py:47 - receive_response_body.complete
|
| 501 |
+
2026-02-17 02:46:59 - DEBUG - _trace.py:47 - response_closed.started
|
| 502 |
+
2026-02-17 02:46:59 - DEBUG - _trace.py:47 - response_closed.complete
|
| 503 |
+
2026-02-17 02:46:59 - INFO - retrieve.py:234 - Search completed in 0.30s, returned 5 results
|
| 504 |
+
2026-02-17 02:46:59 - INFO - retrieve.py:249 - Total query time: 0.76s
|
| 505 |
+
2026-02-17 02:46:59 - INFO - retrieve.py:379 - === Retrieval Pipeline Completed Successfully ===
|
| 506 |
+
2026-02-17 02:46:59 - DEBUG - _trace.py:47 - close.started
|
| 507 |
+
2026-02-17 02:46:59 - DEBUG - _trace.py:47 - close.complete
|
| 508 |
+
2026-02-17 03:15:14 - INFO - retrieve.py:309 - === Retrieval Pipeline Started ===
|
| 509 |
+
2026-02-17 03:15:14 - INFO - retrieve.py:313 - Loading config from .env
|
| 510 |
+
2026-02-17 03:15:14 - INFO - retrieve.py:318 - Initializing Cohere and Qdrant clients
|
| 511 |
+
2026-02-17 03:15:15 - DEBUG - _trace.py:47 - connect_tcp.started host='d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io' port=6333 local_address=None timeout=5.0 socket_options=None
|
| 512 |
+
2026-02-17 03:15:15 - DEBUG - _trace.py:47 - connect_tcp.complete return_value=<httpcore._backends.sync.SyncStream object at 0x7960c15697f0>
|
| 513 |
+
2026-02-17 03:15:15 - DEBUG - _trace.py:47 - start_tls.started ssl_context=<ssl.SSLContext object at 0x7960c1543850> server_hostname='d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io' timeout=5.0
|
| 514 |
+
2026-02-17 03:15:15 - DEBUG - _trace.py:47 - start_tls.complete return_value=<httpcore._backends.sync.SyncStream object at 0x7960c1569730>
|
| 515 |
+
2026-02-17 03:15:15 - DEBUG - _trace.py:47 - send_request_headers.started request=<Request [b'GET']>
|
| 516 |
+
2026-02-17 03:15:15 - DEBUG - _trace.py:47 - send_request_headers.complete
|
| 517 |
+
2026-02-17 03:15:15 - DEBUG - _trace.py:47 - send_request_body.started request=<Request [b'GET']>
|
| 518 |
+
2026-02-17 03:15:15 - DEBUG - _trace.py:47 - send_request_body.complete
|
| 519 |
+
2026-02-17 03:15:15 - DEBUG - _trace.py:47 - receive_response_headers.started request=<Request [b'GET']>
|
| 520 |
+
2026-02-17 03:15:16 - DEBUG - _trace.py:47 - receive_response_headers.complete return_value=(b'HTTP/1.1', 200, b'OK', [(b'Content-Encoding', b'gzip'), (b'Content-Type', b'application/json'), (b'Date', b'Mon, 16 Feb 2026 22:15:14 GMT'), (b'Vary', b'accept-encoding, Origin, Access-Control-Request-Method, Access-Control-Request-Headers'), (b'Transfer-Encoding', b'chunked')])
|
| 521 |
+
2026-02-17 03:15:16 - INFO - _client.py:1025 - HTTP Request: GET https://d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io:6333 "HTTP/1.1 200 OK"
|
| 522 |
+
2026-02-17 03:15:16 - DEBUG - _trace.py:47 - receive_response_body.started request=<Request [b'GET']>
|
| 523 |
+
2026-02-17 03:15:16 - DEBUG - _trace.py:47 - receive_response_body.complete
|
| 524 |
+
2026-02-17 03:15:16 - DEBUG - _trace.py:47 - response_closed.started
|
| 525 |
+
2026-02-17 03:15:16 - DEBUG - _trace.py:47 - response_closed.complete
|
| 526 |
+
2026-02-17 03:15:16 - DEBUG - _trace.py:47 - close.started
|
| 527 |
+
2026-02-17 03:15:16 - DEBUG - _trace.py:47 - close.complete
|
| 528 |
+
2026-02-17 03:15:16 - INFO - retrieve.py:323 - Checking collection 'book_embeddings'
|
| 529 |
+
2026-02-17 03:15:16 - DEBUG - _trace.py:47 - connect_tcp.started host='d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io' port=6333 local_address=None timeout=5.0 socket_options=None
|
| 530 |
+
2026-02-17 03:15:16 - DEBUG - _trace.py:47 - connect_tcp.complete return_value=<httpcore._backends.sync.SyncStream object at 0x7960c1569df0>
|
| 531 |
+
2026-02-17 03:15:16 - DEBUG - _trace.py:47 - start_tls.started ssl_context=<ssl.SSLContext object at 0x7960c1543650> server_hostname='d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io' timeout=5.0
|
| 532 |
+
2026-02-17 03:15:16 - DEBUG - _trace.py:47 - start_tls.complete return_value=<httpcore._backends.sync.SyncStream object at 0x7960c1569b80>
|
| 533 |
+
2026-02-17 03:15:16 - DEBUG - _trace.py:47 - send_request_headers.started request=<Request [b'GET']>
|
| 534 |
+
2026-02-17 03:15:16 - DEBUG - _trace.py:47 - send_request_headers.complete
|
| 535 |
+
2026-02-17 03:15:16 - DEBUG - _trace.py:47 - send_request_body.started request=<Request [b'GET']>
|
| 536 |
+
2026-02-17 03:15:16 - DEBUG - _trace.py:47 - send_request_body.complete
|
| 537 |
+
2026-02-17 03:15:16 - DEBUG - _trace.py:47 - receive_response_headers.started request=<Request [b'GET']>
|
| 538 |
+
2026-02-17 03:15:16 - DEBUG - _trace.py:47 - receive_response_headers.complete return_value=(b'HTTP/1.1', 200, b'OK', [(b'Content-Encoding', b'gzip'), (b'Content-Type', b'application/json'), (b'Date', b'Mon, 16 Feb 2026 22:15:15 GMT'), (b'Vary', b'accept-encoding, Origin, Access-Control-Request-Method, Access-Control-Request-Headers'), (b'Transfer-Encoding', b'chunked')])
|
| 539 |
+
2026-02-17 03:15:16 - INFO - _client.py:1025 - HTTP Request: GET https://d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io:6333/collections/book_embeddings "HTTP/1.1 200 OK"
|
| 540 |
+
2026-02-17 03:15:16 - DEBUG - _trace.py:47 - receive_response_body.started request=<Request [b'GET']>
|
| 541 |
+
2026-02-17 03:15:16 - DEBUG - _trace.py:47 - receive_response_body.complete
|
| 542 |
+
2026-02-17 03:15:16 - DEBUG - _trace.py:47 - response_closed.started
|
| 543 |
+
2026-02-17 03:15:16 - DEBUG - _trace.py:47 - response_closed.complete
|
| 544 |
+
2026-02-17 03:15:16 - INFO - retrieve.py:325 - Collection OK: vector_size=1024, points=277
|
| 545 |
+
2026-02-17 03:15:16 - INFO - retrieve.py:200 - Embedding query: 'ROS 2...' (top_k=5)
|
| 546 |
+
2026-02-17 03:15:16 - DEBUG - _trace.py:47 - connect_tcp.started host='api.cohere.com' port=443 local_address=None timeout=300 socket_options=None
|
| 547 |
+
2026-02-17 03:15:16 - DEBUG - _trace.py:47 - connect_tcp.complete return_value=<httpcore._backends.sync.SyncStream object at 0x7960c156ad20>
|
| 548 |
+
2026-02-17 03:15:16 - DEBUG - _trace.py:47 - start_tls.started ssl_context=<ssl.SSLContext object at 0x7960c1542f50> server_hostname='api.cohere.com' timeout=300
|
| 549 |
+
2026-02-17 03:15:16 - DEBUG - _trace.py:47 - start_tls.complete return_value=<httpcore._backends.sync.SyncStream object at 0x7960c156ac30>
|
| 550 |
+
2026-02-17 03:15:16 - DEBUG - _trace.py:47 - send_request_headers.started request=<Request [b'POST']>
|
| 551 |
+
2026-02-17 03:15:16 - DEBUG - _trace.py:47 - send_request_headers.complete
|
| 552 |
+
2026-02-17 03:15:16 - DEBUG - _trace.py:47 - send_request_body.started request=<Request [b'POST']>
|
| 553 |
+
2026-02-17 03:15:16 - DEBUG - _trace.py:47 - send_request_body.complete
|
| 554 |
+
2026-02-17 03:15:16 - DEBUG - _trace.py:47 - receive_response_headers.started request=<Request [b'POST']>
|
| 555 |
+
2026-02-17 03:15:16 - DEBUG - _trace.py:47 - receive_response_headers.complete return_value=(b'HTTP/1.1', 200, b'OK', [(b'access-control-expose-headers', b'X-Debug-Trace-ID'), (b'cache-control', b'no-cache, no-store, no-transform, must-revalidate, private, max-age=0'), (b'content-encoding', b'gzip'), (b'content-type', b'application/json'), (b'expires', b'Thu, 01 Jan 1970 00:00:00 GMT'), (b'num_chars', b'5'), (b'num_tokens', b'3'), (b'pragma', b'no-cache'), (b'vary', b'Origin,Accept-Encoding'), (b'x-accel-expires', b'0'), (b'x-debug-trace-id', b'4df4171dafe6d9e613e8c5e32b7ae73b'), (b'x-endpoint-monthly-call-limit', b'1000'), (b'x-trial-endpoint-call-limit', b'100'), (b'x-trial-endpoint-call-remaining', b'99'), (b'date', b'Mon, 16 Feb 2026 22:15:15 GMT'), (b'x-envoy-upstream-service-time', b'42'), (b'server', b'envoy'), (b'Via', b'1.1 google'), (b'Alt-Svc', b'h3=":443"; ma=2592000,h3-29=":443"; ma=2592000'), (b'Transfer-Encoding', b'chunked')])
|
| 556 |
+
2026-02-17 03:15:16 - INFO - _client.py:1025 - HTTP Request: POST https://api.cohere.com/v2/embed "HTTP/1.1 200 OK"
|
| 557 |
+
2026-02-17 03:15:16 - DEBUG - _trace.py:47 - receive_response_body.started request=<Request [b'POST']>
|
| 558 |
+
2026-02-17 03:15:16 - DEBUG - _trace.py:47 - receive_response_body.complete
|
| 559 |
+
2026-02-17 03:15:16 - DEBUG - _trace.py:47 - response_closed.started
|
| 560 |
+
2026-02-17 03:15:16 - DEBUG - _trace.py:47 - response_closed.complete
|
| 561 |
+
2026-02-17 03:15:16 - DEBUG - retrieve.py:212 - Generated embedding in 0.49s, dimension: 1024
|
| 562 |
+
2026-02-17 03:15:16 - DEBUG - _trace.py:47 - send_request_headers.started request=<Request [b'POST']>
|
| 563 |
+
2026-02-17 03:15:16 - DEBUG - _trace.py:47 - send_request_headers.complete
|
| 564 |
+
2026-02-17 03:15:16 - DEBUG - _trace.py:47 - send_request_body.started request=<Request [b'POST']>
|
| 565 |
+
2026-02-17 03:15:16 - DEBUG - _trace.py:47 - send_request_body.complete
|
| 566 |
+
2026-02-17 03:15:16 - DEBUG - _trace.py:47 - receive_response_headers.started request=<Request [b'POST']>
|
| 567 |
+
2026-02-17 03:15:17 - DEBUG - _trace.py:47 - receive_response_headers.complete return_value=(b'HTTP/1.1', 200, b'OK', [(b'Content-Encoding', b'gzip'), (b'Content-Type', b'application/json'), (b'Date', b'Mon, 16 Feb 2026 22:15:15 GMT'), (b'Vary', b'accept-encoding, Origin, Access-Control-Request-Method, Access-Control-Request-Headers'), (b'Transfer-Encoding', b'chunked')])
|
| 568 |
+
2026-02-17 03:15:17 - INFO - _client.py:1025 - HTTP Request: POST https://d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io:6333/collections/book_embeddings/points/query "HTTP/1.1 200 OK"
|
| 569 |
+
2026-02-17 03:15:17 - DEBUG - _trace.py:47 - receive_response_body.started request=<Request [b'POST']>
|
| 570 |
+
2026-02-17 03:15:17 - DEBUG - _trace.py:47 - receive_response_body.complete
|
| 571 |
+
2026-02-17 03:15:17 - DEBUG - _trace.py:47 - response_closed.started
|
| 572 |
+
2026-02-17 03:15:17 - DEBUG - _trace.py:47 - response_closed.complete
|
| 573 |
+
2026-02-17 03:15:17 - INFO - retrieve.py:234 - Search completed in 0.31s, returned 5 results
|
| 574 |
+
2026-02-17 03:15:17 - INFO - retrieve.py:249 - Total query time: 0.80s
|
| 575 |
+
2026-02-17 03:15:17 - INFO - retrieve.py:379 - === Retrieval Pipeline Completed Successfully ===
|
| 576 |
+
2026-02-17 03:15:17 - DEBUG - _trace.py:47 - close.started
|
| 577 |
+
2026-02-17 03:15:17 - DEBUG - _trace.py:47 - close.complete
|
retrieve.py
ADDED
|
@@ -0,0 +1,408 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Retrieval pipeline for RAG validation.
|
| 3 |
+
|
| 4 |
+
This module provides functions to:
|
| 5 |
+
- Convert search queries to embeddings using Cohere
|
| 6 |
+
- Perform similarity search against Qdrant collection
|
| 7 |
+
- Format and return results with metadata
|
| 8 |
+
"""
|
| 9 |
+
import argparse
|
| 10 |
+
import json
|
| 11 |
+
import sys
|
| 12 |
+
import time
|
| 13 |
+
import logging
|
| 14 |
+
from pathlib import Path
|
| 15 |
+
from typing import List, Dict, Any
|
| 16 |
+
|
| 17 |
+
# Add parent directory to path for imports
|
| 18 |
+
sys.path.insert(0, str(Path(__file__).parent))
|
| 19 |
+
|
| 20 |
+
import cohere
|
| 21 |
+
from qdrant_client import QdrantClient
|
| 22 |
+
|
| 23 |
+
# Importfrom existing modules
|
| 24 |
+
import config
|
| 25 |
+
import utils
|
| 26 |
+
from logging_config import setup_logging
|
| 27 |
+
|
| 28 |
+
# Initialize logger
|
| 29 |
+
logger = logging.getLogger(__name__)
|
| 30 |
+
|
| 31 |
+
# Custom exceptions
|
| 32 |
+
class ConfigurationError(Exception):
|
| 33 |
+
"""Raised when required configuration is missing."""
|
| 34 |
+
pass
|
| 35 |
+
|
| 36 |
+
class CollectionNotFoundError(Exception):
|
| 37 |
+
"""Raised when Qdrant collection doesn't exist."""
|
| 38 |
+
pass
|
| 39 |
+
|
| 40 |
+
class DimensionMismatchError(Exception):
|
| 41 |
+
"""Raised when embedding dimension doesn't match collection."""
|
| 42 |
+
pass
|
| 43 |
+
|
| 44 |
+
class APIError(Exception):
|
| 45 |
+
"""Raised when Cohere or Qdrant API call fails after retries."""
|
| 46 |
+
pass
|
| 47 |
+
|
| 48 |
+
def validate_config(cfg: dict) -> None:
|
| 49 |
+
"""Validate that all required config values are present."""
|
| 50 |
+
required = ["cohere_api_key", "qdrant_url", "qdrant_api_key"]
|
| 51 |
+
missing = [key for key in required if not cfg.get(key)]
|
| 52 |
+
if missing:
|
| 53 |
+
raise ConfigurationError(f"Missing required environment variables: {', '.join(missing)}")
|
| 54 |
+
|
| 55 |
+
def init_clients(cfg: dict):
|
| 56 |
+
"""Initialize Cohere and Qdrant clients."""
|
| 57 |
+
cohere_client = cohere.ClientV2(api_key=cfg["cohere_api_key"])
|
| 58 |
+
qdrant_client = QdrantClient(url=cfg["qdrant_url"], api_key=cfg["qdrant_api_key"])
|
| 59 |
+
return cohere_client, qdrant_client
|
| 60 |
+
|
| 61 |
+
def check_collection(qdrant_client: QdrantClient, collection_name: str) -> Dict[str, Any]:
|
| 62 |
+
"""Verify collection exists and has correct vector size."""
|
| 63 |
+
try:
|
| 64 |
+
info = qdrant_client.get_collection(collection_name)
|
| 65 |
+
except Exception as e:
|
| 66 |
+
if "not found" in str(e).lower():
|
| 67 |
+
raise CollectionNotFoundError(f"Collection '{collection_name}' does not exist")
|
| 68 |
+
raise
|
| 69 |
+
|
| 70 |
+
vector_size = info.config.params.vectors.size
|
| 71 |
+
if vector_size != 1024:
|
| 72 |
+
raise DimensionMismatchError(f"Expected vector size 1024 but got {vector_size}")
|
| 73 |
+
|
| 74 |
+
return {
|
| 75 |
+
"exists": True,
|
| 76 |
+
"vector_size": vector_size,
|
| 77 |
+
"points_count": info.points_count
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
def embed_query(text: str, cohere_client: cohere.ClientV2) -> List[float]:
|
| 81 |
+
"""Generate embedding for a search query using Cohere."""
|
| 82 |
+
try:
|
| 83 |
+
response = cohere_client.embed(
|
| 84 |
+
texts=[text],
|
| 85 |
+
model="embed-english-v3.0",
|
| 86 |
+
input_type="search_query"
|
| 87 |
+
)
|
| 88 |
+
# Extract embedding from response.embeddings.float_
|
| 89 |
+
embedding = response.embeddings.float_[0]
|
| 90 |
+
return embedding
|
| 91 |
+
except Exception as e:
|
| 92 |
+
logger.error(f"Failed to generate embedding: {e}")
|
| 93 |
+
raise APIError(f"Cohere embedding failed: {e}")
|
| 94 |
+
|
| 95 |
+
def validate_metadata_completeness(results: List[Dict[str, Any]]) -> float:
|
| 96 |
+
"""
|
| 97 |
+
Check metadata completeness in search results.
|
| 98 |
+
|
| 99 |
+
Returns:
|
| 100 |
+
Percentage (0-100) of results with complete metadata:
|
| 101 |
+
- url present and non-empty
|
| 102 |
+
- text present with length ≥ 10
|
| 103 |
+
- at least one of title or section non-empty
|
| 104 |
+
"""
|
| 105 |
+
if not results:
|
| 106 |
+
return 0.0
|
| 107 |
+
|
| 108 |
+
complete = 0
|
| 109 |
+
total = len(results)
|
| 110 |
+
|
| 111 |
+
for result in results:
|
| 112 |
+
payload = result.get('payload', {})
|
| 113 |
+
url = payload.get('url', '')
|
| 114 |
+
text = payload.get('text', '')
|
| 115 |
+
title = payload.get('title', '')
|
| 116 |
+
section = payload.get('section', '')
|
| 117 |
+
|
| 118 |
+
# Check completeness criteria
|
| 119 |
+
url_ok = bool(url and url.strip())
|
| 120 |
+
text_ok = len(text or '') >= 10
|
| 121 |
+
title_section_ok = bool((title and title.strip()) or (section and section.strip()))
|
| 122 |
+
|
| 123 |
+
if url_ok and text_ok and title_section_ok:
|
| 124 |
+
complete += 1
|
| 125 |
+
|
| 126 |
+
percentage = (complete / total) * 100
|
| 127 |
+
logger.debug(f"Metadata completeness: {complete}/{total} = {percentage:.1f}%")
|
| 128 |
+
return percentage
|
| 129 |
+
|
| 130 |
+
|
| 131 |
+
def validate_chunk_sequencing(results: List[Dict[str, Any]]) -> bool:
|
| 132 |
+
"""
|
| 133 |
+
Verify that chunk_index values are properly assigned: integers >= 0 and unique per URL.
|
| 134 |
+
|
| 135 |
+
Note: Since search may return only a subset of chunks for a URL, we cannot
|
| 136 |
+
verify full sequential continuity (0,1,2,3...). Instead we check:
|
| 137 |
+
- All chunk_index values are integers >= 0
|
| 138 |
+
- No duplicate chunk_index for the same URL in the result set
|
| 139 |
+
|
| 140 |
+
Args:
|
| 141 |
+
results: List of search results
|
| 142 |
+
|
| 143 |
+
Returns:
|
| 144 |
+
True if chunk indices are valid, False otherwise
|
| 145 |
+
"""
|
| 146 |
+
# Group by URL
|
| 147 |
+
url_chunks = {}
|
| 148 |
+
for result in results:
|
| 149 |
+
payload = result.get('payload', {})
|
| 150 |
+
url = payload.get('url', '')
|
| 151 |
+
chunk_idx = payload.get('chunk_index')
|
| 152 |
+
|
| 153 |
+
if url not in url_chunks:
|
| 154 |
+
url_chunks[url] = []
|
| 155 |
+
url_chunks[url].append(chunk_idx)
|
| 156 |
+
|
| 157 |
+
# Check each URL's chunks are valid
|
| 158 |
+
for url, indices in url_chunks.items():
|
| 159 |
+
# All indices must be integers >= 0
|
| 160 |
+
for idx in indices:
|
| 161 |
+
if not isinstance(idx, int) or idx < 0:
|
| 162 |
+
logger.debug(f"Invalid chunk_index for {url}: {idx} (must be non-negative integer)")
|
| 163 |
+
return False
|
| 164 |
+
|
| 165 |
+
# Check for duplicates (within this URL's results)
|
| 166 |
+
if len(set(indices)) != len(indices):
|
| 167 |
+
logger.debug(f"Duplicate chunk_index for {url}: {indices}")
|
| 168 |
+
return False
|
| 169 |
+
|
| 170 |
+
logger.debug(f"Chunk indexing valid for {len(url_chunks)} URLs")
|
| 171 |
+
return True
|
| 172 |
+
|
| 173 |
+
|
| 174 |
+
def search(
|
| 175 |
+
query_text: str,
|
| 176 |
+
cohere_client: cohere.ClientV2,
|
| 177 |
+
qdrant_client: QdrantClient,
|
| 178 |
+
collection_name: str,
|
| 179 |
+
top_k: int = 5
|
| 180 |
+
) -> List[Dict[str, Any]]:
|
| 181 |
+
"""
|
| 182 |
+
Convert query to embedding and retrieve top-K relevant chunks.
|
| 183 |
+
|
| 184 |
+
Args:
|
| 185 |
+
query_text: User's search query (non-empty, ≤1000 chars)
|
| 186 |
+
top_k: Number of results to return (1-100)
|
| 187 |
+
|
| 188 |
+
Returns:
|
| 189 |
+
List of search results with id, score, and payload
|
| 190 |
+
"""
|
| 191 |
+
# Validate inputs
|
| 192 |
+
if not query_text or not query_text.strip():
|
| 193 |
+
raise ValueError("Query text must be non-empty")
|
| 194 |
+
query_text = query_text.strip()
|
| 195 |
+
if len(query_text) > 1000:
|
| 196 |
+
raise ValueError("Query text must be ≤ 1000 characters")
|
| 197 |
+
if top_k < 1 or top_k > 100:
|
| 198 |
+
raise ValueError("top_k must be between 1 and 100")
|
| 199 |
+
|
| 200 |
+
logger.info(f"Embedding query: '{query_text[:100]}...' (top_k={top_k})")
|
| 201 |
+
start_time = time.time()
|
| 202 |
+
|
| 203 |
+
# Generate query embedding with retry
|
| 204 |
+
try:
|
| 205 |
+
embedding = utils.retry_with_backoff(
|
| 206 |
+
lambda: embed_query(query_text, cohere_client),
|
| 207 |
+
max_retries=3,
|
| 208 |
+
base_delay=1.0,
|
| 209 |
+
max_delay=10.0
|
| 210 |
+
)
|
| 211 |
+
embed_time = time.time() - start_time
|
| 212 |
+
logger.debug(f"Generated embedding in {embed_time:.2f}s, dimension: {len(embedding)}")
|
| 213 |
+
except Exception as e:
|
| 214 |
+
logger.error(f"Failed to embed query: {e}")
|
| 215 |
+
raise
|
| 216 |
+
|
| 217 |
+
# Search Qdrant with retry
|
| 218 |
+
try:
|
| 219 |
+
search_start = time.time()
|
| 220 |
+
response = utils.retry_with_backoff(
|
| 221 |
+
lambda: qdrant_client.query_points(
|
| 222 |
+
collection_name=collection_name,
|
| 223 |
+
query=embedding,
|
| 224 |
+
limit=top_k,
|
| 225 |
+
with_payload=True,
|
| 226 |
+
with_vectors=False
|
| 227 |
+
),
|
| 228 |
+
max_retries=3,
|
| 229 |
+
base_delay=1.0,
|
| 230 |
+
max_delay=10.0
|
| 231 |
+
)
|
| 232 |
+
results = response.points
|
| 233 |
+
search_time = time.time() - search_start
|
| 234 |
+
logger.info(f"Search completed in {search_time:.2f}s, returned {len(results)} results")
|
| 235 |
+
except Exception as e:
|
| 236 |
+
logger.error(f"Search failed: {e}")
|
| 237 |
+
raise APIError(f"Qdrant search failed: {e}")
|
| 238 |
+
|
| 239 |
+
# Format results
|
| 240 |
+
formatted = []
|
| 241 |
+
for result in results:
|
| 242 |
+
formatted.append({
|
| 243 |
+
"id": str(result.id),
|
| 244 |
+
"score": float(result.score),
|
| 245 |
+
"payload": result.payload
|
| 246 |
+
})
|
| 247 |
+
|
| 248 |
+
total_time = time.time() - start_time
|
| 249 |
+
logger.info(f"Total query time: {total_time:.2f}s")
|
| 250 |
+
|
| 251 |
+
return formatted
|
| 252 |
+
|
| 253 |
+
def format_results(
|
| 254 |
+
results: List[Dict[str, Any]],
|
| 255 |
+
query: str,
|
| 256 |
+
latency_ms: int
|
| 257 |
+
) -> Dict[str, Any]:
|
| 258 |
+
"""Format search results into JSON output structure."""
|
| 259 |
+
output = {
|
| 260 |
+
"query": query,
|
| 261 |
+
"timestamp": time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime()),
|
| 262 |
+
"results": results,
|
| 263 |
+
"metadata": {
|
| 264 |
+
"total_results": len(results),
|
| 265 |
+
"collection": None, # Will be filled by main
|
| 266 |
+
"latency_ms": latency_ms
|
| 267 |
+
}
|
| 268 |
+
}
|
| 269 |
+
return output
|
| 270 |
+
|
| 271 |
+
def main() -> int:
|
| 272 |
+
"""CLI entrypoint for retrieval."""
|
| 273 |
+
parser = argparse.ArgumentParser(
|
| 274 |
+
description="Retrieve relevant chunks from Qdrant using Cohere embeddings"
|
| 275 |
+
)
|
| 276 |
+
parser.add_argument(
|
| 277 |
+
"--query",
|
| 278 |
+
type=str,
|
| 279 |
+
help="Search query text"
|
| 280 |
+
)
|
| 281 |
+
parser.add_argument(
|
| 282 |
+
"--top-k",
|
| 283 |
+
type=int,
|
| 284 |
+
default=5,
|
| 285 |
+
help="Number of results to return (default: 5)"
|
| 286 |
+
)
|
| 287 |
+
parser.add_argument(
|
| 288 |
+
"--output",
|
| 289 |
+
type=str,
|
| 290 |
+
help="Output file path (default: stdout)"
|
| 291 |
+
)
|
| 292 |
+
parser.add_argument(
|
| 293 |
+
"--config",
|
| 294 |
+
type=str,
|
| 295 |
+
default=".env",
|
| 296 |
+
help="Path to .env config file (default: .env)"
|
| 297 |
+
)
|
| 298 |
+
parser.add_argument(
|
| 299 |
+
"--validate-metadata",
|
| 300 |
+
action="store_true",
|
| 301 |
+
help="Run metadata validation on search results (requires --query)"
|
| 302 |
+
)
|
| 303 |
+
|
| 304 |
+
args = parser.parse_args()
|
| 305 |
+
|
| 306 |
+
# Setup logging
|
| 307 |
+
log_file = "retrieve.log"
|
| 308 |
+
setup_logging(log_file=log_file, console_level="INFO")
|
| 309 |
+
logger.info("=== Retrieval Pipeline Started ===")
|
| 310 |
+
|
| 311 |
+
try:
|
| 312 |
+
# Load config
|
| 313 |
+
logger.info(f"Loading config from {args.config}")
|
| 314 |
+
cfg = config.get_config()
|
| 315 |
+
validate_config(cfg)
|
| 316 |
+
|
| 317 |
+
# Initialize clients
|
| 318 |
+
logger.info("Initializing Cohere and Qdrant clients")
|
| 319 |
+
cohere_client, qdrant_client = init_clients(cfg)
|
| 320 |
+
|
| 321 |
+
# Check collection
|
| 322 |
+
collection_name = cfg["qdrant_collection"]
|
| 323 |
+
logger.info(f"Checking collection '{collection_name}'")
|
| 324 |
+
coll_info = check_collection(qdrant_client, collection_name)
|
| 325 |
+
logger.info(f"Collection OK: vector_size={coll_info['vector_size']}, points={coll_info['points_count']}")
|
| 326 |
+
|
| 327 |
+
# Validate query argument
|
| 328 |
+
if not args.query:
|
| 329 |
+
parser.error("--query is required")
|
| 330 |
+
|
| 331 |
+
# Perform search
|
| 332 |
+
results = search(
|
| 333 |
+
query_text=args.query,
|
| 334 |
+
cohere_client=cohere_client,
|
| 335 |
+
qdrant_client=qdrant_client,
|
| 336 |
+
collection_name=collection_name,
|
| 337 |
+
top_k=args.top_k
|
| 338 |
+
)
|
| 339 |
+
|
| 340 |
+
# Perform metadata validation if requested
|
| 341 |
+
metadata_validation = None
|
| 342 |
+
if args.validate_metadata:
|
| 343 |
+
completeness = validate_metadata_completeness(results)
|
| 344 |
+
sequencing = validate_chunk_sequencing(results)
|
| 345 |
+
metadata_validation = {
|
| 346 |
+
"completeness_pct": round(completeness, 2),
|
| 347 |
+
"sequencing_valid": sequencing,
|
| 348 |
+
"pass": completeness >= 98.0 and sequencing
|
| 349 |
+
}
|
| 350 |
+
logger.info(f"Metadata completeness: {completeness:.1f}%")
|
| 351 |
+
logger.info(f"Chunk sequencing: {'VALID' if sequencing else 'INVALID'}")
|
| 352 |
+
logger.info(f"Validation result: {'PASS' if metadata_validation['pass'] else 'FAIL'}")
|
| 353 |
+
|
| 354 |
+
# Format output
|
| 355 |
+
output = {
|
| 356 |
+
"query": args.query,
|
| 357 |
+
"timestamp": time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime()),
|
| 358 |
+
"results": results,
|
| 359 |
+
"metadata": {
|
| 360 |
+
"total_results": len(results),
|
| 361 |
+
"collection": collection_name,
|
| 362 |
+
"vector_size": coll_info['vector_size'],
|
| 363 |
+
"points_count": coll_info['points_count']
|
| 364 |
+
}
|
| 365 |
+
}
|
| 366 |
+
|
| 367 |
+
if metadata_validation:
|
| 368 |
+
output["metadata_validation"] = metadata_validation
|
| 369 |
+
|
| 370 |
+
# Output JSON
|
| 371 |
+
json_output = json.dumps(output, indent=2)
|
| 372 |
+
if args.output:
|
| 373 |
+
with open(args.output, 'w') as f:
|
| 374 |
+
f.write(json_output)
|
| 375 |
+
logger.info(f"Results written to {args.output}")
|
| 376 |
+
else:
|
| 377 |
+
print(json_output)
|
| 378 |
+
|
| 379 |
+
logger.info("=== Retrieval Pipeline Completed Successfully ===")
|
| 380 |
+
return 0
|
| 381 |
+
|
| 382 |
+
except ValueError as ve:
|
| 383 |
+
logger.error(f"Validation error: {ve}")
|
| 384 |
+
print(f"ERROR: {ve}", file=sys.stderr)
|
| 385 |
+
return 2
|
| 386 |
+
except ConfigurationError as ce:
|
| 387 |
+
logger.error(f"Configuration error: {ce}")
|
| 388 |
+
print(f"ERROR: {ce}", file=sys.stderr)
|
| 389 |
+
return 1
|
| 390 |
+
except CollectionNotFoundError as cnfe:
|
| 391 |
+
logger.error(f"Collection error: {cnfe}")
|
| 392 |
+
print(f"ERROR: {cnfe}", file=sys.stderr)
|
| 393 |
+
return 1
|
| 394 |
+
except DimensionMismatchError as dme:
|
| 395 |
+
logger.error(f"Dimension error: {dme}")
|
| 396 |
+
print(f"ERROR: {dme}", file=sys.stderr)
|
| 397 |
+
return 1
|
| 398 |
+
except APIError as api_err:
|
| 399 |
+
logger.error(f"API error: {api_err}")
|
| 400 |
+
print(f"ERROR: {api_err}", file=sys.stderr)
|
| 401 |
+
return 1
|
| 402 |
+
except Exception as e:
|
| 403 |
+
logger.exception(f"Unexpected error: {e}")
|
| 404 |
+
print(f"ERROR: Unexpected error: {e}", file=sys.stderr)
|
| 405 |
+
return 1
|
| 406 |
+
|
| 407 |
+
if __name__ == "__main__":
|
| 408 |
+
sys.exit(main())
|
sitemap_urls.txt
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
https://humanoid-ai-robotics-book-1.vercel.app/blog
|
| 2 |
+
https://humanoid-ai-robotics-book-1.vercel.app/blog/archive
|
| 3 |
+
https://humanoid-ai-robotics-book-1.vercel.app/blog/authors
|
| 4 |
+
https://humanoid-ai-robotics-book-1.vercel.app/blog/authors/all-sebastien-lorber-articles
|
| 5 |
+
https://humanoid-ai-robotics-book-1.vercel.app/blog/authors/yangshun
|
| 6 |
+
https://humanoid-ai-robotics-book-1.vercel.app/blog/first-blog-post
|
| 7 |
+
https://humanoid-ai-robotics-book-1.vercel.app/blog/long-blog-post
|
| 8 |
+
https://humanoid-ai-robotics-book-1.vercel.app/blog/mdx-blog-post
|
| 9 |
+
https://humanoid-ai-robotics-book-1.vercel.app/blog/tags
|
| 10 |
+
https://humanoid-ai-robotics-book-1.vercel.app/blog/tags/docusaurus
|
| 11 |
+
https://humanoid-ai-robotics-book-1.vercel.app/blog/tags/facebook
|
| 12 |
+
https://humanoid-ai-robotics-book-1.vercel.app/blog/tags/hello
|
| 13 |
+
https://humanoid-ai-robotics-book-1.vercel.app/blog/tags/hola
|
| 14 |
+
https://humanoid-ai-robotics-book-1.vercel.app/blog/welcome
|
| 15 |
+
https://humanoid-ai-robotics-book-1.vercel.app/markdown-page
|
| 16 |
+
https://humanoid-ai-robotics-book-1.vercel.app/docs/category/tutorial---basics
|
| 17 |
+
https://humanoid-ai-robotics-book-1.vercel.app/docs/category/tutorial---extras
|
| 18 |
+
https://humanoid-ai-robotics-book-1.vercel.app/docs/intro
|
| 19 |
+
https://humanoid-ai-robotics-book-1.vercel.app/docs/module-1/intro-to-ros2
|
| 20 |
+
https://humanoid-ai-robotics-book-1.vercel.app/docs/module-1/ros2-communication-model
|
| 21 |
+
https://humanoid-ai-robotics-book-1.vercel.app/docs/module-1/urdf-humanoids
|
| 22 |
+
https://humanoid-ai-robotics-book-1.vercel.app/docs/module-2/gazebo-physics-simulation
|
| 23 |
+
https://humanoid-ai-robotics-book-1.vercel.app/docs/module-2/intro-to-digital-twins
|
| 24 |
+
https://humanoid-ai-robotics-book-1.vercel.app/docs/module-2/unity-interaction-sensors
|
| 25 |
+
https://humanoid-ai-robotics-book-1.vercel.app/docs/module-3/intro-to-ai-robot-brain
|
| 26 |
+
https://humanoid-ai-robotics-book-1.vercel.app/docs/module-3/navigation-intelligence
|
| 27 |
+
https://humanoid-ai-robotics-book-1.vercel.app/docs/module-3/perception-simulation-isaac-sim
|
| 28 |
+
https://humanoid-ai-robotics-book-1.vercel.app/docs/module-4/cognitive-planning-llms
|
| 29 |
+
https://humanoid-ai-robotics-book-1.vercel.app/docs/module-4/documentation-standards
|
| 30 |
+
https://humanoid-ai-robotics-book-1.vercel.app/docs/module-4/intro-to-vla
|
| 31 |
+
https://humanoid-ai-robotics-book-1.vercel.app/docs/module-4/voice-to-action-whisper
|
| 32 |
+
https://humanoid-ai-robotics-book-1.vercel.app/docs/tutorial-basics/congratulations
|
| 33 |
+
https://humanoid-ai-robotics-book-1.vercel.app/docs/tutorial-basics/create-a-blog-post
|
| 34 |
+
https://humanoid-ai-robotics-book-1.vercel.app/docs/tutorial-basics/create-a-document
|
| 35 |
+
https://humanoid-ai-robotics-book-1.vercel.app/docs/tutorial-basics/create-a-page
|
| 36 |
+
https://humanoid-ai-robotics-book-1.vercel.app/docs/tutorial-basics/deploy-your-site
|
| 37 |
+
https://humanoid-ai-robotics-book-1.vercel.app/docs/tutorial-basics/markdown-features
|
| 38 |
+
https://humanoid-ai-robotics-book-1.vercel.app/docs/tutorial-extras/manage-docs-versions
|
| 39 |
+
https://humanoid-ai-robotics-book-1.vercel.app/docs/tutorial-extras/translate-your-site
|
| 40 |
+
https://humanoid-ai-robotics-book-1.vercel.app/
|
test_local.py
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Local test that reads sample HTML file and processes it through the pipeline.
|
| 3 |
+
This tests the full flow without relying on external URLs.
|
| 4 |
+
"""
|
| 5 |
+
import sys
|
| 6 |
+
import os
|
| 7 |
+
from pathlib import Path
|
| 8 |
+
|
| 9 |
+
# Add backend to path
|
| 10 |
+
sys.path.insert(0, str(Path(__file__).parent))
|
| 11 |
+
|
| 12 |
+
import config
|
| 13 |
+
import utils
|
| 14 |
+
from logging_config import setup_logging
|
| 15 |
+
from main import (
|
| 16 |
+
extract_text, chunk_text, generate_embeddings, ensure_collection,
|
| 17 |
+
upsert_chunks, run_validation
|
| 18 |
+
)
|
| 19 |
+
import cohere
|
| 20 |
+
from qdrant_client import QdrantClient
|
| 21 |
+
|
| 22 |
+
logger = setup_logging()
|
| 23 |
+
|
| 24 |
+
def test_with_fixture():
|
| 25 |
+
"""Test pipeline using the sample_page.html fixture."""
|
| 26 |
+
import cohere as cohere_module
|
| 27 |
+
|
| 28 |
+
# Load config
|
| 29 |
+
cfg = config.get_config()
|
| 30 |
+
config.validate_config(cfg)
|
| 31 |
+
|
| 32 |
+
# Read fixture HTML
|
| 33 |
+
fixture_path = Path(__file__).parent / 'tests' / 'fixtures' / 'sample_page.html'
|
| 34 |
+
with open(fixture_path, 'r') as f:
|
| 35 |
+
html = f.read()
|
| 36 |
+
|
| 37 |
+
url = "https://example.com/sample-page"
|
| 38 |
+
|
| 39 |
+
# Extract text
|
| 40 |
+
text = extract_text(html, url)
|
| 41 |
+
logger.info(f"Extracted {len(text)} characters from fixture")
|
| 42 |
+
print(f"Text preview: {text[:200]}...")
|
| 43 |
+
|
| 44 |
+
# Chunk text
|
| 45 |
+
chunks_data = chunk_text(text, chunk_size=500, overlap=50)
|
| 46 |
+
logger.info(f"Chunked into {len(chunks_data)} segments")
|
| 47 |
+
print(f"First chunk: {chunks_data[0]['text'][:100]}...")
|
| 48 |
+
|
| 49 |
+
# Generate embeddings - test with Cohere directly to see response structure
|
| 50 |
+
cohere_client = cohere.ClientV2(api_key=cfg['cohere_api_key'])
|
| 51 |
+
texts = [chunk['text'] for chunk in chunks_data]
|
| 52 |
+
|
| 53 |
+
# Simple test: get one embedding to understand structure
|
| 54 |
+
test_response = cohere_client.embed(
|
| 55 |
+
texts=[texts[0]],
|
| 56 |
+
model="embed-english-v3.0",
|
| 57 |
+
input_type="search_document"
|
| 58 |
+
)
|
| 59 |
+
print(f"\nCohere response type: {type(test_response)}")
|
| 60 |
+
print(f"Embeddings attribute: {type(test_response.embeddings)}")
|
| 61 |
+
print(f"Embeddings.float_ attribute: {type(test_response.embeddings.float_)}")
|
| 62 |
+
|
| 63 |
+
# Access embeddings directly via .float_ attribute
|
| 64 |
+
embeddings_float = test_response.embeddings.float_
|
| 65 |
+
if embeddings_float:
|
| 66 |
+
first_emb = embeddings_float[0]
|
| 67 |
+
print(f"First embedding type: {type(first_emb)}")
|
| 68 |
+
print(f"First embedding dimension: {len(first_emb)}")
|
| 69 |
+
print(f"First embedding sample (first 5 values): {first_emb[:5]}")
|
| 70 |
+
|
| 71 |
+
# Now generate all using the proper extraction method
|
| 72 |
+
embeddings = generate_embeddings(texts, cohere_client, batch_size=96)
|
| 73 |
+
logger.info(f"Generated {len(embeddings)} embeddings")
|
| 74 |
+
print(f"Embedding dimension: {len(embeddings[0])}")
|
| 75 |
+
|
| 76 |
+
# Initialize Qdrant and ensure collection
|
| 77 |
+
qdrant_client = QdrantClient(
|
| 78 |
+
url=cfg['qdrant_url'],
|
| 79 |
+
api_key=cfg['qdrant_api_key']
|
| 80 |
+
)
|
| 81 |
+
collection = cfg['qdrant_collection']
|
| 82 |
+
ensure_collection(qdrant_client, collection)
|
| 83 |
+
|
| 84 |
+
# Prepare records
|
| 85 |
+
records = []
|
| 86 |
+
for i, (chunk, embedding) in enumerate(zip(chunks_data, embeddings)):
|
| 87 |
+
record = {
|
| 88 |
+
'url': url,
|
| 89 |
+
'title': url,
|
| 90 |
+
'section': '',
|
| 91 |
+
'chunk_index': i,
|
| 92 |
+
'text': chunk['text'],
|
| 93 |
+
'embedding': embedding
|
| 94 |
+
}
|
| 95 |
+
records.append(record)
|
| 96 |
+
|
| 97 |
+
# Upsert
|
| 98 |
+
stats = upsert_chunks(qdrant_client, collection, records, utils.deterministic_id)
|
| 99 |
+
logger.info(f"Upsert stats: {stats}")
|
| 100 |
+
print(f"Upserted {stats['total']} points to Qdrant")
|
| 101 |
+
|
| 102 |
+
# Verify
|
| 103 |
+
info = qdrant_client.get_collection(collection)
|
| 104 |
+
print(f"Collection now has {info.points_count} points")
|
| 105 |
+
|
| 106 |
+
# Run validation
|
| 107 |
+
print("\n--- Running Validation ---")
|
| 108 |
+
run_validation(qdrant_client, collection, sample_size=min(10, info.points_count))
|
| 109 |
+
|
| 110 |
+
print("\n✅ Local test complete!")
|
| 111 |
+
return True
|
| 112 |
+
|
| 113 |
+
if __name__ == "__main__":
|
| 114 |
+
try:
|
| 115 |
+
test_with_fixture()
|
| 116 |
+
except Exception as e:
|
| 117 |
+
logger.error(f"Test failed: {e}", exc_info=True)
|
| 118 |
+
sys.exit(1)
|
test_run.log
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
INFO: HTTP Request: GET https://d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io:6333 "HTTP/1.1 200 OK"
|
| 2 |
+
INFO: HTTP Request: GET https://d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io:6333/collections "HTTP/1.1 200 OK"
|
| 3 |
+
INFO: Collection 'book_embeddings' already exists
|
| 4 |
+
INFO: Starting ingestion: 3 URLs
|
| 5 |
+
INFO: Chunk size: 500, overlap: 50
|
| 6 |
+
INFO: Fetching https://bookshelf.math.buffalo.edu/bookshelf-free-books-direction.html...
|
| 7 |
+
ERROR: Failed to fetch https://bookshelf.math.buffalo.edu/bookshelf-free-books-direction.html after 5 attempts: [Errno -2] Name or service not known
|
| 8 |
+
ERROR: Failed to process https://bookshelf.math.buffalo.edu/bookshelf-free-books-direction.html: [Errno -2] Name or service not known
|
| 9 |
+
INFO: Fetching https://en.wikipedia.org/wiki/Book...
|
| 10 |
+
INFO: HTTP Request: GET https://en.wikipedia.org/wiki/Book "HTTP/1.1 403 Forbidden"
|
| 11 |
+
INFO: HTTP Request: GET https://en.wikipedia.org/wiki/Book "HTTP/1.1 403 Forbidden"
|
| 12 |
+
INFO: HTTP Request: GET https://en.wikipedia.org/wiki/Book "HTTP/1.1 403 Forbidden"
|
| 13 |
+
INFO: HTTP Request: GET https://en.wikipedia.org/wiki/Book "HTTP/1.1 403 Forbidden"
|
| 14 |
+
INFO: HTTP Request: GET https://en.wikipedia.org/wiki/Book "HTTP/1.1 403 Forbidden"
|
| 15 |
+
ERROR: Failed to fetch https://en.wikipedia.org/wiki/Book after 5 attempts: Client error '403 Forbidden' for url 'https://en.wikipedia.org/wiki/Book'
|
| 16 |
+
For more information check: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/403
|
| 17 |
+
ERROR: Failed to process https://en.wikipedia.org/wiki/Book: Client error '403 Forbidden' for url 'https://en.wikipedia.org/wiki/Book'
|
| 18 |
+
For more information check: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/403
|
| 19 |
+
INFO: Fetching https://www.gutenberg.org/files/1342/1342-h/1342-h.htm...
|
| 20 |
+
INFO: HTTP Request: GET https://www.gutenberg.org/files/1342/1342-h/1342-h.htm "HTTP/1.1 200 OK"
|
| 21 |
+
INFO: Extracted 717156 characters from https://www.gutenberg.org/files/1342/1342-h/1342-h.htm, chunked into 1435 segments
|
| 22 |
+
INFO: HTTP Request: POST https://api.cohere.com/v2/embed "HTTP/1.1 400 Bad Request"
|
| 23 |
+
ERROR: Failed to generate embeddings for batch starting at index 0: headers: {'access-control-expose-headers': 'X-Debug-Trace-ID', 'cache-control': 'no-cache, no-store, no-transform, must-revalidate, private, max-age=0', 'content-encoding': 'gzip', 'content-type': 'application/json', 'expires': 'Thu, 01 Jan 1970 00:00:00 GMT', 'pragma': 'no-cache', 'vary': 'Origin,Accept-Encoding', 'x-accel-expires': '0', 'x-debug-trace-id': '1da9e24a767597a154eaa71df36dcb52', 'x-endpoint-monthly-call-limit': '1000', 'x-trial-endpoint-call-limit': '100', 'x-trial-endpoint-call-remaining': '99', 'date': 'Mon, 16 Feb 2026 20:38:33 GMT', 'x-envoy-upstream-service-time': '5', 'server': 'envoy', 'via': '1.1 google', 'alt-svc': 'h3=":443"; ma=2592000,h3-29=":443"; ma=2592000', 'transfer-encoding': 'chunked'}, status_code: 400, body: {'id': 'cd20a5e4-1efc-44b5-a9f6-43d7a24004ce', 'message': 'invalid request: total number of texts must be at most 96 - received 100'}
|
| 24 |
+
ERROR: Failed to process https://www.gutenberg.org/files/1342/1342-h/1342-h.htm: headers: {'access-control-expose-headers': 'X-Debug-Trace-ID', 'cache-control': 'no-cache, no-store, no-transform, must-revalidate, private, max-age=0', 'content-encoding': 'gzip', 'content-type': 'application/json', 'expires': 'Thu, 01 Jan 1970 00:00:00 GMT', 'pragma': 'no-cache', 'vary': 'Origin,Accept-Encoding', 'x-accel-expires': '0', 'x-debug-trace-id': '1da9e24a767597a154eaa71df36dcb52', 'x-endpoint-monthly-call-limit': '1000', 'x-trial-endpoint-call-limit': '100', 'x-trial-endpoint-call-remaining': '99', 'date': 'Mon, 16 Feb 2026 20:38:33 GMT', 'x-envoy-upstream-service-time': '5', 'server': 'envoy', 'via': '1.1 google', 'alt-svc': 'h3=":443"; ma=2592000,h3-29=":443"; ma=2592000', 'transfer-encoding': 'chunked'}, status_code: 400, body: {'id': 'cd20a5e4-1efc-44b5-a9f6-43d7a24004ce', 'message': 'invalid request: total number of texts must be at most 96 - received 100'}
|
| 25 |
+
INFO: ==================================================
|
| 26 |
+
INFO: Ingestion complete!
|
| 27 |
+
INFO: Total pages processed: 0
|
| 28 |
+
INFO: Total chunks stored: 0
|
| 29 |
+
WARNING: Failed URLs (3): https://bookshelf.math.buffalo.edu/bookshelf-free-books-direction.html, https://en.wikipedia.org/wiki/Book, https://www.gutenberg.org/files/1342/1342-h/1342-h.htm
|
| 30 |
+
INFO: ==================================================
|
| 31 |
+
INFO: HTTP Request: GET https://d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io:6333/collections/book_embeddings "HTTP/1.1 200 OK"
|
| 32 |
+
INFO: Qdrant collection 'book_embeddings' now has 0 points
|
test_simple.log
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
INFO: HTTP Request: GET https://d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io:6333 "HTTP/1.1 200 OK"
|
| 2 |
+
INFO: HTTP Request: GET https://d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io:6333/collections "HTTP/1.1 200 OK"
|
| 3 |
+
INFO: Collection 'book_embeddings' already exists
|
| 4 |
+
INFO: Starting ingestion: 1 URLs
|
| 5 |
+
INFO: Chunk size: 200, overlap: 20
|
| 6 |
+
INFO: Fetching http://example.com...
|
| 7 |
+
INFO: HTTP Request: GET http://example.com "HTTP/1.1 200 OK"
|
| 8 |
+
INFO: Extracted 142 characters from http://example.com, chunked into 1 segments
|
| 9 |
+
INFO: HTTP Request: POST https://api.cohere.com/v2/embed "HTTP/1.1 200 OK"
|
| 10 |
+
ERROR: Failed to process http://example.com: Unexpected embedding dimension: 2
|
| 11 |
+
INFO: ==================================================
|
| 12 |
+
INFO: Ingestion complete!
|
| 13 |
+
INFO: Total pages processed: 0
|
| 14 |
+
INFO: Total chunks stored: 0
|
| 15 |
+
WARNING: Failed URLs (1): http://example.com
|
| 16 |
+
INFO: ==================================================
|
| 17 |
+
INFO: HTTP Request: GET https://d27e55fe-c28d-4275-81d7-7eff807c14a5.europe-west3-0.gcp.cloud.qdrant.io:6333/collections/book_embeddings "HTTP/1.1 200 OK"
|
| 18 |
+
INFO: Qdrant collection 'book_embeddings' now has 0 points
|
test_urls.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
https://bookshelf.math.buffalo.edu/bookshelf-free-books-direction.html
|
| 2 |
+
https://en.wikipedia.org/wiki/Book
|
| 3 |
+
https://www.gutenberg.org/files/1342/1342-h/1342-h.htm
|
tests/fixtures/sample_page.html
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html>
|
| 3 |
+
<head>
|
| 4 |
+
<title>Sample Book Page - Introduction</title>
|
| 5 |
+
</head>
|
| 6 |
+
<body>
|
| 7 |
+
<nav>Navigation menu here</nav>
|
| 8 |
+
<header>Book Title: Example Book</header>
|
| 9 |
+
|
| 10 |
+
<h1>Chapter 1: Introduction</h1>
|
| 11 |
+
|
| 12 |
+
<p>This is the first paragraph of the introduction. It provides an overview of the topic.</p>
|
| 13 |
+
|
| 14 |
+
<p>The second paragraph discusses the background and context. It contains several sentences that should be chunked appropriately when the text is processed.</p>
|
| 15 |
+
|
| 16 |
+
<h2>1.1 Background</h2>
|
| 17 |
+
|
| 18 |
+
<p>This is a subsection with its own content. It provides more detailed information about the background.</p>
|
| 19 |
+
|
| 20 |
+
<p>Another paragraph in the background section. This helps test the chunking algorithm with multiple paragraphs and sections.</p>
|
| 21 |
+
|
| 22 |
+
<h2>1.2 Objectives</h2>
|
| 23 |
+
|
| 24 |
+
<p>This subsection covers the objectives. It should be extracted with its section identifier.</p>
|
| 25 |
+
|
| 26 |
+
<p>Final paragraph of this sample page. It ensures we have enough text to create multiple chunks when using a chunk size of 1000 characters.</p>
|
| 27 |
+
|
| 28 |
+
<footer>Footer content like copyright info should be removed.</footer>
|
| 29 |
+
</body>
|
| 30 |
+
</html>
|
utils.py
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Utility functions for the ingestion pipeline.
|
| 3 |
+
"""
|
| 4 |
+
import hashlib
|
| 5 |
+
import time
|
| 6 |
+
import random
|
| 7 |
+
from typing import Callable, Any
|
| 8 |
+
|
| 9 |
+
def deterministic_id(url: str, chunk_index: int) -> str:
|
| 10 |
+
"""
|
| 11 |
+
Generate deterministic point ID for Qdrant.
|
| 12 |
+
Uses SHA256 hash of "url:chunk_index" and formats as a valid UUID.
|
| 13 |
+
Qdrant accepts UUID v4 format or unsigned integers.
|
| 14 |
+
"""
|
| 15 |
+
import uuid
|
| 16 |
+
key = f"{url}:{chunk_index}"
|
| 17 |
+
hash_bytes = hashlib.sha256(key.encode()).digest()
|
| 18 |
+
# Convert to UUID v4 format (using random variant) but deterministic from hash
|
| 19 |
+
# Use first 16 bytes of SHA256 to create a UUID
|
| 20 |
+
uuid_bytes = hash_bytes[:16]
|
| 21 |
+
# Set version to 4 (random) and variant to RFC 4122
|
| 22 |
+
uuid_bytes = uuid_bytes[:6] + bytes([(uuid_bytes[6] & 0x0f) | 0x40]) + bytes([uuid_bytes[7] & 0x3f | 0x80]) + uuid_bytes[8:]
|
| 23 |
+
return str(uuid.UUID(bytes=uuid_bytes))
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def verify_deterministic_id(url: str, chunk_index: int, expected_id: str = None) -> str:
|
| 27 |
+
"""
|
| 28 |
+
Verify deterministic ID generation and detect collisions.
|
| 29 |
+
Returns the generated ID. If expected_id is provided and differs, logs warning.
|
| 30 |
+
"""
|
| 31 |
+
generated_id = deterministic_id(url, chunk_index)
|
| 32 |
+
if expected_id and generated_id != expected_id:
|
| 33 |
+
logger.warning(f"ID collision detected for {url}:{chunk_index}. Expected {expected_id}, got {generated_id}")
|
| 34 |
+
return generated_id
|
| 35 |
+
|
| 36 |
+
def retry_with_backoff(
|
| 37 |
+
func: Callable,
|
| 38 |
+
max_retries: int = 5,
|
| 39 |
+
base_delay: float = 1.0,
|
| 40 |
+
max_delay: float = 30.0,
|
| 41 |
+
jitter: float = 0.1
|
| 42 |
+
) -> Any:
|
| 43 |
+
"""
|
| 44 |
+
Retry a function with exponential backoff and jitter.
|
| 45 |
+
Suitable for API calls (Cohere, Qdrant, HTTP).
|
| 46 |
+
"""
|
| 47 |
+
for attempt in range(max_retries):
|
| 48 |
+
try:
|
| 49 |
+
return func()
|
| 50 |
+
except Exception as e:
|
| 51 |
+
if attempt == max_retries - 1:
|
| 52 |
+
raise
|
| 53 |
+
delay = min(base_delay * (2 ** attempt) + random.uniform(-jitter, jitter), max_delay)
|
| 54 |
+
time.sleep(delay)
|
validate.py
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
Simple validation script to test the ingestion pipeline components.
|
| 4 |
+
"""
|
| 5 |
+
import sys
|
| 6 |
+
import os
|
| 7 |
+
sys.path.insert(0, '.')
|
| 8 |
+
|
| 9 |
+
def test_imports():
|
| 10 |
+
"""Test all imports work."""
|
| 11 |
+
import config
|
| 12 |
+
import utils
|
| 13 |
+
import logging_config
|
| 14 |
+
print("✓ All imports successful")
|
| 15 |
+
|
| 16 |
+
def test_deterministic_id():
|
| 17 |
+
"""Test deterministic ID generation."""
|
| 18 |
+
from utils import deterministic_id
|
| 19 |
+
id1 = deterministic_id("https://example.com/page", 0)
|
| 20 |
+
id2 = deterministic_id("https://example.com/page", 0)
|
| 21 |
+
id3 = deterministic_id("https://example.com/page", 1)
|
| 22 |
+
assert id1 == id2, "Same input should produce same ID"
|
| 23 |
+
assert id1 != id3, "Different chunk_index should produce different ID"
|
| 24 |
+
assert len(id1) == 64, "SHA256 hex should be 64 characters"
|
| 25 |
+
print("✓ Deterministic ID generation works")
|
| 26 |
+
|
| 27 |
+
def test_chunking():
|
| 28 |
+
"""Test text chunking logic."""
|
| 29 |
+
from main import chunk_text
|
| 30 |
+
text = "A" * 2500 # 2500 characters
|
| 31 |
+
chunks = chunk_text(text, chunk_size=1000, overlap=100)
|
| 32 |
+
assert len(chunks) > 1, "Long text should produce multiple chunks"
|
| 33 |
+
assert all('text' in c and 'char_start' in c and 'char_end' in c for c in chunks), "Chunks have required fields"
|
| 34 |
+
# Check overlap
|
| 35 |
+
for i in range(1, len(chunks)):
|
| 36 |
+
gap = chunks[i]['char_start'] - chunks[i-1]['char_end']
|
| 37 |
+
assert gap <= 100, f"Overlap should be <=100, got {gap}"
|
| 38 |
+
print(f"✓ Chunking works: {len(chunks)} chunks from 2500 chars")
|
| 39 |
+
|
| 40 |
+
def test_config():
|
| 41 |
+
"""Test config loading."""
|
| 42 |
+
import config as cfg_module
|
| 43 |
+
try:
|
| 44 |
+
cfg = cfg_module.get_config()
|
| 45 |
+
cfg_module.validate_config(cfg)
|
| 46 |
+
except ValueError as e:
|
| 47 |
+
if "Missing required environment variables" in str(e):
|
| 48 |
+
print("✓ Config validation works (expected: missing env vars when .env not set)")
|
| 49 |
+
else:
|
| 50 |
+
raise
|
| 51 |
+
|
| 52 |
+
if __name__ == "__main__":
|
| 53 |
+
print("Running validation tests...")
|
| 54 |
+
test_imports()
|
| 55 |
+
test_deterministic_id()
|
| 56 |
+
test_chunking()
|
| 57 |
+
test_config()
|
| 58 |
+
print("\n✓ All validation tests passed!")
|
| 59 |
+
print("\nTo test full pipeline, set COHERE_API_KEY and QDRANT credentials in .env and run:")
|
| 60 |
+
print(" python backend/main.py --urls https://example.com")
|