Skip to main content

Introduction

R2R’s hybrid search combines traditional keyword-based searching with modern semantic understanding, providing more accurate and contextually relevant results. This approach is particularly effective for complex queries where both specific terms and overall meaning are crucial.

How R2R Hybrid Search Works

  1. Full-Text Search: Utilizes PostgreSQL’s full-text search with ts_rank_cd and websearch_to_tsquery.
  2. Semantic Search: Performs vector similarity search using the query’s embedded representation.
  3. Reciprocal Rank Fusion (RRF): Merges results from full-text and semantic searches using the formula:
  4. Result Ranking: Orders final results based on the combined RRF score.

Key Features

The full-text search component incorporates:
  • PostgreSQL’s tsvector for efficient text searching
  • websearch_to_tsquery for parsing user queries
  • ts_rank_cd for ranking full-text search results
The semantic search component uses:
  • Vector embeddings for storing and querying semantic representations
  • Cosine similarity for measuring the relevance of documents to the query

Configuration

VectorSearchSettings

Key settings for vector search configuration:

HybridSearchSettings

Specific parameters for hybrid search:

Usage Example

Results Comparison

Hybrid Search with RRF

Best Practices

  1. Optimize PostgreSQL indexing for both full-text and vector searches
  2. Regularly update search indices
  3. Monitor performance and adjust weights as needed
  4. Use appropriate vector dimensions and embedding models for your use case

Conclusion

R2R’s hybrid search offers a powerful solution for complex information retrieval needs, combining the strengths of keyword matching and semantic understanding. Its flexible configuration and use of Reciprocal Rank Fusion make it adaptable to a wide range of use cases, from technical documentation to broad, context-dependent queries.