You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"CREATE INDEX IF NOT EXISTS document_vector_index ON documents USING hnsw (embedding public.vector_cosine_ops)"
2912
-
)
2913
-
)
2914
-
awaitconn.execute(
2915
-
text(
2916
-
"CREATE INDEX IF NOT EXISTS document_search_index ON documents USING gin (to_tsvector('english', content))"
2917
-
)
2918
-
)
2919
-
# Document Chuck Indexes
2920
-
awaitconn.execute(
2921
-
text(
2922
-
"CREATE INDEX IF NOT EXISTS chucks_vector_index ON chunks USING hnsw (embedding public.vector_cosine_ops)"
2923
-
)
2924
-
)
2925
-
awaitconn.execute(
2926
-
text(
2927
-
"CREATE INDEX IF NOT EXISTS chucks_search_index ON chunks USING gin (to_tsvector('english', content))"
2928
-
)
2929
-
)
2930
-
# pg_trgm indexes for efficient ILIKE '%term%' searches on titles
2931
-
# Critical for document mention picker (@mentions) to scale
2932
-
awaitconn.execute(
2933
-
text(
2934
-
"CREATE INDEX IF NOT EXISTS idx_documents_title_trgm ON documents USING gin (title gin_trgm_ops)"
2935
-
)
2936
-
)
2937
-
# B-tree index on search_space_id for fast filtering
2938
-
awaitconn.execute(
2939
-
text(
2940
-
"CREATE INDEX IF NOT EXISTS idx_documents_search_space_id ON documents (search_space_id)"
2941
-
)
2942
-
)
2943
-
# Covering index for "recent documents" query - enables index-only scan
2944
-
awaitconn.execute(
2945
-
text(
2946
-
"CREATE INDEX IF NOT EXISTS idx_documents_search_space_updated ON documents (search_space_id, updated_at DESC NULLS LAST) INCLUDE (id, title, document_type)"
2947
-
)
2931
+
# (index_name, table, CREATE statement). Built with CONCURRENTLY so an index
2932
+
# build only takes a non-blocking ShareUpdateExclusiveLock — ingestion
2933
+
# INSERT/UPDATE on documents/chunks keep flowing while the index builds, and a
2934
+
# slow build can never freeze the FastAPI lifespan or block writers.
"CREATE INDEX CONCURRENTLY IF NOT EXISTS document_vector_index ON documents USING hnsw (embedding public.vector_cosine_ops)",
2940
+
),
2941
+
(
2942
+
"document_search_index",
2943
+
"documents",
2944
+
"CREATE INDEX CONCURRENTLY IF NOT EXISTS document_search_index ON documents USING gin (to_tsvector('english', content))",
2945
+
),
2946
+
(
2947
+
"chucks_vector_index",
2948
+
"chunks",
2949
+
"CREATE INDEX CONCURRENTLY IF NOT EXISTS chucks_vector_index ON chunks USING hnsw (embedding public.vector_cosine_ops)",
2950
+
),
2951
+
(
2952
+
"chucks_search_index",
2953
+
"chunks",
2954
+
"CREATE INDEX CONCURRENTLY IF NOT EXISTS chucks_search_index ON chunks USING gin (to_tsvector('english', content))",
2955
+
),
2956
+
# pg_trgm index for efficient ILIKE '%term%' searches on titles — critical
2957
+
# for the document mention picker (@mentions) to scale.
2958
+
(
2959
+
"idx_documents_title_trgm",
2960
+
"documents",
2961
+
"CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_documents_title_trgm ON documents USING gin (title gin_trgm_ops)",
2962
+
),
2963
+
(
2964
+
"idx_documents_search_space_id",
2965
+
"documents",
2966
+
"CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_documents_search_space_id ON documents (search_space_id)",
2967
+
),
2968
+
# Covering index for "recent documents" query — enables index-only scan.
2969
+
(
2970
+
"idx_documents_search_space_updated",
2971
+
"documents",
2972
+
"CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_documents_search_space_updated ON documents (search_space_id, updated_at DESC NULLS LAST) INCLUDE (id, title, document_type)",
0 commit comments