Search and RAG capabilities using the R2R CLI.

Retrieval Operations

The R2R CLI provides two main retrieval commands: search and rag (Retrieval-Augmented Generation). These commands allow you to query your document collection and generate AI-powered responses based on the retrieved content.

Search Command

The search command performs document retrieval using vector search and/or knowledge graph search capabilities.

$r2r search --query "Your search query"

Vector Search Options

  • --use-vector-search: Enable vector search (default: true)
  • --filters: Apply JSON filters to the search results
    $r2r search --filters '{"document_id":{"$in":["doc-id-1", "doc-id-2"]}}'
  • --search-limit: Maximum number of search results to return
  • --use-hybrid-search: Enable hybrid search combining vector and keyword search
  • --selected-collection-ids: Specify collection IDs to search within as JSON array
  • --search-strategy: Choose between “vanilla” search or advanced methods like query fusion or HyDE

Knowledge Graph Search Options

  • --use-kg-search: Enable knowledge graph search
  • --kg-search-type: Choose between “local” or “global” search
  • --kg-search-level: Specify the level for global KG search
  • --entity-types: Filter by entity types (as JSON)
  • --relationships: Filter by relationship types (as JSON)
  • --max-community-description-length: Set maximum length for community descriptions
  • --local-search-limits: Set limits for local search (as JSON)

RAG Command

The rag command combines search capabilities with AI generation to provide contextual responses based on your document collection.

$r2r rag --query "Your question"

Generation Options

  • --stream: Stream the response in real-time
  • --rag-model: Specify the model to use for generation

Vector Search Settings

  • --use-vector-search: Enable vector search (default: true)
  • --filters: Apply JSON filters to search results
  • --search-limit: Maximum number of search results (default: 10)
  • --use-hybrid-search: Enable hybrid search
  • --selected-collection-ids: Specify collection IDs to search within
  • --search-strategy: Choose search method (default: “vanilla”)

Knowledge Graph Settings

  • --use-kg-search: Enable knowledge graph search
  • --kg-search-type: Set to “local” or “global” (default: “local”)
  • --kg-search-level: Specify cluster level for Global KG search
  • --kg-search-model: Choose the model for KG agent
  • --entity-types: Filter by entity types (as JSON)
  • --relationships: Filter by relationship types (as JSON)
  • --max-community-description-length: Set maximum community description length
  • --local-search-limits: Set limits for local search (as JSON)

Examples

$# Simple vector search
>r2r search --query "What is quantum computing?"
>
># Search with filters
>r2r search --query "quantum computing" --filters '{"category": "physics"}'
$# Hybrid search with collection filtering
>r2r search --query "quantum computing" \
> --use-hybrid-search \
> --selected-collection-ids '["physics-collection", "computing-collection"]'
>
># Knowledge graph search
>r2r search --query "quantum computing relationships" \
> --use-kg-search \
> --kg-search-type "local" \
> --entity-types '["Concept", "Technology"]'

Basic RAG

$# Simple RAG query
>r2r rag --query "Explain quantum computing"
>
># Streaming RAG response
>r2r rag --query "Explain quantum computing" --stream

Advanced RAG

$# RAG with custom model and hybrid search
>r2r rag --query "Explain quantum computing" \
> --rag-model "gpt-4" \
> --use-hybrid-search \
> --search-limit 20
>
># RAG with knowledge graph integration
>r2r rag --query "How do quantum computers relate to cryptography?" \
> --use-kg-search \
> --kg-search-type "global" \
> --relationships '["ENABLES", "IMPACTS"]' \
> --stream

Tips for Effective Retrieval

  1. Refine Your Queries: Be specific and clear in your search queries to get more relevant results.

  2. Use Filters: Narrow down results using filters when you know specific document characteristics.

  3. Combine Search Types: Use hybrid search and knowledge graph capabilities together for more comprehensive results.

  4. Adjust Search Limits: Modify the search limit based on your needs - higher limits for broad topics, lower limits for specific queries.

  5. Stream Long Responses: Use the --stream option with RAG for better user experience with longer generations.