Search documentation of Ragex

# Ragex.Retrieval.Hybrid (Ragex v0.4.0)

View Source

Hybrid retrieval combining symbolic graph queries with semantic similarity search.

Provides multiple strategies for combining structural and semantic search:

- Semantic-first: Use embeddings to find candidates, refine with graph
- Graph-first: Use symbolic queries to filter, rank by similarity
- Fusion: Combine results from both approaches using RRF

## Summary

### Functions

reciprocal_rank_fusion(result_sets, opts \\ [])

Performs Reciprocal Rank Fusion on multiple result sets.

search(query, opts \\ [])

Performs hybrid search combining semantic and symbolic approaches.

## Functions

# reciprocal_rank_fusion(result_sets, opts \\ [])

Performs Reciprocal Rank Fusion on multiple result sets.

RRF combines rankings from different sources by:

1. Converting ranks to scores: 1 / (rank + k)
2. Summing scores across all sources
3. Re-ranking by combined score

The constant k (default 60) prevents high rankings from dominating.

# search(query, opts \\ [])

Performs hybrid search combining semantic and symbolic approaches.

## Strategies

- `:semantic_first` - Semantic search followed by graph filtering
- `:graph_first` - Graph query followed by semantic ranking
- `:fusion` - Combine both with Reciprocal Rank Fusion (default)

## Options

- `:strategy` - Search strategy (default: :fusion)
- `:limit` - Maximum results (default: 10)
- `:threshold` - Semantic similarity threshold (default: 0.7)
- `:node_type` - Filter by entity type
- `:graph_filter` - Additional graph constraints
- `:metaast_ranking` - Enable MetaAST-based ranking boosts (default: true)
- `:metaast_opts` - Options for MetaAST ranking:
  - `:prefer_pure` - Boost pure functions more (default: true)
  - `:penalize_complex` - Penalize complex code more (default: true)
  - `:cross_language` - Enable cross-language equivalence search (default: false)

## Examples

    # Fusion strategy (default)
    Hybrid.search("parse JSON", limit: 5)

    # Semantic-first strategy
    Hybrid.search("HTTP handler", strategy: :semantic_first)

    # Graph-first with constraints
    Hybrid.search("calculate",
      strategy: :graph_first,
      graph_filter: %{module: "Math"}
    )

    # With MetaAST ranking for cross-language results
    Hybrid.search("map operations",
      metaast_ranking: true,
      metaast_opts: [cross_language: true]
    )