@langchain/google-cloud-sql-pg 0.0.2 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/LICENSE +6 -6
  3. package/README.md +1 -1
  4. package/dist/_virtual/rolldown_runtime.cjs +25 -0
  5. package/dist/chat_message_history.cjs +104 -137
  6. package/dist/chat_message_history.cjs.map +1 -0
  7. package/dist/chat_message_history.d.cts +57 -0
  8. package/dist/chat_message_history.d.ts +53 -43
  9. package/dist/chat_message_history.js +103 -133
  10. package/dist/chat_message_history.js.map +1 -0
  11. package/dist/engine.cjs +188 -242
  12. package/dist/engine.cjs.map +1 -0
  13. package/dist/engine.d.cts +138 -0
  14. package/dist/engine.d.ts +102 -80
  15. package/dist/engine.js +186 -234
  16. package/dist/engine.js.map +1 -0
  17. package/dist/index.cjs +21 -20
  18. package/dist/index.d.cts +6 -0
  19. package/dist/index.d.ts +6 -4
  20. package/dist/index.js +7 -4
  21. package/dist/indexes.cjs +96 -168
  22. package/dist/indexes.cjs.map +1 -0
  23. package/dist/indexes.d.cts +68 -0
  24. package/dist/indexes.d.ts +50 -47
  25. package/dist/indexes.js +90 -161
  26. package/dist/indexes.js.map +1 -0
  27. package/dist/loader.cjs +159 -242
  28. package/dist/loader.cjs.map +1 -0
  29. package/dist/loader.d.cts +101 -0
  30. package/dist/loader.d.ts +40 -26
  31. package/dist/loader.js +157 -237
  32. package/dist/loader.js.map +1 -0
  33. package/dist/utils/utils.cjs +36 -65
  34. package/dist/utils/utils.cjs.map +1 -0
  35. package/dist/utils/utils.js +36 -62
  36. package/dist/utils/utils.js.map +1 -0
  37. package/dist/vectorstore.cjs +438 -593
  38. package/dist/vectorstore.cjs.map +1 -0
  39. package/dist/vectorstore.d.cts +300 -0
  40. package/dist/vectorstore.d.ts +147 -130
  41. package/dist/vectorstore.js +436 -588
  42. package/dist/vectorstore.js.map +1 -0
  43. package/package.json +41 -48
  44. package/dist/utils/utils.d.ts +0 -22
  45. package/index.cjs +0 -1
  46. package/index.d.cts +0 -1
  47. package/index.d.ts +0 -1
  48. package/index.js +0 -1
@@ -1,41 +1,43 @@
1
- import { EmbeddingsInterface } from "@langchain/core/embeddings";
1
+ import { PostgresEngine } from "./engine.js";
2
+ import { BaseIndex, DistanceStrategy, QueryOptions } from "./indexes.js";
2
3
  import { MaxMarginalRelevanceSearchOptions, VectorStore } from "@langchain/core/vectorstores";
3
4
  import { Document } from "@langchain/core/documents";
