feat: support negative matching in queries - #28
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
Adds negative matching support to the semantic element finder so queries can exclude/penalize elements using triggers like not, without, excluding, etc.
Changes:
- Introduces centralized query parsing into positive/negative token sets.
- Applies negative penalties/exclusions across lexical, embedding, and combined matchers (with score clamping).
- Adds tests and benchmarks covering negative matching, negative-only queries, and regressions.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| semantic_test.go | Adds end-to-end tests for negative matching behavior in the public package surface. |
| internal/types/types.go | Adds ParsedQuery type to represent positive vs negative tokens. |
| internal/engine/query_parser.go | Implements query parsing with negative triggers. |
| internal/engine/query_parser_test.go | Adds table-driven tests for query parsing edge cases. |
| internal/engine/lexical.go | Integrates negative parsing and penalties into lexical matching. |
| internal/engine/lexical_test.go | Adds lexical unit tests for negative penalization, synonyms, and empty queries. |
| internal/engine/embedding.go | Integrates negative parsing and cosine-similarity penalties into embedding matching. |
| internal/engine/embedding_test.go | Adds embedding unit tests for negative penalization, negative-only, and empty queries. |
| internal/engine/combined.go | Centralizes parsing and fuses results with clamped combined scores. |
| internal/engine/combined_test.go | Adds combined-matcher coverage for negative queries, regressions, and clamping. |
| internal/engine/benchmark_test.go | Fixes element ref generation and adds benchmark scenarios for negative queries. |
| README.md | Documents negative query syntax, examples, and expected behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+616
to
+620
| dSet := tokenSet(descTokens) | ||
| for _, nt := range negativeTokens { | ||
| if dSet[nt] { | ||
| return true | ||
| } |
|
|
||
| inNegative := false | ||
| for _, tok := range tokens { | ||
| if negativeTriggers[tok] { |
Comment on lines
+219
to
+220
| for _, m := range result.Matches { | ||
| if m.Ref == "e0" { |
Chetnapadhi
force-pushed
the
feat/negative-matching
branch
from
April 17, 2026 05:55
1f74041 to
f89759e
Compare
luigi-agosti
approved these changes
Apr 22, 2026
luigi-agosti
left a comment
Contributor
There was a problem hiding this comment.
@Chetnapadhi thanks, I'm going to do a follow up on this to fix a couple of things
luigi-agosti
added a commit
that referenced
this pull request
Apr 24, 2026
feat: support negative matching in queries
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR implements support for negative matching in queries, enabling expressions such as "button not submit", "link without logout", and "input excluding email".
Changes
Tests
Validation
Notes
Fixes #24