mongodb-search-and-ai

Implement and optimize MongoDB Atlas Search, Vector Search, and Hybrid Search solutions.

4|2|Updated May 18, 2022
One-click install
npx skills add https://github.com/pjmagee/starwars-data --skill mongodb-search-and-ai-pjmagee
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: mongodb-search-and-ai
Source: https://github.com/pjmagee/starwars-data/tree/main/.agents/skills/mongodb-search-and-ai
Command: npx skills add https://github.com/pjmagee/starwars-data --skill mongodb-search-and-ai-pjmagee

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Helps MongoDB users choose, implement, and optimize Atlas lexical search, Vector Search, and Hybrid Search so applications return relevant results for keyword, fuzzy, autocomplete, and semantic queries without wasting compute or misconfiguring indexes.

Core Features & Use Cases

  • Search type guidance: Recommends when to use Atlas Search (lexical), Vector Search (semantic), or Hybrid patterns (rankFusion / scoreFusion / lexical prefilters).
  • Index and query recipes: Provides index JSON examples, field-type guidance (vector/filter/token/autocomplete), analyzer and storedSource recommendations, and aggregation pipeline patterns for $vectorSearch, $search, $rankFusion, and $scoreFusion.
  • Optimization & safety: Covers cluster version checks for fusion stages, numCandidates tuning, quantization and hnswOptions trade-offs, pre-filter vs post-filter guidance, and anti-patterns to avoid (e.g., $regex/$text for search).
  • Use Case Example: Build a RAG-enabled search that prefilters by genre, uses a dotProduct vector index for normalized embeddings, and fuses lexical title matches with vector plot similarity for ranked results.

Quick Start

Configure a hybrid search for the target collection by proposing two index JSONs (one vector, one search-type with vector field or a vectorSearch-type index), name the indexes, and return the aggregation pipeline that uses either $rankFusion or $scoreFusion depending on desired scoring.

Frequently Asked Questions about mongodb-search-and-ai

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I implement hybrid search in MongoDB Atlas combining lexical and semantic results?

To implement hybrid search in MongoDB Atlas, define separate vector and lexical search index JSONs, then use aggregation pipelines with $rankFusion or $scoreFusion to combine and rank results from both indexes.

When should I use Atlas Search versus Vector Search for my queries?

Use Atlas Search for lexical text queries like autocomplete and fuzzy matching, and use Vector Search for semantic similarity tasks such as RAG. Hybrid search combines both when you need keyword precision and semantic relevance together.

How do I optimize numCandidates and pre-filters in MongoDB Vector Search?

Optimize MongoDB Vector Search by tuning numCandidates for accuracy versus compute trade-offs and applying pre-filters to restrict the search space before vector retrieval, avoiding costly post-filter operations on large collections.

What MongoDB cluster version is required for $rankFusion and $scoreFusion stages?

MongoDB $rankFusion and $scoreFusion aggregation stages require specific cluster version checks to ensure compatibility, as these fusion stages are only available on recent MongoDB Atlas versions supporting advanced hybrid search pipelines.

Why should I avoid using $regex or $text for search queries in MongoDB?

Using $regex or $text for search in MongoDB is an anti-pattern because they lack the relevance scoring, analyzer support, and performance optimization of dedicated Atlas Search indexes built specifically for lexical and fuzzy matching.

Can I configure a vector index with dotProduct for normalized embeddings in MongoDB?

You can configure a vectorSearch-type index in MongoDB using dotProduct similarity for normalized embeddings, adjusting hnswOptions and quantization settings to balance index size, search latency, and recall accuracy.