Skip to content

fix: correct reranker score display and add URL content fetching - #11

Merged
suneel944 merged 17 commits into
masterfrom
feature/rag-calibration-and-metrics-refactor
Nov 23, 2025
Merged

suneel944 merged 17 commits into
masterfrom
feature/rag-calibration-and-metrics-refactor

Conversation

@suneel944

Copy link
Copy Markdown
Owner

Description

This PR fixes the reranker score display issue in the dashboard and adds URL content fetching to improve reranker accuracy for real chat interactions. The reranker score was incorrectly displaying as a percentage (e.g., 61.36) instead of a 0-1 decimal (e.g., 0.61). Additionally, the framework now fetches content from URLs to provide richer context for reranker scoring, significantly improving accuracy when sources are URLs rather than document text.

Type of Change

  • 🐛 Bug fix (non-breaking change which fixes an issue)
  • ✨ New feature (non-breaking change which adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 📝 Documentation update
  • ⚡ Performance improvement
  • ♻️ Code refactoring (no functional changes)
  • 🧪 Test improvements
  • 🔧 Build/config changes

Changes Made

  • Fixed reranker score display: Removed reranker_score from percentage_metrics list in collectors.py and data_store.py to prevent incorrect conversion to 0-100 percentage range
  • Added URL content fetching: New url_fetcher.py utility with parallel fetching, retry logic, and support for HTML, PDF, JSON, and plain text content
  • Improved reranker accuracy: Integrated URL content fetching into RAG metrics calculator to use actual document content instead of URLs for scoring
  • Fixed RAG context storage: Updated rag_tester.py to prioritize test-provided retrieved_docs over extracted URLs
  • Fixed reranker model loading: Corrected _load_model() check to properly detect transformers-based models
  • Source extraction: Enhanced chat_page.py to extract sources from both /api/chat/completed and async polling endpoints
  • Query retrieval: Fixed query extraction from RAG context for reranker score calculation
  • Removed debug logs: Cleaned up all console.log debug statements from dashboard JavaScript
  • Updated documentation: Clarified reranker score display format and documented URL fetching feature

Testing

Test Coverage

  • Unit tests added/updated
  • Integration tests added/updated
  • E2E tests added/updated
  • UI tests added/updated (if applicable)
  • Security tests added/updated (if applicable)
  • Manual testing performed

Test Results

# RAG metrics tests pass with URL fetching enabled
pytest tests/e2e/ai/test_rag_metrics.py -v
# Results: All RAG metric tests pass, reranker_score now displays correctly as 0-1 decimal

Manual Testing:

  • Verified reranker score displays as 0.61 (not 61.36) in dashboard
  • Confirmed URL content fetching works for HTML, PDF, and JSON content
  • Tested parallel fetching with multiple URLs
  • Verified retry logic handles failed requests gracefully
  • Confirmed RAG context properly stores test data and extracted sources

Code Quality

Pre-Submission Checks

  • make check passes (linting + type checking)
  • make format has been run
  • make test-all passes
  • ✅ All pre-commit hooks pass

Code Standards

  • Code follows PEP 8 style guidelines
  • Type hints added/updated for all functions
  • Docstrings added/updated (Google style)
  • No new warnings or errors generated
  • Imports are organized correctly
  • Self-review completed

Documentation

  • Code comments added for complex logic
  • README.md updated (if needed)
  • API documentation updated (if needed)
  • Architecture Decision Record (ADR) created (if significant change)

Related Issues

Fixes reranker score display issue where values > 1 were appearing (e.g., 61.36 instead of 0.61)

Additional Context

Screenshots/Demo

Before: Reranker score displayed as 61.36 (incorrect percentage)
After: Reranker score displays as 0.61 (correct 0-1 decimal)

Breaking Changes

None. This is a bug fix and feature addition that maintains backward compatibility.

Performance Impact

  • URL Content Fetching: Uses parallel fetching with configurable worker pool (default: 5 workers) for improved performance
  • Retry Logic: Exponential backoff (1s, 2s, 4s) prevents overwhelming servers while ensuring reliability
  • Content Length Limits: Configurable max content length (default: 10,000 chars) prevents memory issues

Security Considerations

  • URL fetching includes timeout protection (default: 10 seconds) to prevent hanging requests
  • Content length limits prevent DoS attacks via large responses
  • Error handling gracefully handles malicious or malformed URLs

Configuration

New environment variables added:

# Enable/disable URL content fetching (default: true)
RAG_FETCH_URL_CONTENT=true

# Timeout per URL in seconds (default: 10)
RAG_URL_FETCH_TIMEOUT=10

# Maximum content length per URL in characters (default: 10000)
RAG_URL_MAX_CONTENT_LENGTH=10000

# Maximum retry attempts per URL if fetch fails (default: 3)
RAG_URL_MAX_RETRIES=3

# Delay between retries in seconds, uses exponential backoff (default: 1.0)
RAG_URL_RETRY_DELAY=1.0

# Maximum parallel workers for URL fetching (default: 5)
RAG_URL_MAX_WORKERS=5

Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have updated the documentation accordingly
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published
  • I have checked that my changes don't break existing functionality

…warning

- Change self.model_fields to Settings.model_fields
- Fixes PydanticDeprecatedSince211 warning
- Add extract_sources_from_message() to parse sources from API responses
- Extract from 'sources' field if available
- Fallback to parsing markdown references ([^1], [^2], etc.) from content
- Store extracted sources as retrieved_docs for RAG metrics calculation
- Fixes reranker_score and other RAG metrics showing 0 when sources are in markdown format
- Add source extraction to /api/chat/completed endpoint handler
- Ensures sources are extracted from both async polling and direct response paths
- Fixes missing source extraction when response comes via completed endpoint
- Store user query when sending message in chat_page
- Pass query to RAG context when storing retrieved docs
- Retrieve query from RAG context in collector if not in validation_data
- Fixes reranker_score showing 0 when query is missing
…tracted URLs

- Update _store_rag_context to merge instead of replace
- Preserve test data's retrieved_docs if already set
- Prevents extracted URLs from overwriting test context
- Fixes context_relevance showing 0 when test data is available
- Fix _load_model() to return True when model/tokenizer are available (not just pipeline)
- Update BGE reranker format to use tokenizer's sep_token instead of literal [SEP]
- Add debug logging for reranker scoring
- Fixes reranker_score showing 0.0 when reranker is actually loaded and working
- Add url_fetcher utility with parallel fetching, retry logic, and content type support
- Integrate URL content fetching into RAG metrics calculator
- Add configuration settings for URL fetching (timeout, max length, retries, workers)
- Update .env.example and README.md with new configuration options
- Remove reranker_score from percentage_metrics list to prevent incorrect conversion
- Ensure reranker_score is displayed as 0-1 decimal instead of 0-100 percentage
- Fix reranker score normalization to always return 0-1 range
- Fix RAG context storage to prioritize test-provided retrieved_docs
- Remove all console.log debug statements from dashboard.js
- Update cache-busting version to v=8 to force browser reload
- Clean up whitespace and styling issues in dashboard UI
- Clarify that reranker_score is displayed as 0-1 decimal, not percentage
- Document URL content fetching feature and configuration options
- Update RAG calibration usage documentation with URL fetching details
Comment thread src/utils/url_fetcher.py Fixed
- Update regex patterns to match closing tags with whitespace (e.g., </script >)
- Fixes CodeQL security alert for bad HTML filtering regexp
- Use \s* to allow optional whitespace before closing angle bracket
Comment thread src/utils/url_fetcher.py Fixed
Comment thread src/utils/url_fetcher.py Fixed
- Change from \s* to [^>]* to match any characters in closing tags
- Fixes CodeQL alert for edge cases like </script\t\n bar>
- Handles whitespace, text, and any other characters before closing bracket
- More robust against malformed HTML injection attempts
…ands

- Reorganize help section into logical categories (Setup, Testing, Code Quality, etc.)
- Add missing targets: install-hooks, test-unit-cov, test-integration, test-property, format-check, security-scan, dashboard-custom, metrics-raw
- Update README Development section to match new Makefile organization
- Add reference to 'make help' for complete command list
- Reorganize commands into logical categories matching Makefile help
- Add missing commands: install-hooks, test-unit-cov, test-integration, test-property, format-check, security-scan, docs, docs-serve, dashboard-custom, metrics-raw
- Add reference to 'make help' for complete command list
- Make VENV_BIN absolute using $(abspath) to fix path resolution after cd
- Update docs target to run sphinx from repo root without cd
- Update docs-serve target to use -d flag instead of cd
- Reorganize .PHONY targets for better maintainability
- Clean up docs/conf.py imports and structure

Fixes issue where 'make docs' failed with 'No such file or directory' errors
when trying to use relative venv paths after changing directories.
@suneel944
suneel944 merged commit 1ad6a43 into master Nov 23, 2025
9 checks passed
@suneel944
suneel944 deleted the feature/rag-calibration-and-metrics-refactor branch November 23, 2025 03:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants