Skip to content

Commit 0bc9388

Browse files
Update vectorscale section to include L2 distance (timescale#3598)
Co-authored-by: Iain Cox <[email protected]>
1 parent 5ee8610 commit 0bc9388

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

ai/sql-interface-for-pgvector-and-timescale-vector.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,20 @@ You can read more about it in
107107
[How We Made PostgreSQL as Fast as Pinecone for Vector Data](https://www.timescale.com/blog/how-we-made-postgresql-as-fast-as-pinecone-for-vector-data/).
108108

109109

110-
To create an index named `document_embedding_idx` on table `document_embedding` having a vector column named `embedding`, run:
110+
To create an index named `document_embedding_idx` on table `document_embedding` having a vector column named `embedding`, with cosine distance metric, run:
111111
```sql
112-
CREATE INDEX document_embedding_idx ON document_embedding
113-
USING diskann (embedding);
112+
CREATE INDEX document_embedding_cos_idx ON document_embedding
113+
USING diskann (embedding vector_cosine_ops);
114114
```
115115

116-
StreamingDiskANN indexes only support cosine distance at this time, so you should use the `<=>` operator in your queries.
116+
Since this index uses cosine distance, you should use the `<=>` operator in your queries. StreamingDiskANN also supports L2 distance:
117+
```sql
118+
CREATE INDEX document_embedding_l2_idx ON document_embedding
119+
USING diskann (embedding vector_l2_ops);
120+
```
121+
For L2 distance, use the `<->` operator in queries.
117122

118-
This creates the index with smart defaults for all the index parameters. These should be the right value for most cases. But if you want to delve deeper, the available parameters are below.
123+
These examples create the index with smart defaults for all parameters not listed. These should be the right values for most cases. But if you want to delve deeper, the available parameters are below.
119124

120125
#### StreamingDiskANN index build-time parameters
121126

0 commit comments

Comments
 (0)