Skip to content

Commit b591c36

Browse files
hnwyllmmlongdafeng
authored andcommitted
Enhance articles table with indexing for search
Added full-text and vector indexing to articles table for improved search capabilities.
1 parent f864aac commit b591c36

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

README_CN.md

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -276,14 +276,13 @@ print(f"\nDeleted collection '{collection_name}'")
276276
```sql
277277
-- Create table with vector column
278278
CREATE TABLE articles (
279-
id INT PRIMARY KEY,
280-
title TEXT,
281-
content TEXT,
282-
embedding VECTOR(384)
283-
);
284-
285-
-- Create vector index for fast similarity search
286-
CREATE INDEX idx_vector ON articles USING VECTOR (embedding);
279+
id INT PRIMARY KEY,
280+
title TEXT,
281+
content TEXT,
282+
embedding VECTOR(384),
283+
FULLTEXT INDEX idx_fts(content) WITH PARSER ik,
284+
VECTOR INDEX idx_vec (embedding) WITH(DISTANCE=l2, TYPE=hnsw, LIB=vsag)
285+
) ORGANIZATION = HEAP;
287286

288287
-- Insert documents with embeddings
289288
-- Note: Embeddings should be pre-computed using your embedding model
@@ -298,11 +297,11 @@ VALUES
298297
SELECT
299298
title,
300299
content,
301-
embedding <-> '[query_embedding]' AS vector_distance,
300+
l2_distance(embedding, '[query_embedding]') AS vector_distance,
302301
MATCH(content) AGAINST('your keywords' IN NATURAL LANGUAGE MODE) AS text_score
303302
FROM articles
304303
WHERE MATCH(content) AGAINST('your keywords' IN NATURAL LANGUAGE MODE)
305-
ORDER BY vector_distance ASC, text_score DESC
304+
ORDER BY vector_distance APPROXIMATE
306305
LIMIT 10;
307306
```
308307

0 commit comments

Comments
 (0)