Arcana.Search module provides powerful search capabilities across your ingested documents. It supports multiple search modes and can be enhanced with GraphRAG for entity-aware retrieval.
Overview
Arcana Search offers three search modes:- Semantic Search - Vector similarity using embeddings (default)
- Fulltext Search - Traditional keyword-based text search
- Hybrid Search - Combines semantic and fulltext using Reciprocal Rank Fusion (RRF)
Functions
search/2
Searches for chunks similar to the query.The search query text. For semantic search, this will be embedded and compared against document embeddings. For fulltext, it’s matched against text content.
Search options:
The Ecto repo to use. Required when using the pgvector backend (default).
Maximum number of results to return. The actual number may be lower if fewer matches exist.
Search mode:
:semantic- Vector similarity search (default):fulltext- Keyword-based text search:hybrid- Combines both with RRF
Filter results to documents with this source_id. Useful for scoping searches to specific document sources.
Minimum similarity score (0.0 to 1.0). Results below this score are filtered out. Only applies to semantic search.
Filter results to a specific collection by name. Use this to search within a subset of documents.
Filter results to multiple collections. Results are combined and ranked together.
Override the configured vector store backend (e.g.,
:pgvector, :qdrant).Weight for semantic scores in hybrid mode (0.0 to 1.0). Must sum with
fulltext_weight to 1.0.Weight for fulltext scores in hybrid mode (0.0 to 1.0). Must sum with
semantic_weight to 1.0.Optional query rewriting function:
fn query -> {:ok, rewritten} | {:error, reason} end. Can expand queries, add synonyms, etc.Explicitly enable/disable GraphRAG enhancement for this search (overrides config).
Returns a list of result maps, sorted by score in descending order. Each result contains:
id(string) - UUID of the chunktext(string) - The chunk’s text contentdocument_id(string) - UUID of the parent documentchunk_index(integer) - Position of the chunk within its document (0-based)score(float) - Relevance score (0.0 to 1.0 for semantic, varies for fulltext)semantic_score(float, hybrid only) - Semantic component scorefulltext_score(float, hybrid only) - Fulltext component score
Returns an error tuple if search fails:
{:error, {:embedding_failed, reason}}- Failed to embed the query (semantic/hybrid mode){:error, reason}- Other errors
Search Modes
Semantic Search (Default)
Uses vector embeddings to find conceptually similar content:- Conceptual similarity
- Natural language queries
- Finding related topics
- Handling synonyms automatically
Fulltext Search
Traditional keyword-based search using PostgreSQL’s fulltext capabilities:- Exact keyword matching
- Technical terms and identifiers
- Code snippets
- Faster searches (no embedding required)
Hybrid Search
Combines semantic and fulltext using Reciprocal Rank Fusion (RRF):- General purpose search
- Balancing precision and recall
- Queries with both concepts and specific terms
- Performs both semantic and fulltext searches
- Ranks results from each independently
- Combines using RRF with configured weights
- Returns unified, re-ranked results
GraphRAG Enhancement
When GraphRAG is enabled, searches are enhanced with entity-based retrieval:- Better results for entity-centric queries
- Follows relationships (“CEO of X”, “located in Y”)
- Improves precision for proper nouns
- Leverages knowledge graph structure
Query Rewriting
Improve search quality by rewriting queries before search:rewrite_query/2
Rewrites a query using a provided rewriter function.The query to rewrite
Function that takes a query and returns
{:ok, rewritten} or {:error, reason}Advanced Filtering
By Source
By Collection
By Threshold
Performance Optimization
Adjust Limits
Choose the Right Mode
Telemetry Events
Monitor search performance with telemetry:[:arcana, :search, :start]- Search started[:arcana, :search, :stop]- Search completed[:arcana, :search, :exception]- Search failed[:arcana, :graph, :search, :start]- GraphRAG enhancement started[:arcana, :graph, :search, :stop]- GraphRAG enhancement completed
Error Handling
Related Functions
- Arcana.search/2 - Main module function
- Arcana.ask/2 - RAG question answering with search
- Arcana.ingest/2 - Ingest documents for searching