-
Type:
Improvement
-
Resolution: Unresolved
-
Priority:
Unknown
-
None
-
Affects Version/s: None
-
Component/s: ABX
-
None
-
None
-
None
-
None
-
None
-
None
TL;DR
Each MongoDBVector instance caches where an index lives and which fields its search index can filter on. It doesn't notice when another process or a database admin changes them, so it keeps using stale values until it restarts. Choose and document a refresh strategy.
Context
MongoDBVector keeps three in-process caches:
- indexTargets: the logical index name's collection, search index names, and write policy, read from the registry.
- declaredFilterPaths: the fields the vector search index declares as filters, read once the index is ready.
- collections: collection handles.
When every filter field is declared, Mastra passes the filter straight to vector search ("pushdown"). Otherwise it runs a slower preliminary query. createSearchIndex() and deleteIndex() already re-read the registry instead of trusting the cache. query(), upsert() and the other operations don't.
Desired User Experience
await store.query({ indexName, queryVector: embedding, filter: { status: 'completed' } }); // process A caches the filter fields
// Meanwhile, another process or an admin recreates the search index without `status` as a filter field.
await store.query({ indexName, queryVector: embedding, filter: { status: 'completed' } });
// Before: process A keeps pushing the filter down, so the new index rejects it until A restarts.
// After: a documented refresh path or time limit applies, and dropped or moved resources are handled safely.
Task
Goals: Long-running apps keep routing and filtering correctly when indexes change outside the process, without losing the cache's speed.
Where: cache fields, resolveIndexTarget(), getCollection() and getDeclaredFilterPaths() in stores/mongodb/src/vector/index.ts. Live page: mastra.ai/integrations/vectors/mongodb.
Acceptance Criteria
- [ ] A refresh strategy is chosen and documented on the MongoDB vector page. Change streams are one option, not a requirement.
- [ ] A running process picks up an external change within the documented bound, without restarting.
- [ ] When freshness can't be established, writes and deletes stay conservative.
- [ ] Repeat operations on unchanged indexes don't add a database round trip every time.