Parallel Hybrid Search Fusion for High‑Reliability Agentic AI
This article explains design patterns that boost the reliability of modern agentic AI systems, focusing on a parallel hybrid search fusion that runs vector and keyword retrievals concurrently, merges their results, and demonstrates through code and benchmarks that the combined approach yields more accurate and complete answers than either method alone.
Parallel Hybrid Search Fusion
Vector search (semantic) understands concepts but may miss exact rare keywords; keyword search (lexical) finds exact terms but lacks conceptual understanding.
Implementation steps:
from langchain_community.vectorstores import FAISS
from langchain_community.embeddings import HuggingFaceEmbeddings
vector_store = FAISS.from_documents(kb_docs, embedding=embeddings)
vector_retriever = vector_store.as_retriever(search_kwargs={"k": 2}) from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.metrics.pairwise import cosine_similarity
import numpy as np
from langchain_core.retrievers import BaseRetriever
from langchain_core.callbacks import CallbackManagerForRetrieverRun
from typing import List
from langchain_core.documents import Document
class TfidfRetriever(BaseRetriever):
"""Custom LangChain retriever that uses TF‑IDF for keyword search"""
vectorizer: TfidfVectorizer
docs: List[Document]
k: int = 2
def _get_relevant_documents(self, query: str, *, run_manager: CallbackManagerForRetrieverRun) -> List[Document]:
query_vec = self.vectorizer.transform([query])
doc_vectors = self.vectorizer.transform([doc.page_content for doc in self.docs])
similarities = cosine_similarity(query_vec, doc_vectors).flatten()
top_k_indices = np.argsort(similarities)[-self.k:][::-1]
return [self.docs[i] for i in top_k_indices]
vectorizer = TfidfVectorizer().fit([doc.page_content for doc in kb_docs])
keyword_retriever = TfidfRetriever(vectorizer=vectorizer, docs=kb_docs, k=2)Parallel retrieval node runs both retrievers and deduplicates results:
from langgraph.graph import StateGraph, END
from typing import TypedDict, List
class HybridRAGState(TypedDict):
question: str
retrieved_docs: List[Document]
final_answer: str
def parallel_retrieval_node(state: HybridRAGState):
"""Run vector and keyword searches in parallel and fuse results"""
print("--- [Hybrid Retriever] Running Vector and Keyword searches in parallel... ---")
vector_docs = vector_retriever.invoke(state['question'])
keyword_docs = keyword_retriever.invoke(state['question'])
all_docs = vector_docs + keyword_docs
unique_docs = list({doc.page_content: doc for doc in all_docs}.values())
print(f"--- [Hybrid Retriever] Fused results: Found {len(unique_docs)} unique documents. ---")
return {"retrieved_docs": unique_docs}
workflow = StateGraph(HybridRAGState)
workflow.add_node("parallel_retrieval", parallel_retrieval_node)
workflow.add_node("generate_answer", generation_node)
workflow.set_entry_point("parallel_retrieval")
workflow.add_edge("parallel_retrieval", "generate_answer")
workflow.add_edge("generate_answer", END)
hybrid_rag_app = workflow.compile()Evaluation query combines a semantic concept and a rare lexical token:
user_query = "What are our company's power saving efforts, and what is the error code for QLeap-V4 overheating?"
vector_answer = rag_chain_vector.invoke(user_query)
keyword_answer = rag_chain_keyword.invoke(user_query)
hybrid_answer = hybrid_result['final_answer']Results:
Vector‑only RAG captures the semantic part but fails to provide the error code.
Keyword‑only RAG returns the error code but omits the broader “power‑saving” context.
Hybrid RAG returns both parts correctly, demonstrating that parallel execution and deduplication combine the strengths of each modality.
Conclusion: Parallel hybrid search fusion yields a richer, single context for downstream generation, improving answer completeness for queries that require both conceptual understanding and exact term matching.
Code and full experiment are available in the GitHub repository: https://github.com/FareedKhan-dev/agentic-parallelism
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
DeepNoMind
I’m Yu Fan, a tech leader with deep technical expertise and managerial vision. Formerly at Motorola, now at Mavenir, I’ve led teams for years, focusing on backend architecture and cloud-native solutions, staying abreast of AI and other frontier fields, and championing personal growth and lifelong learning.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
