Compare commits

...

6 Commits

Author SHA1 Message Date
Thuc Pham 0252c1659a fix: try not uuid 2024-10-08 07:25:33 +07:00
Thuc Pham 1e68fc71c3 fix: test 2024-10-08 07:17:40 +07:00
Thuc Pham 3d5c7de0ae fix: test 2024-10-08 07:08:02 +07:00
Thuc Pham 4f6b38b15c fix: update test 2024-10-08 07:03:01 +07:00
Thuc Pham 75a47d805e Create serious-ears-tap.md 2024-10-08 06:52:57 +07:00
Thuc Pham 396b1d92b1 fix: use UUID when inserting nodes in postgres 2024-10-08 06:48:14 +07:00
3 changed files with 14 additions and 4 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"llamaindex": patch
---
fix: use UUID when inserting nodes in postgres
@@ -1,4 +1,5 @@
/* eslint-disable turbo/no-undeclared-env-vars */
import { UUIDFromString } from "@llamaindex/core/utils";
import { config } from "dotenv";
import { Document, VectorStoreQueryMode } from "llamaindex";
import { PGVectorStore } from "llamaindex/vector-store/PGVectorStore";
@@ -60,7 +61,7 @@ await test("simple node", async (t) => {
const dimensions = 3;
const schemaName =
"llamaindex_vector_store_test_" + Math.random().toString(36).substring(7);
const nodeId = "5bb16627-f6c0-459c-bb18-71642813ef21";
const nodeId = "document_id_1";
const node = new Document({
text: "hello world",
id_: nodeId,
@@ -78,6 +79,7 @@ await test("simple node", async (t) => {
await vectorStore.add([node]);
const insertedNodeId = UUIDFromString(nodeId);
{
const result = await vectorStore.query({
mode: VectorStoreQueryMode.DEFAULT,
@@ -85,16 +87,18 @@ await test("simple node", async (t) => {
queryEmbedding: [1, 2, 3],
});
const actualJSON = result.nodes![0]!.toJSON();
assert.deepStrictEqual(actualJSON, {
...node.toJSON(),
id_: insertedNodeId,
hash: actualJSON.hash,
metadata: actualJSON.metadata,
});
assert.deepStrictEqual(result.ids, [nodeId]);
assert.deepStrictEqual(result.ids, [insertedNodeId]);
assert.deepStrictEqual(result.similarities, [1]);
}
await vectorStore.delete(nodeId);
await vectorStore.delete(insertedNodeId);
{
const result = await vectorStore.query({
@@ -20,6 +20,7 @@ import type { BaseEmbedding } from "@llamaindex/core/embeddings";
import { DEFAULT_COLLECTION } from "@llamaindex/core/global";
import type { BaseNode, Metadata } from "@llamaindex/core/schema";
import { Document, MetadataMode } from "@llamaindex/core/schema";
import { UUIDFromString } from "@llamaindex/core/utils";
// todo: create adapter for postgres client
function fromVercelPool(client: VercelPool): IsomorphicDB {
@@ -293,7 +294,7 @@ export class PGVectorStore
private getDataToInsert(embeddingResults: BaseNode<Metadata>[]) {
return embeddingResults.map((node) => {
const id: any = node.id_.length ? node.id_ : null;
const id: any = node.id_.length ? UUIDFromString(node.id_) : null;
const meta = node.metadata || {};
if (!meta.create_date) {
meta.create_date = new Date();