Evaluation Metrics
compute_recall_at_k
Compute Recall@k for a single query.List of retrieved document IDs in ranked order
Set of ground truth relevant document IDs
Number of top results to consider
Recall score between 0 and 1. Formula: (relevant docs in top-k) / (total relevant docs)
compute_precision_at_k
Compute Precision@k for a single query.List of retrieved document IDs in ranked order
Set of ground truth relevant document IDs
Number of top results to consider
Precision score between 0 and 1. Formula: (relevant docs in top-k) / k
compute_mrr
Compute Mean Reciprocal Rank for a single query.List of retrieved document IDs in ranked order
Set of ground truth relevant document IDs
Reciprocal rank score between 0 and 1. Formula: 1 / (rank of first relevant document)
compute_ndcg_at_k
Compute Normalized Discounted Cumulative Gain at k.List of retrieved document IDs in ranked order
Set of ground truth relevant document IDs
Number of top results to consider
NDCG score between 0 and 1. Formula: DCG@k / IDCG@k (Ideal DCG)
compute_hit_rate
Compute hit rate (binary success) for a single query.List of retrieved document IDs in ranked order
Set of ground truth relevant document IDs
Number of top results to consider
1.0 if any relevant doc is in top-k, else 0.0
evaluate_retrieval
Evaluate retrieval quality over multiple queries.List of QueryResult objects with retrieved and relevant IDs
Cutoff for top-k metrics
RetrievalMetrics object with averaged scores across all queries
Sparse Embeddings
normalize_sparse
Normalize any sparse format to Haystack SparseEmbedding.Sparse embedding in any supported format:
- SparseEmbedding object (passthrough)
- Dict with int keys and float values (Milvus format)
- Dict with indices and values lists (Pinecone format)
- None (passthrough)
Normalized SparseEmbedding or None
to_milvus_sparse
Convert SparseEmbedding to Milvus format.Haystack SparseEmbedding object
Dictionary mapping indices to values in Milvus format
to_pinecone_sparse
Convert SparseEmbedding to Pinecone sparse_values format.Haystack SparseEmbedding object
Dictionary with ‘indices’ and ‘values’ keys in Pinecone format
to_qdrant_sparse
Convert SparseEmbedding to Qdrant SparseVector format.Haystack SparseEmbedding object
Qdrant SparseVector object
get_doc_sparse_embedding
Extract sparse embedding from Document, checking standard and legacy locations.Haystack Document object
Legacy meta key to check if doc.sparse_embedding is None
SparseEmbedding from doc.sparse_embedding or doc.meta[fallback_meta_key], or None
Document Converters
ChromaDocumentConverter
Utility class for converting between Haystack Documents and Chroma format.prepare_haystack_documents_for_upsert
List of Haystack Document objects
Dictionary with keys: ids, texts, metadatas, embeddings formatted for Chroma upsert
PineconeDocumentConverter
Utility class for converting between Haystack Documents and Pinecone format.prepare_haystack_documents_for_upsert
List of Haystack Document objects
List of Pinecone vector dictionaries with id, values, metadata keys
convert_query_results_to_haystack_documents
Pinecone query results dictionary
Whether to include vector embeddings in Documents
List of Haystack Document objects
Configuration
load_config
Load configuration from YAML file.Path to YAML configuration file
Loaded configuration dictionary with environment variables resolved
resolve_env_vars
Resolve environment variable references in configuration.Configuration dictionary potentially containing $ references
Configuration with all environment variables resolved