searcheval)searcheval is a command-line tool for benchmarking, evaluating, and tuning search relevance for pkgsite. It supports comparing standard PostgreSQL full-text keyword search (ts_rank) against Hybrid Vector Search combining keyword scoring with Vertex AI text embeddings via Reciprocal Rank Fusion (RRF).
Choose one of the following options to launch the database proxy on port 5431:
Option A: Connect to Main Dev Database (dev-discovery-db)
./private/devtools/run_cloud_sql_proxy.sh dev
Option B: Connect to Custom / Cloned Database Instance (dev-discovery-db-clone)
cloud-sql-proxy --port 5431 go-discovery:us-central1:dev-discovery-db-clone
Set your GCP project, Cloud SQL password, and connection parameters:
export GOOGLE_CLOUD_PROJECT=go-discovery export GO_DISCOVERY_DATABASE_PASSWORD=<password> export GO_DISCOVERY_DATABASE_PORT=5431 export GO_DISCOVERY_DATABASE_NAME=dev-discovery-db
eval)Runs search quality benchmarks against a curated set of ground-truth queries (golden_queries.json) and reports Mean Reciprocal Rank (MRR@5) metrics. Each cell displays the target package's 1-based Rank and its corresponding Reciprocal Rank score (1/rank), which is averaged in the summary row.
go run ./devtools/cmd/searcheval eval
Output Example:
Query | Target Package | Keyword | Vector | Hybrid ---------------------------------------------------------------------------------------------------- http router | github.com/go-chi/chi/v5 | #2 (0.500) | #6 (0.167) | #2 (0.500) structured logger | go.uber.org/zap | >5 (0.000) | #4 (0.250) | >5 (0.000) web framework | github.com/gin-gonic/gin | #1 (1.000) | #3 (0.333) | #1 (1.000) command line parser | github.com/spf13/cobra | >5 (0.000) | #2 (0.500) | #4 (0.250) orm | gorm.io/gorm | #2 (0.500) | #1 (1.000) | #1 (1.000) ---------------------------------------------------------------------------------------------------- MEAN RECIPROCAL RANK (MRR) | | 0.479 | 0.449 | 0.562
log-eval)Evaluates performance and zero-result recovery rates across unlabelled, real-world production query logs (e.g. extracted via queries_for_compare.sh or log exports). This will enable one to benchmark against real user search traffic.
# Optional: Pull fresh query logs from Cloud Logging for the last 24h ./private/devtools/cmd/search/queries_for_compare.sh 24h > fresh_24h.queries # Run comparative log evaluation go run ./devtools/cmd/searcheval -log-queries=fresh_24h.queries log-eval
Metrics Measured:
search)Runs a single search query string and displays top 10 search results side-by-side across Keyword, Pure Vector, and Hybrid RRF modes:
go run ./devtools/cmd/searcheval search "structured logger"
embed)Scans PostgreSQL for active packages (imported_by_count >= 1 AND embedding IS NULL), generates 256-dimensional text embeddings via Vertex AI (text-embedding-004), and updates search_documents.embedding in the connected database:
go run ./devtools/cmd/searcheval embed
seed)[!CAUTION] Do NOT run
searcheval seedwhile connected to Cloud SQL database proxies (dev,staging,prod).seedwrites module data into PostgreSQL and is intended ONLY for fresh local Postgres instances (localhost:5432).searchevalautomatically blocksseedwhen connected to non-standard ports unlessGO_DISCOVERY_ALLOW_SEED=trueis set.
Populates a fresh local PostgreSQL database with popular Go modules (e.g. chi, gin, zap, pgx, cobra, viper, gorm, uuid, grpc, testify, zerolog, bun, badger, bbolt, etc.) fetched directly from proxy.golang.org:
# Seed default set of 100 popular benchmark modules go run ./devtools/cmd/searcheval seed # Or seed specific custom modules go run ./devtools/cmd/searcheval seed github.com/go-chi/chi/v5@v5.0.12 github.com/gin-gonic/gin@v1.9.1
You can experiment with search scoring parameters (such as feature weights and result limits) dynamically without recompiling code:
| Flag | Description | Default | Example |
|---|---|---|---|
-text-weights | Custom ts_rank section weights (D,C,B,A) | DB default (0.1,0.2,1.0,1.0) | -text-weights="0.1,0.5,1.0,2.0" |
-popularity-weight | Exponent for package import count popularity | DB default (1.0) | -popularity-weight=0.8 |
-vector-weight | RRF vector search weight in hybrid fusion | DB default (1.0) | -vector-weight=1.5 |
-limit | Number of search results to display per engine | 10 | -limit=20 |
-queries | Path to golden queries JSON file | testdata/golden_queries.json | -queries=custom_queries.json |
Example using custom weights:
go run ./devtools/cmd/searcheval -vector-weight=1.2 -popularity-weight=0.8 eval