🔍 Code Extractor

function basic_rag_example

Maturity: 44

Demonstrates a basic RAG (Retrieval-Augmented Generation) workflow by initializing a DocChatRAG engine, executing a sample query about document topics, and displaying the response with metadata.

File:
/tf/active/vicechatdev/docchat/example_usage.py
Lines:
46 - 73
Complexity:
simple

Purpose

This function serves as a demonstration/example of how to use the DocChatRAG system in basic mode. It shows the complete workflow: initializing the RAG engine, formulating a query, executing the chat method with specific parameters (basic mode, top_k=5, reranking enabled), and displaying both the response and metadata. This is intended as a reference implementation for developers learning to use the RAG system.

Source Code

def basic_rag_example():
    """Example: Use Basic RAG mode"""
    print("\n=== Basic RAG Example ===\n")
    
    # Initialize RAG engine
    rag = DocChatRAG()
    
    # Example query
    query = "What are the main topics in the documents?"
    
    print(f"Query: {query}\n")
    
    # Run basic RAG
    result = rag.chat(
        query=query,
        mode="basic",
        top_k=5,
        use_reranking=True
    )
    
    print("Response:")
    print("-" * 80)
    print(result['response'])
    print("-" * 80)
    
    print(f"\nMetadata:")
    print(f"  Mode: {result['mode']}")
    print(f"  Chunks used: {result.get('num_chunks', 0)}")

Return Value

This function does not return any value (implicitly returns None). It performs side effects by printing output to the console, including the query, the RAG response, and metadata about the operation (mode used and number of chunks processed).

Dependencies

  • pathlib
  • document_indexer
  • rag_engine
  • config

Required Imports

from pathlib import Path
from document_indexer import DocumentIndexer
from rag_engine import DocChatRAG
import config

Usage Example

from pathlib import Path
from document_indexer import DocumentIndexer
from rag_engine import DocChatRAG
import config

# Ensure documents are indexed first
# indexer = DocumentIndexer()
# indexer.index_documents()

# Run the basic RAG example
basic_rag_example()

# Output will be printed to console showing:
# - The query being asked
# - The RAG system's response
# - Metadata including mode and number of chunks used

Best Practices

  • This function is intended as a demonstration only and should not be used in production code
  • Ensure documents are indexed before running this example
  • The function uses hardcoded query and parameters - modify these for different use cases
  • Check that the DocChatRAG engine is properly initialized with required configurations
  • Consider error handling when adapting this code for production use
  • The function prints to console - redirect or capture output if needed in automated environments
  • Verify that the config module contains all necessary settings for the RAG engine

Similar Components

AI-powered semantic similarity - components with related functionality:

  • class DocChatRAG 81.0% similar

    Main RAG engine with three operating modes: 1. Basic RAG (similarity search) 2. Extensive (full document retrieval with preprocessing) 3. Full Reading (process all documents)

    From: /tf/active/vicechatdev/docchat/rag_engine.py
  • function extensive_mode_example 77.2% similar

    Demonstrates the usage of DocChatRAG's extensive mode for detailed document analysis with a sample query about methodologies.

    From: /tf/active/vicechatdev/docchat/example_usage.py
  • function full_reading_example 75.8% similar

    Demonstrates the full reading mode of a RAG (Retrieval-Augmented Generation) system by processing all documents to answer a comprehensive query about key findings.

    From: /tf/active/vicechatdev/docchat/example_usage.py
  • function conversation_example 73.6% similar

    Demonstrates a multi-turn conversational RAG system with chat history management, showing how follow-up questions are automatically optimized based on conversation context.

    From: /tf/active/vicechatdev/docchat/example_usage.py
  • function process_chat_background 70.9% similar

    Processes chat requests asynchronously in a background thread, managing RAG engine interactions, progress updates, and session state for various query modes including basic, extensive, full_reading, and deep_reflection.

    From: /tf/active/vicechatdev/docchat/app.py
← Back to Browse