Skip to content

Commit a1d1776

Browse files
committed
fix: suggest query and docker-compose pgvector image
1 parent 8c34130 commit a1d1776

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

docker-compose.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
services:
22
postgres:
3-
image: postgres:16
3+
image: pgvector/pgvector:pg16
44
ports:
55
- 5433:5432
66
environment:

store/postgres/entity_search_repository.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,12 @@ func (r *EntitySearchRepository) Suggest(ctx context.Context, ns *namespace.Name
5959
limit = 5
6060
}
6161

62-
query := `SELECT DISTINCT name FROM entities
62+
query := `SELECT name FROM (
63+
SELECT name, similarity(name, $2) AS sim FROM entities
6364
WHERE namespace_id = $1 AND valid_to IS NULL AND name % $2
64-
ORDER BY similarity(name, $2) DESC
65-
LIMIT $3`
65+
ORDER BY sim DESC
66+
LIMIT $3
67+
) sub`
6668

6769
var names []string
6870
if err := r.client.SelectContext(ctx, &names, query, ns.ID, text, limit); err != nil {

0 commit comments

Comments
 (0)