Skip to content

feat(search): bounded operator-intent query shaping for long prompts (#303 slice A) - #315

Merged
hurttlocker merged 1 commit into
mainfrom
feat/303-operator-query-shaping
Mar 11, 2026
Merged

hurttlocker merged 1 commit into
mainfrom
feat/303-operator-query-shaping

Conversation

@hurttlocker

Copy link
Copy Markdown
Owner

What this does

Implements #303 slice A as a bounded retrieval-only improvement: long operator workflow prompts are query-shaped before retrieval to reduce answer-contract/transport boilerplate noise.

This slice is intentionally narrow and dependency-safe.

Problem / Context

Long workflow prompts (especially operator/heartbeat style prompts) often include high-noise boilerplate (current time, reply HEARTBEAT_OK, session wrappers, etc.).

That noise can dilute retrieval query quality and make top results less focused.

Issue: #303

How it works

Retrieval-only query shaping

In search.Engine.Search:

  • keep rawQuery intact
  • derive retrievalQuery via shapeOperatorIntentQuery(rawQuery) only when prompt is long and operator-scaffold cues are present
  • use retrievalQuery for search + ranking filters only

Guardrails (bounded behavior)

Shaping applies only when all are true:

  • query length >= 120 chars
  • token count >= 18
  • cue/scaffold present (operator/workflow/session/format markers)

Then it:

  • strips known boilerplate tokens
  • caps shaped query to 40 tokens
  • no-op fallback when shaping would be too destructive

Debug/telemetry visibility

When --explain is enabled, each result now includes:

  • explain.query_shape.raw
  • explain.query_shape.shaped
  • explain.query_shape.applied
  • explain.query_shape.removed_tokens
  • explain.query_shape.reason

This provides explicit raw-vs-shaped comparison for operator debugging/evidence.

Files changed

  • internal/search/search.go
  • internal/search/query_shape_test.go (new)

Testing done

Exact commands run:

  1. go test ./internal/search -run 'QueryShape|SearchExplain_AttachesQueryShape|SearchExplain' -count=1
  2. go test ./...

Screenshots / before-after

Terminal/JSON behavior change:

  • search --explain --json now surfaces query_shape when shaping is applied.

Breaking changes / risks

Breaking changes: None.

Concise risk note:

  • Main risk is over-shaping/false-positive shaping on atypical long prompts.
  • Guardrails + no-op fallback + deterministic tests are included to keep blast radius narrow.
  • No ranking-model rewrites and no actionability/reason-lane changes in this PR.

Explicit out-of-scope (kept for later slices)

Merge notes

@hurttlocker
hurttlocker merged commit 997ed14 into main Mar 11, 2026
4 checks passed
@hurttlocker
hurttlocker deleted the feat/303-operator-query-shaping branch March 21, 2026 01:27
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.

1 participant