pgvector Hybrid Search Query and Index
Write the Postgres side of hybrid search for a document set. This is the schema, index, and query — not a product strategy. CORPUS Documents: [WHAT THEY ARE] Approx rows now / in a year: [N / N] Embedding model and dimensions: [MODEL, DIMS] Distance: [COSINE | L2 | INNER PRODUCT] Filters every query must honor: [TENANT_ID, LANGUAGE, UPDATED_AFTER, ACL] Need keyword match as well as vectors: [YES | NO] Latency budget: [MS] at [QPS] DELIVER SQL 1) Table: id, tenant_id, content, metadata jsonb, embedding vector(DIMS), tsv tsvector, updated_at. Constraints and the trigger or generated column that keeps tsv current. 2) Index choice: HNSW vs IVFFlat for this scale, with the CREATE INDEX statement, the opclass that matches the distance, and the build-time settings you would start with. Say when you would REINDEX. 3) The query: a hybrid of vector distance and ts_rank, filtered by tenant_id BEFORE the distance scan, returning id, score, and a snippet. Explain the CTE or subquery order and why the filter cannot be applied after the limit. 4) A parameter block: how many candidates to fetch before the final LIMIT, and how you would tune it. 5) A note on iterative scans / max_scan_tuples behavior if the filter is selective, in plain language. 6) Three EXPLAIN assumptions: what a good plan looks like, and two plans that mean the index is being ignored. Do not embed in the database. Embeddings arrive as parameters. Do not suggest a second vector database unless the row or QPS numbers make Postgres a bad fit, and if you do, say the threshold.
🌟 Example Output / Preview
Prompt Metadata
Primary Use Cases:
- •Legacy code modernization & technical refactoring
- •Full-stack layout generation & component structuring
- •CI/CD workflow automation & unit/E2E testing suites
Associated Tags:
💡 Pro Tips & Advice
1. Use bracketed items: Be sure to fill out all [PLACEHOLDER] elements with specific details before sending the prompt to the AI model.
2. Adjust temperature: For creative tasks, set AI temperature higher (e.g., 0.8), or lower (e.g., 0.2) for strict coding/technical tasks.
🔗 Related AI Prompts
Full SaaS Landing Page Build Spec (SEO + Conversion)
You are a Staff Product Designer + Frontend Engineer + SEO strategist. Build a complete, production-ready marketing landing page f...
SaaS Analytics Dashboard Full Build Spec
You are a Principal Product Designer + Frontend Lead. Design and specify a complete [LIGHT | DARK] analytics dashboard for [PRODUC...
SaaS Admin Panel Dashboard Build Spec
Design a full internal Admin Dashboard for [PRODUCT_NAME] used by [ADMIN_ROLE: support | ops | super-admin]. --- 🎯 CONTEXT Adm...