# `Arcana.Graph.FusionSearch`
[🔗](https://github.com/georgeguimaraes/arcana/blob/main/lib/arcana/graph/fusion_search.ex#L1)

Combines vector search and graph-based search using Reciprocal Rank Fusion.

FusionSearch implements the core GraphRAG retrieval strategy:
1. Extract entities from the query
2. Run vector search on document chunks (standard RAG)
3. Run graph search on the knowledge graph
4. Merge results using Reciprocal Rank Fusion (RRF)

## Reciprocal Rank Fusion

RRF is a simple but effective method for combining ranked lists:

    score(doc) = Σ 1 / (k + rank(doc, list_i))

where k is a constant (default: 60) that reduces the impact of high ranks.

## Example

    # Build graph from extracted data
    graph = GraphQuery.build_graph(entities, relationships, chunks, communities)

    # Extract entities from query
    {:ok, entities} = Arcana.Graph.EntityExtractor.NER.extract("Tell me about OpenAI", [])

    # Run vector search
    vector_results = Arcana.search(repo, collection, query, top_k: 10)

    # Combine with graph search
    FusionSearch.search(graph, entities, vector_results)

# `graph_search`

Searches the knowledge graph based on recognized entities.

Finds entities in the graph matching the provided extracted entities,
then traverses relationships to collect connected chunks.

## Options

  - `:depth` - How many hops to traverse (default: 1)

# `reciprocal_rank_fusion`

Merges multiple ranked lists using Reciprocal Rank Fusion.

## Options

  - `:k` - RRF constant to reduce high-rank impact (default: 60)

## Algorithm

For each document, computes:

    score = sum(1 / (k + rank)) across all lists

Higher scores indicate documents that appear in multiple lists
and/or rank highly in individual lists.

# `search`

Combines vector search results with graph search using RRF.

Takes pre-computed vector search results and entities extracted from
the query, runs graph search, then merges both result sets.

## Options

  - `:depth` - Graph traversal depth (default: 1)
  - `:limit` - Maximum results to return (default: 10)
  - `:k` - RRF constant (default: 60)

---

*Consult [api-reference.md](api-reference.md) for complete listing*
