From e74fe88342d9d254f79a8d76ecc2b2859cb80857 Mon Sep 17 00:00:00 2001
From: JT-Dev-215 <65767260+JT-Dev-215@users.noreply.github.com>
Date: Sat, 4 May 2024 00:10:36 +0700
Subject: [PATCH] fix: change <-> to <=> in the SELECT query (#804)

Co-authored-by: Alex Yang <himself65@outlook.com>
---
 .changeset/silly-horses-carry.md                       | 5 +++++
 packages/core/src/storage/vectorStore/PGVectorStore.ts | 4 ++--
 2 files changed, 7 insertions(+), 2 deletions(-)
 create mode 100644 .changeset/silly-horses-carry.md

diff --git a/.changeset/silly-horses-carry.md b/.changeset/silly-horses-carry.md
new file mode 100644
index 000000000..2d1b13dcd
--- /dev/null
+++ b/.changeset/silly-horses-carry.md
@@ -0,0 +1,5 @@
+---
+"llamaindex": patch
+---
+
+fix: change <-> to <=> in the SELECT query
diff --git a/packages/core/src/storage/vectorStore/PGVectorStore.ts b/packages/core/src/storage/vectorStore/PGVectorStore.ts
index bc5954245..b48848577 100644
--- a/packages/core/src/storage/vectorStore/PGVectorStore.ts
+++ b/packages/core/src/storage/vectorStore/PGVectorStore.ts
@@ -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;
 
@@ -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 
-- 
GitLab