feat(db): add HNSW index on asset_embeddings and natural sort collation on assets.name

- Add HNSW index on asset_embeddings.embedding using vector_cosine_ops (m=16,
  ef_construction=64) with hnsw.iterative_scan=relaxed_order for efficient
  filtered ANN queries
- Create ICU numeric collation and alter assets.name column to use it for
  natural sort (file2 < file10 instead of lexicographic ordering)
- Add B-tree index on assets.name with numeric collation for sort performance
- Add schema @@index annotations to match migration index names
- Add 7 tests verifying natural sort behaviour in both AssetService.listChildren
  and SearchService.search (Prisma ORM and raw-SQL paths)
This commit is contained in:
yiling
2026-05-29 15:18:31 +08:00
parent 840cf87728
commit 048028007e
6 changed files with 234 additions and 0 deletions
+2
View File
@@ -406,6 +406,7 @@ model Asset {
@@index([sortIndex])
@@index([isDeleted])
@@index([deletedAt])
@@index([name], name: "assets_name_idx")
@@index([nameNgram], type: Gin)
@@unique([parentId, targetId], name: "parentIdTargetId")
}
@@ -494,6 +495,7 @@ model AssetEmbedding {
assetId String @map("asset_id")
asset Asset @relation("AssetToEmbedding", fields: [assetId], references: [id], onDelete: Cascade)
@@index([embedding], name: "AssetEmbedding_embedding_idx")
@@map("asset_embeddings")
}