4
- import { BaseIndex, DistanceStrategy, QueryOptions } from "./indexes.js";
5
- import PostgresEngine from "./engine.js";
6
- export interface PostgresVectorStoreArgs {
7
- schemaName?: string;
8
- contentColumn?: string;
9
- embeddingColumn?: string;
10
- metadataColumns?: Array<string>;
11
- idColumn?: string;
12
- distanceStrategy?: DistanceStrategy;
13
- k?: number;
14
- fetchK?: number;
15
- lambdaMult?: number;
16
- ignoreMetadataColumns?: Array<string>;
17
- metadataJsonColumn?: string;
18
- indexQueryOptions?: QueryOptions;
5
+ import { EmbeddingsInterface } from "@langchain/core/embeddings";
6
+
7
+ //#region src/vectorstore.d.ts
8
+ interface PostgresVectorStoreArgs {
9
+ schemaName?: string;
10
+ contentColumn?: string;
11
+ embeddingColumn?: string;
12
+ metadataColumns?: Array<string>;
13
+ idColumn?: string;
14
+ distanceStrategy?: DistanceStrategy;
15
+ k?: number;
16
+ fetchK?: number;
17
+ lambdaMult?: number;
18
+ ignoreMetadataColumns?: Array<string>;
19
+ metadataJsonColumn?: string;
20
+ indexQueryOptions?: QueryOptions;
19
21
  }
20
- export interface dbConfigArgs {
21
- engine: PostgresEngine;
22
- tableName: string;
23
- dbConfig?: PostgresVectorStoreArgs;
22
+ interface dbConfigArgs {
23
+ engine: PostgresEngine;
24
+ tableName: string;
25
+ dbConfig?: PostgresVectorStoreArgs;
24
26
  }
25
27
  interface VSArgs {
26
- engine: PostgresEngine;
27
- tableName: string;
28
- schemaName: string;
29
- contentColumn: string;
30
- embeddingColumn: string;
31
- metadataColumns: Array<string>;
32
- idColumn: string;
33
- distanceStrategy: DistanceStrategy;
34
- k: number;
35
- fetchK: number;
36
- lambdaMult: number;
37
- metadataJsonColumn: string;
38
- indexQueryOptions?: QueryOptions;
28
+ engine: PostgresEngine;
29
+ tableName: string;
30
+ schemaName: string;
31
+ contentColumn: string;
32
+ embeddingColumn: string;
33
+ metadataColumns: Array<string>;
34
+ idColumn: string;
35
+ distanceStrategy: DistanceStrategy;
36
+ k: number;
37
+ fetchK: number;
38
+ lambdaMult: number;
39
+ metadataJsonColumn: string;
40
+ indexQueryOptions?: QueryOptions;
39
41
  }
40
42
  /**
41
43
  * Google Cloud SQL for PostgreSQL vector store integration.
@@ -183,101 +185,116 @@ interface VSArgs {
183
185
  *
184
186
  * <br />
185
187
  */
186
- export declare class PostgresVectorStore extends VectorStore {
187
- FilterType: string;
188
- engine: PostgresEngine;
189
- embeddings: EmbeddingsInterface;
190
- tableName: string;
191
- schemaName: string;
192
- contentColumn: string;
193
- embeddingColumn: string;
194
- metadataColumns: Array<string>;
195
- idColumn: string;
196
- metadataJsonColumn: string;
197
- distanceStrategy: DistanceStrategy;
198
- k: number;
199
- fetchK: number;
200
- lambdaMult: number;
201
- indexQueryOptions: QueryOptions | undefined;
202
- /**
203
- * Initializes a new vector store with embeddings and database configuration.
204
- *
205
- * @param embeddings - Instance of `EmbeddingsInterface` used to embed queries.
206
- * @param dbConfig - Configuration settings for the database or storage system.
207
- */
208
- constructor(embeddings: EmbeddingsInterface, dbConfig: VSArgs);
209
- /**
210
- * Create a new PostgresVectorStore instance.
211
- * @param {PostgresEngine} engine Required - Connection pool engine for managing connections to Cloud SQL for PostgreSQL database.
212
- * @param {Embeddings} embeddings Required - Text embedding model to use.
213
- * @param {string} tableName Required - Name of an existing table or table to be created.
214
- * @param {string} schemaName Database schema name of the table. Defaults to "public".
215
- * @param {string} contentColumn Column that represent a Document's page_content. Defaults to "content".
216
- * @param {string} embeddingColumn Column for embedding vectors. The embedding is generated from the document value. Defaults to "embedding".
217
- * @param {Array<string>} metadataColumns Column(s) that represent a document's metadata.
218
- * @param {Array<string>} ignoreMetadataColumns Optional - Column(s) to ignore in pre-existing tables for a document's metadata. Can not be used with metadata_columns.
219
- * @param {string} idColumn Column that represents the Document's id. Defaults to "langchain_id".
220
- * @param {string} metadataJsonColumn Optional - Column to store metadata as JSON. Defaults to "langchain_metadata".
221
- * @param {DistanceStrategy} distanceStrategy Distance strategy to use for vector similarity search. Defaults to COSINE_DISTANCE.
222
- * @param {number} k Number of Documents to return from search. Defaults to 4.
223
- * @param {number} fetchK Number of Documents to fetch to pass to MMR algorithm.
224
- * @param {number} lambdaMult Number between 0 and 1 that determines the degree of diversity among the results with 0 corresponding to maximum diversity and 1 to minimum diversity. Defaults to 0.5.
225
- * @param {QueryOptions} indexQueryOptions Optional - Index query option.
226
- * @returns PostgresVectorStore instance.
227
- */
228
- static initialize(engine: PostgresEngine, embeddings: EmbeddingsInterface, tableName: string, { schemaName, contentColumn, embeddingColumn, metadataColumns, ignoreMetadataColumns, idColumn, metadataJsonColumn, distanceStrategy, k, fetchK, lambdaMult, indexQueryOptions, }?: PostgresVectorStoreArgs): Promise<PostgresVectorStore>;
229
- static fromTexts(texts: string[], metadatas: object[] | object, embeddings: EmbeddingsInterface, dbConfig: dbConfigArgs): Promise<VectorStore>;
230
- static fromDocuments(docs: Document[], embeddings: EmbeddingsInterface, dbConfig: dbConfigArgs): Promise<VectorStore>;
231
- addVectors(vectors: number[][], documents: Document[], options?: {
232
- ids?: string[];
233
- }): Promise<string[] | void>;
234
- _vectorstoreType(): string;
235
- /**
236
- * Adds documents to the vector store, embedding them first through the
237
- * `embeddings` instance.
238
- *
239
- * @param documents - Array of documents to embed and add.
240
- * @param options - Optional configuration for embedding and storing documents.
241
- * @returns A promise resolving to an array of document IDs or void, based on implementation.
242
- * @abstract
243
- */
244
- addDocuments(documents: Document[], options?: {
245
- ids?: string[];
246
- }): Promise<string[] | void>;
247
- /**
248
- * Deletes documents from the vector store based on the specified ids.
249
- *
250
- * @param params - Flexible key-value pairs defining conditions for document deletion.
251
- * @param ids - Optional: Property of {params} that contains the array of ids to be deleted
252
- * @returns A promise that resolves once the deletion is complete.
253
- */
254
- delete(params: {
255
- ids?: string[];
256
- }): Promise<void>;
257
- similaritySearchVectorWithScore(embedding: number[], k: number, filter?: this["FilterType"]): Promise<[Document, number][]>;
258
- private queryCollection;
259
- maxMarginalRelevanceSearch(query: string, options: MaxMarginalRelevanceSearchOptions<this["FilterType"]>): Promise<Document[]>;
260
- /**
261
- * Create an index on the vector store table
262
- * @param {BaseIndex} index
263
- * @param {string} name Optional
264
- * @param {boolean} concurrently Optional
265
- */
266
- applyVectorIndex(index: BaseIndex, name?: string, concurrently?: boolean): Promise<void>;
267
- /**
268
- * Check if index exists in the table.
269
- * @param {string} indexName Optional - index name
270
- */
271
- isValidIndex(indexName?: string): Promise<boolean>;
272
- /**
273
- * Drop the vector index
274
- * @param {string} indexName Optional - index name
275
- */
276
- dropVectorIndex(indexName?: string): Promise<void>;
277
- /**
278
- * Re-index the vector store table
279
- * @param {string} indexName Optional - index name
280
- */
281
- reIndex(indexName?: string): Promise<void>;
188
+ declare class PostgresVectorStore extends VectorStore {
189
+ FilterType: string;
190
+ engine: PostgresEngine;
191
+ embeddings: EmbeddingsInterface;
192
+ tableName: string;
193
+ schemaName: string;
194
+ contentColumn: string;
195
+ embeddingColumn: string;
196
+ metadataColumns: Array<string>;
197
+ idColumn: string;
198
+ metadataJsonColumn: string;
199
+ distanceStrategy: DistanceStrategy;
200
+ k: number;
201
+ fetchK: number;
202
+ lambdaMult: number;
203
+ indexQueryOptions: QueryOptions | undefined;
204
+ /**
205
+ * Initializes a new vector store with embeddings and database configuration.
206
+ *
207
+ * @param embeddings - Instance of `EmbeddingsInterface` used to embed queries.
208
+ * @param dbConfig - Configuration settings for the database or storage system.
209
+ */
210
+ constructor(embeddings: EmbeddingsInterface, dbConfig: VSArgs);
211
+ /**
212
+ * Create a new PostgresVectorStore instance.
213
+ * @param {PostgresEngine} engine Required - Connection pool engine for managing connections to Cloud SQL for PostgreSQL database.
214
+ * @param {Embeddings} embeddings Required - Text embedding model to use.
215
+ * @param {string} tableName Required - Name of an existing table or table to be created.
216
+ * @param {string} schemaName Database schema name of the table. Defaults to "public".
217
+ * @param {string} contentColumn Column that represent a Document's page_content. Defaults to "content".
218
+ * @param {string} embeddingColumn Column for embedding vectors. The embedding is generated from the document value. Defaults to "embedding".
219
+ * @param {Array<string>} metadataColumns Column(s) that represent a document's metadata.
220
+ * @param {Array<string>} ignoreMetadataColumns Optional - Column(s) to ignore in pre-existing tables for a document's metadata. Can not be used with metadata_columns.
221
+ * @param {string} idColumn Column that represents the Document's id. Defaults to "langchain_id".
222
+ * @param {string} metadataJsonColumn Optional - Column to store metadata as JSON. Defaults to "langchain_metadata".
223
+ * @param {DistanceStrategy} distanceStrategy Distance strategy to use for vector similarity search. Defaults to COSINE_DISTANCE.
224
+ * @param {number} k Number of Documents to return from search. Defaults to 4.
225
+ * @param {number} fetchK Number of Documents to fetch to pass to MMR algorithm.
226
+ * @param {number} lambdaMult Number between 0 and 1 that determines the degree of diversity among the results with 0 corresponding to maximum diversity and 1 to minimum diversity. Defaults to 0.5.
227
+ * @param {QueryOptions} indexQueryOptions Optional - Index query option.
228
+ * @returns PostgresVectorStore instance.
229
+ */
230
+ static initialize(engine: PostgresEngine, embeddings: EmbeddingsInterface, tableName: string, {
231
+ schemaName,
232
+ contentColumn,
233
+ embeddingColumn,
234
+ metadataColumns,
235
+ ignoreMetadataColumns,
236
+ idColumn,
237
+ metadataJsonColumn,
238
+ distanceStrategy,
239
+ k,
240
+ fetchK,
241
+ lambdaMult,
242
+ indexQueryOptions
243
+ }?: PostgresVectorStoreArgs): Promise<PostgresVectorStore>;
244
+ static fromTexts(texts: string[], metadatas: object[] | object, embeddings: EmbeddingsInterface, dbConfig: dbConfigArgs): Promise<VectorStore>;
245
+ static fromDocuments(docs: Document[], embeddings: EmbeddingsInterface, dbConfig: dbConfigArgs): Promise<VectorStore>;
246
+ addVectors(vectors: number[][], documents: Document[], options?: {
247
+ ids?: string[];
248
+ }): Promise<string[] | void>;
249
+ _vectorstoreType(): string;
250
+ /**
251
+ * Adds documents to the vector store, embedding them first through the
252
+ * `embeddings` instance.
253
+ *
254
+ * @param documents - Array of documents to embed and add.
255
+ * @param options - Optional configuration for embedding and storing documents.
256
+ * @returns A promise resolving to an array of document IDs or void, based on implementation.
257
+ * @abstract
258
+ */
259
+ addDocuments(documents: Document[], options?: {
260
+ ids?: string[];
261
+ }): Promise<string[] | void>;
262
+ /**
263
+ * Deletes documents from the vector store based on the specified ids.
264
+ *
265
+ * @param params - Flexible key-value pairs defining conditions for document deletion.
266
+ * @param ids - Optional: Property of {params} that contains the array of ids to be deleted
267
+ * @returns A promise that resolves once the deletion is complete.
268
+ */
269
+ delete(params: {
270
+ ids?: string[];
271
+ }): Promise<void>;
272
+ similaritySearchVectorWithScore(embedding: number[], k: number, filter?: this["FilterType"]): Promise<[Document, number][]>;
273
+ private queryCollection;
274
+ maxMarginalRelevanceSearch(query: string, options: MaxMarginalRelevanceSearchOptions<this["FilterType"]>): Promise<Document[]>;
275
+ /**
276
+ * Create an index on the vector store table
277
+ * @param {BaseIndex} index
278
+ * @param {string} name Optional
279
+ * @param {boolean} concurrently Optional
280
+ */
281
+ applyVectorIndex(index: BaseIndex, name?: string, concurrently?: boolean): Promise<void>;
282
+ /**
283
+ * Check if index exists in the table.
284
+ * @param {string} indexName Optional - index name
285
+ */
286
+ isValidIndex(indexName?: string): Promise<boolean>;
287
+ /**
288
+ * Drop the vector index
289
+ * @param {string} indexName Optional - index name
290
+ */
291
+ dropVectorIndex(indexName?: string): Promise<void>;
292
+ /**
293
+ * Re-index the vector store table
294
+ * @param {string} indexName Optional - index name
295
+ */
296
+ reIndex(indexName?: string): Promise<void>;
282
297
  }
283
- export default PostgresVectorStore;
298
+ //#endregion
299
+ export { PostgresVectorStore, PostgresVectorStoreArgs, dbConfigArgs };
300
+ //# sourceMappingURL=vectorstore.d.ts.map