← Back to learning path
Chapter · Published

Hybrid retrieval and reranking: improve candidate relevance

Combine keyword, vector, and filter signals while keeping relevance scoring separate from permission boundaries.

Source: knowledge/p24-b/collection_6e8fbe1e8b1ea569a539e8a5/tutorials/rag-hybrid-search-and-reranking.mdRAG knowledge engineering
Chapter progress 0%Learning path progress 0% · 0/10 chapters completedContinue learning path →

Pure vector retrieval can miss exact model names, error codes, and abbreviations. Pure keyword search can miss semantic variants. Hybrid retrieval broadens the candidate set first, then uses reranking and business filters to produce the final context.

Core concepts

Keyword search handles exact matches, vector search handles semantic recall, and filters handle tenant and permission boundaries. A reranker may compare only authorized candidates; its result must never bypass access control.

def reciprocal_rank_fusion(*ranked_lists: list[str], k: int = 60) -> list[str]:
    scores: dict[str, float] = {}
    for items in ranked_lists:
        for rank, item in enumerate(items, start=1):
            scores[item] = scores.get(item, 0) + 1 / (k + rank)
    return [item for item, _ in sorted(scores.items(), key=lambda pair: pair[1], reverse=True)]

assert reciprocal_rank_fusion(['a', 'b'], ['b', 'c'])[0] in {'a', 'b'}

Steps

  1. Implement keyword and vector retrieval separately and attach document permission tags to every candidate.
  2. Merge candidates, then apply tenant, role, and document-status filters.
  3. Rerank or score the remaining candidates, keeping sources and scores for debugging.
  4. Evaluate exact, ambiguous, and cross-language question sets separately.

When to use it

It suits product search, technical support, and multilingual knowledge bases.

Common questions

Can reranking fix a permission problem? No. Permission filtering must happen before reranking.

How should fusion weights be chosen? Build a fixed baseline first, then adjust with labeled data rather than one example.

What if evidence is insufficient? Return a clear lack-of-evidence state instead of asking the model to invent facts.

Official references

OpenAI Retrieval; Qdrant filtering.

Last checked: 2026-11-16. Use the linked official documentation for current retrieval behavior.

Related practical cases

KnowledgeCase study: replaying RAG retrieval regression with a fixed question set

Related source resources

SourceQdrant

Further reading

KnowledgeRAG for Enterprise Knowledge: Architecture and PracticeKnowledgeDesigning Reliable AI Automation WorkflowsKnowledgeStructured Outputs and Tool Contracts for Safe Agents
Product Hub Demo · V0.3