@langchain/community
Advanced tools
Comparing version 0.3.8 to 0.3.9
@@ -56,11 +56,2 @@ import type { Client } from "@libsql/client"; | ||
/** | ||
* Deletes vectors from the store. | ||
* @param {Object} params - Delete parameters. | ||
* @param {string[] | number[]} [params.ids] - The ids of the vectors to delete. | ||
* @returns {Promise<void>} | ||
*/ | ||
delete(params: { | ||
ids?: string[] | number[]; | ||
}): Promise<void>; | ||
/** | ||
* Creates a new LibSQLVectorStore instance from texts. | ||
@@ -67,0 +58,0 @@ * @param {string[]} texts - The texts to add to the store. |
@@ -70,3 +70,6 @@ import { VectorStore } from "@langchain/core/vectorstores"; | ||
const chunk = rows.slice(i, i + batchSize); | ||
const insertQueries = chunk.map((row) => `INSERT INTO ${this.table} (content, metadata, ${this.column}) VALUES (${row.content}, ${row.metadata}, vector(${row.embedding})) RETURNING id`); | ||
const insertQueries = chunk.map((row) => ({ | ||
sql: `INSERT INTO ${this.table} (content, metadata, ${this.column}) VALUES (?, ?, ?) RETURNING id`, | ||
args: [row.content, row.metadata, row.embedding], | ||
})); | ||
const results = await this.db.batch(insertQueries); | ||
@@ -100,10 +103,12 @@ for (const result of results) { | ||
const sql = ` | ||
SELECT content, metadata, vector_distance_cos(${this.column}, vector(${queryVector})) AS distance | ||
FROM vector_top_k('${this.table}_idx', vector(${queryVector}), ${k}) | ||
JOIN ${this.table} ON ${this.table}.rowid = id | ||
SELECT ${this.table}.id, ${this.table}.content, ${this.table}.metadata, vector_distance_cos(${this.table}.${this.column}, vector('${queryVector}')) AS distance | ||
FROM vector_top_k('idx_${this.table}_${this.column}', vector('${queryVector}'), ${k}) AS top_k | ||
JOIN ${this.table} ON top_k.rowid = ${this.table}.id | ||
`; | ||
const results = await this.db.execute(sql); | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
return results.rows.map((row) => { | ||
const metadata = JSON.parse(row.metadata); | ||
const doc = new Document({ | ||
id: row.id, | ||
metadata, | ||
@@ -116,19 +121,2 @@ pageContent: row.content, | ||
/** | ||
* Deletes vectors from the store. | ||
* @param {Object} params - Delete parameters. | ||
* @param {string[] | number[]} [params.ids] - The ids of the vectors to delete. | ||
* @returns {Promise<void>} | ||
*/ | ||
async delete(params) { | ||
if (!params.ids) { | ||
await this.db.execute(`DELETE FROM ${this.table}`); | ||
return; | ||
} | ||
const idsToDelete = params.ids.join(", "); | ||
await this.db.execute({ | ||
sql: `DELETE FROM ${this.table} WHERE id IN (?)`, | ||
args: [idsToDelete], | ||
}); | ||
} | ||
/** | ||
* Creates a new LibSQLVectorStore instance from texts. | ||
@@ -135,0 +123,0 @@ * @param {string[]} texts - The texts to add to the store. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5349139
132477
+ Added@types/body-parser@1.19.5(transitive)
+ Added@types/express-serve-static-core@4.19.6(transitive)
+ Added@types/qs@6.9.17(transitive)
+ Added@types/serve-static@1.15.7(transitive)
+ Added@types/yauzl@2.10.3(transitive)
+ Addedip-address@9.0.5(transitive)
+ Addednopt@5.0.0(transitive)
+ Addednpmlog@5.0.1(transitive)
+ Addedpac-proxy-agent@7.0.2(transitive)
+ Addedquerystringify@2.2.0(transitive)
+ Addedrequires-port@1.0.0(transitive)
+ Addedsmart-buffer@4.2.0(transitive)
+ Addedsocks@2.8.3(transitive)
+ Addedsocks-proxy-agent@8.0.4(transitive)
+ Addedsprintf-js@1.1.3(transitive)
+ Addedthrough@2.3.8(transitive)
+ Addedtldts-core@6.1.61(transitive)
+ Addedyauzl@2.10.0(transitive)
- Removed@types/triple-beam@1.3.5(transitive)
- Removedbare-fs@2.3.5(transitive)
- Removedbare-path@2.1.3(transitive)
- Removedbuffer-from@1.1.2(transitive)
- Removedcolor@3.2.1(transitive)
- Removedcolorspace@1.1.4(transitive)
- Removedenabled@2.0.0(transitive)
- Removedescape-string-regexp@1.0.5(transitive)
- Removedfecha@4.2.3(transitive)
- Removedfn.name@1.1.0(transitive)
- Removedis-obj@2.0.0(transitive)
- Removedkuler@2.0.0(transitive)
- Removedlangsmith@0.1.68(transitive)
- Removedp-finally@1.0.0(transitive)
- Removedpg-numeric@1.0.2(transitive)
- Removedpostgres-range@1.1.4(transitive)
- Removedshebang-command@2.0.0(transitive)
- Removedwhich@2.0.2(transitive)
Updatedlangsmith@^0.2.0