Source identity
| Field | Recorded value |
|---|---|
| Source type | GitHub source |
| Original record | Janady13/missionmatch / internal/integration/retrieval_snippet_integration_test.go |
| Date | Not specified in source |
| Repository | Janady13/missionmatch |
| Revision | 720d47fae476b0d38477ae4401697d372b1ea2bc |
| Branch | feature/opportunity-to-outcome |
| Path or archive member | internal/integration/retrieval_snippet_integration_test.go |
| Original SHA-256 | 50c62c8edbc3951c0832cf9244a3533703020f5241c53ad7a53a6dad260351f9 |
| Git blob SHA | d98d969e3e3447a91aabbf555de5bd31b3101f6e |
| Reading-copy SHA-256 | 50c62c8edbc3951c0832cf9244a3533703020f5241c53ad7a53a6dad260351f9 |
Every recorded occurrence
These 12 records contain identical original source bytes. Their paths and revisions remain part of the archive.
| Original record | Branch or archive | Revision / identifier | Original location |
|---|---|---|---|
| Janady13/missionmatch / internal/integration/retrieval_snippet_integration_test.go | feature/opportunity-to-outcome | 720d47fae476b0d38477ae4401697d372b1ea2bc | Open original |
| Janady13/missionmatch / internal/integration/retrieval_snippet_integration_test.go | collision-deconfliction | 4ee5a09972608ed89f8377c6665542d5f450f0a6 | Open original |
| Janady13/missionmatch / internal/integration/retrieval_snippet_integration_test.go | m5-price-to-win | 41000ad30fff4129fdaf5ec84e15ba14c27d4890 | Open original |
| Janady13/missionmatch / internal/integration/retrieval_snippet_integration_test.go | master | 1e9249840a4302ec82e123b9c9cb6f75badea3e4 | Open original |
| Janady13/missionmatch / internal/integration/retrieval_snippet_integration_test.go | mag-substrate | b82c7100a492dec67dfd1eda6b3f53def859be35 | Open original |
| Janady13/missionmatch / internal/integration/retrieval_snippet_integration_test.go | time-to-fill-survival | b66e1e505863d4f17741a4b9ede73509e45bd6c6 | Open original |
| Janady13/missionmatch / internal/integration/retrieval_snippet_integration_test.go | graphrag-foundation | b0ddeb9f633fd138d09309d1a17b7d13bc3a67f7 | Open original |
| Janady13/missionmatch / internal/integration/retrieval_snippet_integration_test.go | presentation-readiness | eb574acaa29d71ce4d0f852572e87c275c79fdb7 | Open original |
| Janady13/missionmatch / internal/integration/retrieval_snippet_integration_test.go | vendor-intelligence | fe9796a19c261951d3f2565206c0c1b5ac294465 | Open original |
| Janady13/missionmatch / internal/integration/retrieval_snippet_integration_test.go | phase2-connectors | e038d4c687aec16f8bd9bc4d907eea14d91f8704 | Open original |
| Janady13/missionmatch / internal/integration/retrieval_snippet_integration_test.go | feature/aioe-upgrade | 2178e7298d0e5d9af83afa12402fd587f0ba6ed8 | Open original |
| Janady13/missionmatch / internal/integration/retrieval_snippet_integration_test.go | capture-readiness | bae6af7cb2997e819174a9e9cfff5e16067a1975 | Open original |
Recovered source transcript
Download complete source text ↓116 lines · 4.8 KB
//go:build integration
// Snippet on the hit, exercised against a REAL Postgres with pgvector, full text, and RLS in force. It
// proves the added ts_headline snippet expression on the hybrid retrieval query: a candidate seeded with a
// distinctive headline term, retrieved under RLS with that term as the text query, comes back with a non
// empty Snippet that contains the matched term, so the faithfulness gate and the narration can cite WHY the
// candidate matched, the matched TEXT, not only the name. It also proves the degrade contract: a pure
// semantic query (an empty text query, so an empty tsquery) still returns hits through the vector arm with
// an empty, no highlight snippet and no error. The snippet is built over the SAME text the search_tsv is
// built from and bound to the SAME tsquery the full text leg already uses, so it never diverges from the
// query that produced the match. This tests the query directly via dbgen with a deterministic embedding, so
// it needs no inference client, exactly like the sibling hybrid search tests.
package integration
import (
"context"
"strings"
"testing"
"github.com/google/uuid"
"github.com/jackc/pgx/v5"
"github.com/pgvector/pgvector-go"
"github.com/missionworkforce/missionmatch/internal/platform/database/dbgen"
"github.com/missionworkforce/missionmatch/internal/platform/embeddings"
)
func TestHybridSearchSnippetOnHit(t *testing.T) {
orgA := seedOrg(t)
emb := embeddings.NewDeterministic(384)
// A distinctive headline term that the snippet must surface. It lives in the headline, one of the three
// fields the search_tsv (and the matching ts_headline source text) is built from in migration 0002.
const term = "cryptanalysis"
seed := func(name, headline string) uuid.UUID {
vec, _ := emb.Embed(context.Background(), name+" "+headline)
pv := pgvector.NewVector(vec)
hn := headline
c, err := dbgen.New(migrator).CreateCandidate(context.Background(), dbgen.CreateCandidateParams{
OrganizationID: orgA, FullName: name, Headline: &hn, ClearanceLevel: "top_secret",
ClearancePoly: "none", ClearanceStatus: "active", Available: true, ResumeEmbedding: &pv,
})
if err != nil {
t.Fatalf("seed candidate %q: %v", name, err)
}
return c.ID
}
wantID := seed("Alice Analyst", "Senior cryptanalysis lead for SIGINT collection")
seed("Bob Builder", "Kubernetes and AWS platform engineer")
// A text matching query: the FTS leg matches Alice on the term, so her snippet must surface it.
var rows []dbgen.SearchCandidatesHybridRow
qv := pgvector.NewVector(mustEmbed(emb, term))
err := appDB.RunInTenantTx(ctxOrg(orgA), func(ctx context.Context, tx pgx.Tx) error {
if _, e := tx.Exec(ctx, "SET LOCAL hnsw.ef_search = 200"); e != nil {
return e
}
var e error
rows, e = dbgen.New(tx).SearchCandidatesHybrid(ctx, dbgen.SearchCandidatesHybridParams{
Column1: qv, Limit: 10, WebsearchToTsquery: term,
})
return e
})
if err != nil {
t.Fatalf("hybrid search with snippet failed: %v", err)
}
var found *dbgen.SearchCandidatesHybridRow
for i := range rows {
if rows[i].ID == wantID {
found = &rows[i]
}
if rows[i].OrganizationID != orgA {
t.Fatalf("hybrid search leaked a foreign tenant row: %s", rows[i].OrganizationID)
}
}
if found == nil {
t.Fatalf("the term matching candidate %s was not retrieved for query %q", wantID, term)
}
if strings.TrimSpace(found.Snippet) == "" {
t.Fatalf("the text matching hit has an empty snippet; the matched span was not attached")
}
if !strings.Contains(strings.ToLower(found.Snippet), term) {
t.Fatalf("the snippet %q does not contain the matched term %q", found.Snippet, term)
}
// The degrade contract: a pure semantic query (an empty text query yields an empty tsquery) must still
// return hits through the vector arm, with an empty, no highlight snippet, and no error. ts_headline on an
// empty tsquery returns an unhighlighted head, never an error, so an empty snippet is a valid result.
var semRows []dbgen.SearchCandidatesHybridRow
err = appDB.RunInTenantTx(ctxOrg(orgA), func(ctx context.Context, tx pgx.Tx) error {
if _, e := tx.Exec(ctx, "SET LOCAL hnsw.ef_search = 200"); e != nil {
return e
}
var e error
semRows, e = dbgen.New(tx).SearchCandidatesHybrid(ctx, dbgen.SearchCandidatesHybridParams{
Column1: qv, Limit: 10, WebsearchToTsquery: "",
})
return e
})
if err != nil {
t.Fatalf("pure semantic (empty query) hybrid search must not error, got: %v", err)
}
if len(semRows) == 0 {
t.Fatal("pure semantic search returned no rows; the vector arm should still recall the seeded candidates")
}
for _, r := range semRows {
if r.OrganizationID != orgA {
t.Fatalf("semantic search leaked a foreign tenant row: %s", r.OrganizationID)
}
if strings.TrimSpace(r.Snippet) != "" {
t.Fatalf("a pure semantic hit must carry an empty snippet (no tsquery to highlight), got %q for %s", r.Snippet, r.FullName)
}
}
}