Skip to content

Commit

Permalink
Changed <-> to <=> in the SELECT query
Browse files Browse the repository at this point in the history
The SQL is comparing the parameter vector with the embeddings column using "<=>" operator. "<->" is used for vector distance calculations. The change now matches with the code in the Python package.
  • Loading branch information
JT-Dev-215 authored May 3, 2024
1 parent f1862cc commit c587e5f
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/core/src/storage/vectorStore/PGVectorStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ export class PGVectorStore implements VectorStore {
options?: any,
): Promise<VectorStoreQueryResult> {
// TODO QUERY TYPES:
// Distance: SELECT embedding <-> $1 AS distance FROM items;
// Distance: SELECT embedding <=> $1 AS distance FROM items;
// Inner Product: SELECT (embedding <#> $1) * -1 AS inner_product FROM items;
// Cosine Sim: SELECT 1 - (embedding <=> $1) AS cosine_similarity FROM items;

Expand All @@ -273,7 +273,7 @@ export class PGVectorStore implements VectorStore {

const sql = `SELECT
v.*,
embeddings <-> $1 s
embeddings <=> $1 s
FROM ${this.schemaName}.${this.tableName} v
${where}
ORDER BY s
Expand Down

0 comments on commit c587e5f

Please sign in to comment.