Skip to content

Reject mismatched vector names in multi-target searches - #2161

Merged
g-despot merged 2 commits into
weaviate:mainfrom
xblwh:fix/validate-named-vector-targets
Sep 17, 2026
Merged

g-despot merged 2 commits into
weaviate:mainfrom
xblwh:fix/validate-named-vector-targets

Conversation

@xblwh

@xblwh xblwh commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

What changed

Reject vector dictionaries whose keys differ from the requested target vector names before constructing a near-vector or hybrid request.

For example, near_vector={"body": [1.0, 0.0]} with target_vector=["title"] currently changes the request target to body on Weaviate 1.27+ instead of reporting the mismatch. Using TargetVectors.manual_weights({"title": 1.0}) instead raises KeyError. The legacy request path also accepts mismatched names.

These inputs now raise WeaviateInvalidInputError. Matching names may still appear in a different order, and repeated targets with multiple weights remain supported.

Validation

  • The 18 mismatch regression cases fail before the fix; all 33 focused cases pass afterward. Tests cover near-vector, hybrid, and HybridVector.near_vector request construction across the legacy, 1.27, and 1.29 encodings.
  • pytest test mock_tests -q: 539 passed, 1 skipped.
  • Repository Ruff lint/format and Flake8 checks passed; Pyright 1.1.399 over weaviate reported 0 errors and 0 warnings.
  • Local validation used Python 3.12 on macOS. Tests construct protobuf requests without a live Weaviate server; the server integration suite was not run.

AI assistance: Codex helped investigate, implement, test, and review this change.

@orca-security-eu orca-security-eu Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Orca Security Scan Summary

Status Check Issues by priority
Passed Passed Infrastructure as Code high 0   medium 0   low 0   info 0 View in Orca
Passed Passed SAST high 0   medium 0   low 0   info 0 View in Orca
Passed Passed Secrets high 0   medium 0   low 0   info 0 View in Orca
Passed Passed Vulnerabilities high 0   medium 0   low 0   info 0 View in Orca

@weaviate-git-bot

Copy link
Copy Markdown

To avoid any confusion in the future about your contribution to Weaviate, we work with a Contributor License Agreement. If you agree, you can simply add a comment to this PR that you agree with the CLA so that we can merge.

beep boop - the Weaviate bot 👋🤖

PS:
Are you already a member of the Weaviate Forum?

@xblwh

xblwh commented Sep 15, 2026

Copy link
Copy Markdown
Contributor Author

I agree to the CLA

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The validation is consistent across affected request paths and has focused version-specific coverage.

Pull request overview

Adds validation to reject mismatched vector dictionary keys and requested target vectors.

Changes:

  • Validates target names across legacy and modern request encodings.
  • Adds regression coverage for near-vector and hybrid searches.
File summaries
File Description
weaviate/collections/grpc/shared.py Enforces matching vector and target names.
test/collection/test_target_vectors.py Tests mismatches, ordering, and repeated weighted targets.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@g-despot
g-despot merged commit 142d798 into weaviate:main Sep 17, 2026
127 checks passed
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