Combines multiple retrieval results using Reciprocal Rank Fusion to improve RAG answer quality via a query pipeline.
# Source: https://github.com/mperkins0155/llama-hub | License: MIT | Copyright Jerry Liu
# Provided via justclaw.it.com; keep this notice with the code.
"""RAG Fusion Pipeline."""
from llama_index.query_pipeline import (
QueryPipeline,
InputComponent,
FnComponent,
ArgPackComponent,
)
from typing import Dict, Any, List, Optional
from llama_index.llama_pack.base import BaseLlamaPack
from llama_index.llms.llm import LLM
from llama_index.llms.openai import OpenAI
from llama_index import Document, VectorStoreIndex, ServiceContext
from llama_index.response_synthesizers import TreeSummarize
from llama_index.schema import NodeWithScore
from llama_index.node_parser import SentenceSplitter
DEFAULT_CHUNK_SIZES = [128, 256, 512, 1024]
def reciprocal_rank_fusion(
results: List[L
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search 40K more like it.
Get a free API key