-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(community): Escape libSQL vector store inserts by using object sy…
…ntax with placeholders (#7041) Co-authored-by: jacoblee93 <[email protected]>
- Loading branch information
1 parent
4aee924
commit 7981aa9
Showing
3 changed files
with
61 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
libs/langchain-community/src/vectorstores/tests/libsql.int.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* eslint-disable no-process-env */ | ||
/* eslint-disable @typescript-eslint/no-non-null-assertion */ | ||
import { expect, test } from "@jest/globals"; | ||
import { OpenAIEmbeddings } from "@langchain/openai"; | ||
import { Document } from "@langchain/core/documents"; | ||
import { createClient } from "@libsql/client"; | ||
|
||
import { LibSQLVectorStore } from "../libsql.js"; | ||
|
||
test("can create and query", async () => { | ||
const client = createClient({ | ||
url: process.env.LIBSQL_URL!, | ||
authToken: process.env.LIBSQL_AUTH_TOKEN, | ||
}); | ||
const vectorStore = new LibSQLVectorStore( | ||
new OpenAIEmbeddings({ | ||
model: "text-embedding-3-small", | ||
dimensions: 1536, | ||
}), | ||
{ | ||
db: client, | ||
table: "documents", | ||
column: "embeddings", | ||
} | ||
); | ||
const ids = await vectorStore.addDocuments([ | ||
new Document({ | ||
pageContent: "added first page", | ||
}), | ||
new Document({ | ||
pageContent: "added second page", | ||
}), | ||
new Document({ | ||
pageContent: "added third page", | ||
}), | ||
]); | ||
const nextId = await vectorStore.addDocuments([ | ||
new Document({ | ||
pageContent: "added another first page", | ||
}), | ||
]); | ||
ids.push(nextId[0]); | ||
const results = await vectorStore.similaritySearchWithScore("added first", 4); | ||
expect(results.length).toBe(4); | ||
}); |