Skip to content

fix: upgrade MongoDB vector store from deprecated knnVector to GA vectorSearch#3995

Merged
kartik-mem0 merged 3 commits intomem0ai:mainfrom
veeceey:fix/issue-3970-mongodb-knnvector
Mar 23, 2026
Merged

fix: upgrade MongoDB vector store from deprecated knnVector to GA vectorSearch#3995
kartik-mem0 merged 3 commits intomem0ai:mainfrom
veeceey:fix/issue-3970-mongodb-knnvector

Conversation

@veeceey
Copy link
Copy Markdown
Contributor

@veeceey veeceey commented Feb 7, 2026

Summary

Fixes #3970

Upgrades the MongoDB vector store implementation from the deprecated knnBeta/knnVector index syntax to the stable GA vectorSearch format, as documented in the MongoDB Atlas migration guide.

Changes

  • VECTOR_TYPE: Changed from "knnVector" (deprecated) to "vector" (GA)
  • Index creation (create_col): Replaced legacy mappings definition with type="vectorSearch" and fields list format using numDimensions instead of dimensions
  • Search accuracy (search): Increased numCandidates from limit (identical to limit, poor recall) to limit * 20 (recommended 10-20x multiplier for HNSW indexes)

Before (deprecated)

SearchIndexModel(
    name=self.index_name,
    definition={
        "mappings": {
            "dynamic": False,
            "fields": {
                "embedding": {
                    "type": "knnVector",
                    "dimensions": self.embedding_model_dims,
                    ...
                }
            },
        }
    },
)

After (GA)

SearchIndexModel(
    name=self.index_name,
    type="vectorSearch",
    definition={
        "fields": [
            {
                "type": "vector",
                "path": "embedding",
                "numDimensions": self.embedding_model_dims,
                ...
            }
        ]
    },
)

Test plan

  • Verify index creation uses type="vectorSearch" with fields list format
  • Verify field definition uses numDimensions instead of dimensions
  • Verify numCandidates is set to limit * 20 for improved recall
  • Verify no knnVector references remain in the codebase

@veeceey
Copy link
Copy Markdown
Contributor Author

veeceey commented Feb 10, 2026

Hi team -- friendly ping! This PR has been open for a couple of days without review. Would love any feedback when you get a chance. Thanks!

@veeceey
Copy link
Copy Markdown
Contributor Author

veeceey commented Feb 19, 2026

Friendly ping - any chance someone could take a look at this when they get a chance? It's been open for about 10 days now. Happy to make any changes if needed. Thanks!

kartik-mem0 and others added 2 commits March 23, 2026 12:01
…ration

- Cap numCandidates to min(limit * 20, 10000) to respect MongoDB's hard upper limit
- Update test assertions to match new vectorSearch index format
- Update numCandidates assertion in test_search to reflect 20x multiplier

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@kartik-mem0 kartik-mem0 merged commit 7cebaba into mem0ai:main Mar 23, 2026
6 of 7 checks passed
jamebobob pushed a commit to jamebobob/mem0-vigil-recall that referenced this pull request Mar 29, 2026
…torSearch (mem0ai#3995)

Co-authored-by: kartik-mem0 <kartik.labhshetwar@mem0.ai>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MONGODB BUG FIX: knnVector is deprecated

2 participants