{"slug": "building-a-four-tier-parallel-rag-pipeline-with-gemini", "title": "Building a Four-Tier Parallel RAG Pipeline with Gemini", "summary": "BotForge, an AI no-code chatbot platform, built a four-tier parallel RAG pipeline using Gemini's gemini-embedding-2 model to handle messy user queries. The system runs semantic search, MongoDB full-text search, regex keyword search, and fuzzy matching simultaneously via Promise.all, merging results with weighted scoring to improve retrieval accuracy over naive vector search alone.", "body_md": "When building BotForge, our AI no-code chatbot platform, we needed a retrieval system that could handle messy, real-world user queries — typos, partial phrases, semantically similar-but-differently-worded questions.\n\nA naive vector search alone wasn't good enough. It's powerful but brittle to out-of-vocabulary terms and exact keyword lookups.\n\nWe ran four retrieval strategies **simultaneously** using `Promise.all\\`\n\n, then merged results with a weighted scoring function.\n\n`\\`\n\n`javascript`\n\nconst [semanticResults, textResults, regexResults, fuzzyResults] = await Promise.all([\n\nsemanticSearch(query, embeddings), // weight 1.8x\n\nmongoFullTextSearch(query), // weight 1.5x\n\nregexKeywordSearch(query), // weight 1.0x\n\nfuzzyPerWordMatch(query), // weight 0.6x\n\n])\n\n\\`\\`\n\nUsing Gemini `gemini-embedding-2\\`\n\nto produce **3072-dimensional vectors**, we compute cosine similarity against stored document embeddings. This catches meaning — \"how do I reset my login?\" matches \"account recovery options\" even with no shared words.\n\nA native MongoDB Atlas text index for fast, exact keyword hits. Great for technical terms, product names, and precise phrases.\n\nEach significant word in the query is compiled to a case-insensitive regex. Catches partial matches and hyphenated variants.\n\nLevenshtein distance matching per query word — handles typos and misspellings like \"configuraton\" → \"configuration\".\n\nEach result carries a base score from its retrieval strategy. We deduplicate by chunk ID, sum scores across strategies, and sort descending:\n\n`\\`\n\n`javascript`\n\nfunction mergeResults(tiers, weights) {\n\nconst scoreMap = new Map()\n\ntiers.forEach((results, i) => {\n\nresults.forEach(({ id, score, chunk }) => {\n\nconst weighted = score * weights[i]\n\nscoreMap.set(id, {\n\nchunk,\n\ntotal: (scoreMap.get(id)?.total || 0) + weighted,\n\n})\n\n})\n\n})\n\nreturn [...scoreMap.values()].sort((a, b) => b.total - a.total).slice(0, 5)\n\n}\n\n\\`\\`\n\nThe parallel architecture was the key insight — running all four strategies concurrently keeps latency close to the slowest individual strategy (semantic search) rather than multiplying it.", "url": "https://wpnews.pro/news/building-a-four-tier-parallel-rag-pipeline-with-gemini", "canonical_source": "https://dev.to/danish_raza_dev/building-a-four-tier-parallel-rag-pipeline-with-gemini-3lpa", "published_at": "2026-07-07 12:39:27+00:00", "updated_at": "2026-07-07 12:58:32.217752+00:00", "lang": "en", "topics": ["large-language-models", "artificial-intelligence", "ai-products", "developer-tools", "natural-language-processing"], "entities": ["BotForge", "Gemini", "MongoDB Atlas", "Promise.all", "Levenshtein distance", "cosine similarity", "gemini-embedding-2"], "alternates": {"html": "https://wpnews.pro/news/building-a-four-tier-parallel-rag-pipeline-with-gemini", "markdown": "https://wpnews.pro/news/building-a-four-tier-parallel-rag-pipeline-with-gemini.md", "text": "https://wpnews.pro/news/building-a-four-tier-parallel-rag-pipeline-with-gemini.txt", "jsonld": "https://wpnews.pro/news/building-a-four-tier-parallel-rag-pipeline-with-gemini.jsonld"}}