-
-
Notifications
You must be signed in to change notification settings - Fork 88
Add HNSW vector indexes for tasks and tickets #208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| CREATE OR REPLACE FUNCTION get_similar_tasks( | ||
| query_embedding vector(768), | ||
| match_count INT DEFAULT 3 | ||
| ) | ||
| RETURNS TABLE ( | ||
| task_id UUID, | ||
| title TEXT, | ||
| description TEXT, | ||
| similarity FLOAT | ||
| ) AS $$ | ||
| BEGIN | ||
| RETURN QUERY | ||
| SELECT | ||
| t.id AS task_id, | ||
| t.title, | ||
| t.description, | ||
| 1 - (t.description_embedding <=> query_embedding) AS similarity | ||
| FROM tasks t | ||
| WHERE t.description_embedding IS NOT NULL | ||
| ORDER BY t.description_embedding <=> query_embedding | ||
| LIMIT match_count; | ||
| END; | ||
| $$ LANGUAGE plpgsql; | ||
|
|
||
|
|
||
| CREATE OR REPLACE FUNCTION get_similar_tickets( | ||
| query_embedding vector(768), | ||
| match_count INT DEFAULT 3 | ||
| ) | ||
| RETURNS TABLE ( | ||
| ticket_id UUID, | ||
| title TEXT, | ||
| description TEXT, | ||
| similarity FLOAT | ||
| ) AS $$ | ||
| BEGIN | ||
| RETURN QUERY | ||
| SELECT | ||
| tk.id AS ticket_id, | ||
| tk.title, | ||
| tk.description, | ||
| 1 - (tk.description_embedding <=> query_embedding) AS similarity | ||
| FROM tickets tk | ||
| WHERE tk.description_embedding IS NOT NULL | ||
| ORDER BY tk.description_embedding <=> query_embedding | ||
| LIMIT match_count; | ||
| END; | ||
| $$ LANGUAGE plpgsql; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| CREATE INDEX IF NOT EXISTS idx_tasks_embedding | ||
| ON tasks USING hnsw (description_embedding vector_cosine_ops); | ||
|
|
||
| CREATE INDEX IF NOT EXISTS idx_tickets_embedding | ||
| ON tickets USING hnsw (description_embedding vector_cosine_ops); | ||
|
Comment on lines
+1
to
+5
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: # Check if there are any version constraints or documentation in the repo
git ls-files | grep -E "(requirements|docker|package.json|supabase|version)" | head -20Repository: AOSSIE-Org/Ell-ena Length of output: 1081 🌐 Web query:
💡 Result: pgvector HNSW index support (and major HNSW-related changes) by version:
Sources: pgvector PGXN changelog (canonical per-version list), plus PostgreSQL.org release announcements for 0.6.0 and 0.8.0. [1][2][3] References: Citations:
🌐 Web query:
💡 Result:
PGXN’s source archive listing also shows v0.1.2 as the earliest available pgvector release in that archive, so it’s not possible (from PGXN alone) to verify whether it was introduced in v0.1.0 or v0.1.1. [2] Sources: [1] [2] 🏁 Script executed: # Look for Supabase configuration files that might specify pgvector version
find supabase -type f -name "config.toml" -o -name "*.json" -o -name "*.md" | head -20Repository: AOSSIE-Org/Ell-ena Length of output: 206 🏁 Script executed: # Check the migration directory for context and other migrations
ls -la supabase/migrations/ | head -30Repository: AOSSIE-Org/Ell-ena Length of output: 1237 🏁 Script executed: # Look at the migration file itself and nearby migrations for version hints
cat -n supabase/migrations/20251021120000_add_hnsw_indexes.sqlRepository: AOSSIE-Org/Ell-ena Length of output: 321 🏁 Script executed: # Check if there's a .env or docker file with version constraints
cat supabase/.gitignoreRepository: AOSSIE-Org/Ell-ena Length of output: 133 🏁 Script executed: # Look for any README or docs mentioning pgvector version
find . -maxdepth 3 -name "README*" -o -name "*.md" | xargs grep -l "pgvector\|vector" 2>/dev/null | head -10Repository: AOSSIE-Org/Ell-ena Length of output: 131 🏁 Script executed: # Check README.md for pgvector or version information
cat README.md | grep -A 5 -B 5 "pgvector\|vector\|version" -i | head -50Repository: AOSSIE-Org/Ell-ena Length of output: 2343 🏁 Script executed: # Check BACKEND.md for setup or version information
cat BACKEND.md | grep -A 5 -B 5 "pgvector\|vector\|version" -i | head -50Repository: AOSSIE-Org/Ell-ena Length of output: 771 🏁 Script executed: # Look at the vector search migration to see if there are version hints
cat -n supabase/migrations/20251021090000_meeting_vector_search.sqlRepository: AOSSIE-Org/Ell-ena Length of output: 4913 🏁 Script executed: # Check the task schema migration to see when vector type is first used
cat -n supabase/migrations/20251021030000_task_schema.sql | head -80Repository: AOSSIE-Org/Ell-ena Length of output: 3184 Ensure pgvector >= 0.5.0 is deployed before applying these indexes. The migration uses Before rollout, verify the deployed SELECT extversion FROM pg_extension WHERE extname = 'vector';Expected: 0.5.0 or later. Consider adding a version check comment to the migration or documenting the minimum pgvector version requirement. 🤖 Prompt for AI Agents |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: AOSSIE-Org/Ell-ena
Length of output: 11657
🏁 Script executed:
Repository: AOSSIE-Org/Ell-ena
Length of output: 2048
Add explicit checks for embedding columns before defining vector search functions.
Lines 17–20 and 42–45 reference
description_embeddingcolumns that do not exist in the base table schemas (20251021030000_task_schema.sqland20251021040000_tickets_schema.sql). Migration20251021100000_generate_missing_embeddings.sqldoes not create these columns—it only processes meeting embeddings. This creates a hard dependency on external code (PR#166) that must be applied first; without it, these functions fail silently at runtime and the subsequent index creation in20251021120000_add_hnsw_indexes.sqlfails outright.Add guards to fail fast with a clear message:
Suggested guard to fail fast with a clear message
📝 Committable suggestion
🤖 Prompt for AI Agents