Skip to content

feat: hybrid search with semantic ranking via pgvector - #35

Merged
Smasduq merged 1 commit into
mainfrom
feat/hybrid-search
Jul 28, 2026
Merged

feat: hybrid search with semantic ranking via pgvector#35
Smasduq merged 1 commit into
mainfrom
feat/hybrid-search

Conversation

@Smasduq

@Smasduq Smasduq commented Jul 28, 2026

Copy link
Copy Markdown
Member
  • Add app/services/hybrid_search.py with:
    • semantic_search(): pgvector cosine similarity query against media_analysis.caption_embedding joined to videos, returns [(video_id, similarity_score)] ranked by <=> distance
    • merge_search_results(): pure function merging keyword IDs and semantic scores with KEYWORD_BOOST=1.0 so exact matches always rank above semantic-only hits; deduplicates by video_id
    • Lazy-loaded sentence-transformers model singleton
  • Extend GET /api/v1/users/search with mode param (hybrid/keyword/semantic):
    • hybrid (default): runs both keyword and semantic, merges via merge_search_results, deduplicates, sorts by final score desc
    • keyword: existing ILIKE search only (no change to logic)
    • semantic: pgvector-only search
    • Semantic failures are caught and logged, keyword results still returned
  • Existing keyword logic in crud/video.py is completely untouched

- Add app/services/hybrid_search.py with:
  - semantic_search(): pgvector cosine similarity query against
    media_analysis.caption_embedding joined to videos, returns
    [(video_id, similarity_score)] ranked by <=> distance
  - merge_search_results(): pure function merging keyword IDs
    and semantic scores with KEYWORD_BOOST=1.0 so exact matches
    always rank above semantic-only hits; deduplicates by video_id
  - Lazy-loaded sentence-transformers model singleton
- Extend GET /api/v1/users/search with mode param (hybrid/keyword/semantic):
  - hybrid (default): runs both keyword and semantic, merges via
    merge_search_results, deduplicates, sorts by final score desc
  - keyword: existing ILIKE search only (no change to logic)
  - semantic: pgvector-only search
  - Semantic failures are caught and logged, keyword results still returned
- Existing keyword logic in crud/video.py is completely untouched
@vercel

vercel Bot commented Jul 28, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
monteeq-gjvd Ready Ready Preview, Comment Jul 28, 2026 1:57pm
monteeq-nextjs Ready Ready Preview, Comment Jul 28, 2026 1:57pm

@Smasduq
Smasduq merged commit fab5e5b into main Jul 28, 2026
3 checks passed
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