function full_reading_example
Demonstrates the full reading mode of a RAG (Retrieval-Augmented Generation) system by processing all documents to answer a comprehensive query about key findings.
/tf/active/vicechatdev/docchat/example_usage.py
103 - 132
simple
Purpose
This function serves as a demonstration/example of how to use the DocChatRAG system in 'full_reading' mode, which processes all available documents rather than using selective retrieval. It showcases progress tracking, result formatting, and metadata extraction. This mode is useful when comprehensive analysis across all documents is needed, though it takes longer (1-5 minutes) than standard retrieval modes.
Source Code
def full_reading_example():
"""Example: Use Full Reading mode"""
print("\n=== Full Reading Mode Example ===\n")
rag = DocChatRAG()
query = "What are all the key findings across all documents?"
print(f"Query: {query}\n")
print("Processing all documents (this may take 1-5 minutes)...\n")
# Progress callback
def show_progress(message):
print(f" → {message}")
result = rag.chat(
query=query,
mode="full_reading",
progress_callback=show_progress
)
print("\nResponse:")
print("-" * 80)
print(result['response'])
print("-" * 80)
print(f"\nMetadata:")
print(f" Mode: {result['mode']}")
print(f" Total documents: {result.get('num_documents', 0)}")
print(f" Relevant documents: {result.get('num_relevant_documents', 0)}")
Return Value
This function does not return any value (implicitly returns None). It prints output directly to the console, including the query, processing progress updates, the generated response, and metadata about the operation (mode used, total documents processed, and number of relevant documents found).
Dependencies
pathlibdocument_indexerrag_engineconfig
Required Imports
from pathlib import Path
from document_indexer import DocumentIndexer
from rag_engine import DocChatRAG
import config
Usage Example
# Ensure documents are indexed and config is set up
# Then simply call the function:
full_reading_example()
# Expected output:
# === Full Reading Mode Example ===
# Query: What are all the key findings across all documents?
# Processing all documents (this may take 1-5 minutes)...
# → [progress messages]
# Response:
# --------------------------------------------------------------------------------
# [Generated response with key findings]
# --------------------------------------------------------------------------------
# Metadata:
# Mode: full_reading
# Total documents: 10
# Relevant documents: 8
Best Practices
- This is a demonstration function meant to be run as an example, not integrated into production code
- The full_reading mode processes all documents and can take 1-5 minutes - use sparingly and only when comprehensive analysis is needed
- Consider implementing timeout handling for production use cases
- The progress_callback pattern shown here is useful for long-running operations to provide user feedback
- Ensure documents are properly indexed before calling this function
- For production use, extract the core logic and add error handling around the rag.chat() call
- Consider adding logging instead of print statements for production environments
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function process_full_reading_background 78.8% similar
-
function extensive_mode_example 77.4% similar
-
function basic_rag_example 75.8% similar
-
class DocChatRAG 75.4% similar
-
function conversation_example 65.3% similar