Skip to content

Conversation

@himanshusinghs
Copy link
Collaborator

Proposed changes

This PR adds an assertion to validate that if a vector search stage asks for a pre-filter using MQL expression then the fields in the MQL expression are indeed indexed as part of vector search index.

When validation is not met, we fail the tool call with MongoDBError.

Checklist

Copilot AI review requested due to automatic review settings October 27, 2025 19:38
@himanshusinghs himanshusinghs requested a review from a team as a code owner October 27, 2025 19:38
@himanshusinghs himanshusinghs force-pushed the chore/MCP-242-validate-pre-filter-fields branch from 080d840 to e77cf2e Compare October 27, 2025 19:39
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds validation to ensure that fields used in $vectorSearch pre-filter MQL expressions are properly indexed in the vector search index. When validation fails, the tool call is rejected with a MongoDBError.

Key Changes:

  • Adds a helper function to extract field names from vector search filter expressions
  • Implements validation logic in the aggregate tool to check filter fields against the vector search index definition
  • Adds comprehensive test coverage for the new validation behavior

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
tests/unit/helpers/collectFieldsFromVectorSearchFilter.test.ts New unit tests for the filter field extraction helper
tests/integration/tools/mongodb/read/aggregate.test.ts Integration tests validating filter field validation behavior
src/tools/mongodb/read/aggregate.ts Implements validation logic and index field retrieval
src/helpers/collectFieldsFromVectorSearchFilter.ts Helper to recursively extract field names from MQL filter expressions
src/common/logger.ts Adds new log ID for validation errors

@coveralls
Copy link
Collaborator

coveralls commented Oct 27, 2025

Pull Request Test Coverage Report for Build 18978749862

Details

  • 133 of 142 (93.66%) changed or added relevant lines in 6 files are covered.
  • 24 unchanged lines in 2 files lost coverage.
  • Overall coverage decreased (-0.2%) to 79.88%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/tools/mongodb/mongodbSchemas.ts 67 70 95.71%
src/tools/mongodb/read/aggregate.ts 4 10 40.0%
Files with Coverage Reduction New Missed Lines %
src/common/search/vectorSearchEmbeddingsManager.ts 10 82.74%
src/tools/mongodb/read/aggregate.ts 14 77.32%
Totals Coverage Status
Change from base Build 18977258753: -0.2%
Covered Lines: 6479
Relevant Lines: 7989

💛 - Coveralls

@gagik
Copy link
Collaborator

gagik commented Oct 31, 2025

Changes LGTM, added a small refactor to put the assertion helper independent of the class since the tool class was getting quite huge. We might want this for others helpers we have to.

@gagik gagik enabled auto-merge (squash) October 31, 2025 16:35
@gagik gagik merged commit 464c37a into main Oct 31, 2025
18 of 19 checks passed
@gagik gagik deleted the chore/MCP-242-validate-pre-filter-fields branch October 31, 2025 16:35
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.

4 participants