Repository navigation
feat(search): add hybrid FTS + pgvector job matching with OpenRouter embeddings - #112
Open
hugoalves-dev wants to merge 4 commits into
Open
hugoalves-dev wants to merge 4 commits into
hugoalves-dev wants to merge 4 commits into
Conversation
…embeddings - Flyway V37: pgvector extension and semantic_embeddings (vector(1024), FKs with cascade, content hash, model/dimensions, status, attempts, timestamps) - OpenRouter /embeddings client with batching, Matryoshka truncation, timeouts, token/cost/latency metrics - Polling sync: backfill, hash-based change detection, model switches, retries with backoff and SKIP LOCKED leases; no transaction held across HTTP calls - Hybrid searchApplications: FTS + per-user exact cosine search fused with RRF, matchedBy label, FTS-only fallback with provider cooldown - matchApplicationsToProfile tool: ranks against the user's profile documents and checks must-have terms explicitly with evidence; no similarity scores - Fix ts_rank Float->Double ClassCastException in existing FTS search - pgvector image for docker-compose, load test and Testcontainers Closes #111 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GfjfbRwirbsTBATemyhmxy
Qodana for JVM5 new problems were found
View the detailed Qodana reportTo be able to view the detailed Qodana report, you can either:
To get - name: 'Qodana Scan'
uses: JetBrains/qodana-action@v2025.3.2
with:
upload-result: trueContact Qodana teamContact us at qodana-support@jetbrains.com
|
…'s V37
main added V37__add_assistant_quota.sql, which collided with this branch's
V37 ("Found more than one migration with version 37" in SemanticSearchPostgresIT).
The MariaDB-to-PostgreSQL migrator pins the Flyway version and requires
identical table sets, so it now targets V38 and treats semantic_embeddings as
PostgreSQL-only derived data: not compared or copied, required to be empty,
rebuilt by the application's backfill after cutover.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GfjfbRwirbsTBATemyhmxy
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GfjfbRwirbsTBATemyhmxy
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.
Closes #111
The blocker, #107 (the PostgreSQL migration), is already on
main.What it does
CREATE EXTENSION vectorand a newsemantic_embeddingstable. The vector column isvector(1024). Each row has a real foreign key withON DELETE CASCADEto its application or profile document and to its user. It also stores the embedded text, its SHA-256, the model, the dimensions, a status (PENDING/READY/FAILED/EMPTY/SOURCE_ERROR), the number of attempts and timestamps. All access goes through JDBC, so Hibernate never sees thevectortype andddl-auto: validateand the H2 test schema stay unchanged.RestClientcall toPOST /embeddingswith batching and timeouts. It sendsdimensions: 1024. If the provider ignores that field, the client keeps the first 1024 values and re-normalises. That is only valid for Matryoshka-trained models such as Qwen3-Embedding, and it can be turned off in config.EmbeddingSyncService, every minute): one polling loop handles backfill, change detection, model switches and retries:FOR UPDATE SKIP LOCKED, so several instances never embed the same row twice.searchApplications: full-text search and per-user cosine search each fetch up to 50 candidates with the same user and filters. The two lists are combined with Reciprocal Rank Fusion. Each result has amatchedByfield (KEYWORD,SEMANTICorKEYWORD_AND_SEMANTIC).Go,C#) and filter-only queries stay on the existing path. Aggregates still come from plain SQL.matchApplicationsToProfile: ranks applications against the user's own Drive profile documents. It checksrequiredTerms(stack, seniority, location, work modality, salary wording) literally against the vacancy text, ignoring case and accents and respecting word boundaries, soJavadoes not matchJavaScript. It returns evidence snippets and ranks only, never distances or percentages. The system prompt now tells the model not to turn similarity into a fit score and not to invent qualifications.semantic.embeddings.{latency, tokens, cost.usd, inputs, failures}coverage,backlog,exhaustedandsource_errorsassistant.search.latency{mode}Decisions worth reviewing
MATERIALIZEDCTE scans one user's rows exactly, using the(user_id, source_type, status)index. At 1024 dimensions an HNSW index can still be added later;docs/semantic-search.mdexplains when it would be worth it.ApplicationServiceor Drive, and backfill and retries reuse the same code. The cost is up to about one minute of delay before new content becomes searchable by meaning, while keyword search covers it immediately.SEMANTIC_SEARCH_DISABLED.MariaDB → PostgreSQL migrator
scripts/migrate_mariadb_to_postgresql.pypins the Flyway version and requires identical table sets on both sides. It now targets V38 and treatssemantic_embeddingsas PostgreSQL-only derived data: it is not compared or copied, it must be empty in the target, and the app's backfill rebuilds it after the cutover. The README cutover steps now say V1-V38, and a new unit test covers the exclusion.pgvector/pgvector:pg17image). V38 creates the extension unconditionally, so the app will not start without it.docker-compose.yml, the load-test workflow and Testcontainers have been switched to that image.qwen/qwen3-embedding-8bis available, what it costs, and whether it supportsdimensions. I couldn't reach OpenRouter from the build environment.APP_SEMANTIC_SEARCH_MAX_COSINE_DISTANCE=0.65is an initial value that hasn't been calibrated on real data.Bugs found while testing
ts_rank(PostgreSQLreal, which the driver returns asjava.lang.Float) toDouble. As a result, every ranked Ask ApplyWell keyword search threw aClassCastExceptionon PostgreSQL. The existing ITs missed it because they build the schema withddl-auto, so the full-text search column never exists in them.mainsince this PR opened: on a fresh PostgreSQL database,maindid not boot because the assistant quota tables from feat(assistant): add per-user daily quota and anti-flood limits #110 had no PostgreSQL migration.fb0d05fadded them asV37__add_assistant_quota.sql. That collided with this PR's V37, which broke CI, so I mergedmainin and renumbered this PR's migration to V38.Tests
MockRestServiceServer) and provider cooldown.SemanticSearchPostgresIT: runs the real Flyway chain on pgvector (Testcontainers in CI). It covers tenant isolation, model and space filtering, the distance cutoff, structured filters, keyword vs semantic results, missing embeddings, profile matching, the sync lifecycle (backfill, idempotency, re-embedding on content or model change), retries and leases, exhausted rows and cascade deletes.main, against PostgreSQL 16 + pgvector 0.6 (no Docker here): 312 tests in 56 classes pass, covering all unit tests,SemanticSearchPostgresITandJobTrackerApplicationTests. Flyway applies V37 (quota) and then V38 (embeddings). Migrator tests: 7/7./actuator/prometheus. That boot ran beforemain's quota fix, so it usedddl-auto=none.Docs:
docs/semantic-search.md🤖 Generated with Claude Code
https://claude.ai/code/session_01GfjfbRwirbsTBATemyhmxy