langchain 0.0.150 → 0.0.152
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.
- package/cache/cloudflare_kv.cjs +1 -0
- package/cache/cloudflare_kv.d.ts +1 -0
- package/cache/cloudflare_kv.js +1 -0
- package/dist/agents/chat/index.cjs +1 -1
- package/dist/agents/chat/index.js +1 -1
- package/dist/agents/chat_convo/index.cjs +1 -1
- package/dist/agents/chat_convo/index.js +1 -1
- package/dist/agents/openai/index.cjs +1 -1
- package/dist/agents/openai/index.js +1 -1
- package/dist/agents/structured_chat/index.cjs +1 -1
- package/dist/agents/structured_chat/index.js +1 -1
- package/dist/agents/xml/index.cjs +1 -1
- package/dist/agents/xml/index.js +1 -1
- package/dist/base_language/count_tokens.cjs +1 -0
- package/dist/base_language/count_tokens.js +1 -0
- package/dist/base_language/index.cjs +5 -3
- package/dist/base_language/index.d.ts +1 -1
- package/dist/base_language/index.js +4 -3
- package/dist/cache/cloudflare_kv.cjs +61 -0
- package/dist/cache/cloudflare_kv.d.ts +29 -0
- package/dist/cache/cloudflare_kv.js +57 -0
- package/dist/chains/openai_functions/openapi.cjs +1 -1
- package/dist/chains/openai_functions/openapi.js +1 -1
- package/dist/chains/question_answering/map_reduce_prompts.cjs +2 -3
- package/dist/chains/question_answering/map_reduce_prompts.js +2 -3
- package/dist/chains/question_answering/refine_prompts.cjs +2 -2
- package/dist/chains/question_answering/refine_prompts.js +2 -2
- package/dist/chains/question_answering/stuff_prompts.cjs +1 -2
- package/dist/chains/question_answering/stuff_prompts.js +1 -2
- package/dist/chat_models/ollama.cjs +3 -7
- package/dist/chat_models/ollama.d.ts +1 -1
- package/dist/chat_models/ollama.js +3 -7
- package/dist/document_loaders/web/pdf.cjs +87 -0
- package/dist/document_loaders/web/pdf.d.ts +17 -0
- package/dist/document_loaders/web/pdf.js +83 -0
- package/dist/evaluation/agents/prompt.cjs +2 -3
- package/dist/evaluation/agents/prompt.js +2 -3
- package/dist/experimental/chat_models/bittensor.cjs +141 -0
- package/dist/experimental/chat_models/bittensor.d.ts +36 -0
- package/dist/experimental/chat_models/bittensor.js +137 -0
- package/dist/experimental/plan_and_execute/prompt.cjs +1 -1
- package/dist/experimental/plan_and_execute/prompt.js +1 -1
- package/dist/llms/llama_cpp.cjs +10 -4
- package/dist/llms/llama_cpp.d.ts +2 -1
- package/dist/llms/llama_cpp.js +10 -4
- package/dist/llms/ollama.cjs +5 -6
- package/dist/llms/ollama.d.ts +2 -2
- package/dist/llms/ollama.js +5 -6
- package/dist/llms/openai.cjs +3 -3
- package/dist/llms/openai.js +3 -3
- package/dist/load/import_constants.cjs +4 -0
- package/dist/load/import_constants.js +4 -0
- package/dist/load/import_map.cjs +2 -1
- package/dist/load/import_map.d.ts +1 -0
- package/dist/load/import_map.js +1 -0
- package/dist/prompts/chat.cjs +12 -1
- package/dist/prompts/chat.d.ts +8 -0
- package/dist/prompts/chat.js +12 -1
- package/dist/schema/runnable/base.cjs +10 -2
- package/dist/schema/runnable/base.d.ts +2 -0
- package/dist/schema/runnable/base.js +9 -2
- package/dist/schema/runnable/branch.cjs +106 -0
- package/dist/schema/runnable/branch.d.ts +66 -0
- package/dist/schema/runnable/branch.js +102 -0
- package/dist/schema/runnable/index.cjs +12 -16
- package/dist/schema/runnable/index.d.ts +2 -1
- package/dist/schema/runnable/index.js +2 -1
- package/dist/stores/message/cloudflare_d1.cjs +134 -0
- package/dist/stores/message/cloudflare_d1.d.ts +49 -0
- package/dist/stores/message/cloudflare_d1.js +130 -0
- package/dist/types/openai-types.d.ts +2 -0
- package/dist/vectorstores/pgvector.cjs +277 -0
- package/dist/vectorstores/pgvector.d.ts +132 -0
- package/dist/vectorstores/pgvector.js +270 -0
- package/document_loaders/web/pdf.cjs +1 -0
- package/document_loaders/web/pdf.d.ts +1 -0
- package/document_loaders/web/pdf.js +1 -0
- package/experimental/chat_models/bittensor.cjs +1 -0
- package/experimental/chat_models/bittensor.d.ts +1 -0
- package/experimental/chat_models/bittensor.js +1 -0
- package/package.json +46 -1
- package/stores/message/cloudflare_d1.cjs +1 -0
- package/stores/message/cloudflare_d1.d.ts +1 -0
- package/stores/message/cloudflare_d1.js +1 -0
- package/vectorstores/pgvector.cjs +1 -0
- package/vectorstores/pgvector.d.ts +1 -0
- package/vectorstores/pgvector.js +1 -0
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { type Pool, type PoolClient, type PoolConfig } from "pg";
|
|
2
|
+
import { VectorStore } from "./base.js";
|
|
3
|
+
import { Embeddings } from "../embeddings/base.js";
|
|
4
|
+
import { Document } from "../document.js";
|
|
5
|
+
type Metadata = Record<string, unknown>;
|
|
6
|
+
/**
|
|
7
|
+
* Interface that defines the arguments required to create a
|
|
8
|
+
* `PGVectorStore` instance. It includes Postgres connection options,
|
|
9
|
+
* table name, filter, and verbosity level.
|
|
10
|
+
*/
|
|
11
|
+
export interface PGVectorStoreArgs {
|
|
12
|
+
postgresConnectionOptions: PoolConfig;
|
|
13
|
+
tableName: string;
|
|
14
|
+
columns?: {
|
|
15
|
+
idColumnName?: string;
|
|
16
|
+
vectorColumnName?: string;
|
|
17
|
+
contentColumnName?: string;
|
|
18
|
+
metadataColumnName?: string;
|
|
19
|
+
};
|
|
20
|
+
filter?: Metadata;
|
|
21
|
+
verbose?: boolean;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Class that provides an interface to a Postgres vector database. It
|
|
25
|
+
* extends the `VectorStore` base class and implements methods for adding
|
|
26
|
+
* documents and vectors, performing similarity searches, and ensuring the
|
|
27
|
+
* existence of a table in the database.
|
|
28
|
+
*/
|
|
29
|
+
export declare class PGVectorStore extends VectorStore {
|
|
30
|
+
FilterType: Metadata;
|
|
31
|
+
tableName: string;
|
|
32
|
+
idColumnName: string;
|
|
33
|
+
vectorColumnName: string;
|
|
34
|
+
contentColumnName: string;
|
|
35
|
+
metadataColumnName: string;
|
|
36
|
+
filter?: Metadata;
|
|
37
|
+
_verbose?: boolean;
|
|
38
|
+
pool: Pool;
|
|
39
|
+
client?: PoolClient;
|
|
40
|
+
_vectorstoreType(): string;
|
|
41
|
+
private constructor();
|
|
42
|
+
/**
|
|
43
|
+
* Static method to create a new `PGVectorStore` instance from a
|
|
44
|
+
* connection. It creates a table if one does not exist, and calls
|
|
45
|
+
* `connect` to return a new instance of `PGVectorStore`.
|
|
46
|
+
*
|
|
47
|
+
* @param embeddings - Embeddings instance.
|
|
48
|
+
* @param fields - `PGVectorStoreArgs` instance.
|
|
49
|
+
* @returns A new instance of `PGVectorStore`.
|
|
50
|
+
*/
|
|
51
|
+
static initialize(embeddings: Embeddings, config: PGVectorStoreArgs): Promise<PGVectorStore>;
|
|
52
|
+
protected _initializeClient(): Promise<void>;
|
|
53
|
+
/**
|
|
54
|
+
* Method to add documents to the vector store. It converts the documents into
|
|
55
|
+
* vectors, and adds them to the store.
|
|
56
|
+
*
|
|
57
|
+
* @param documents - Array of `Document` instances.
|
|
58
|
+
* @returns Promise that resolves when the documents have been added.
|
|
59
|
+
*/
|
|
60
|
+
addDocuments(documents: Document[]): Promise<void>;
|
|
61
|
+
/**
|
|
62
|
+
* Generates the SQL placeholders for a specific row at the provided index.
|
|
63
|
+
*
|
|
64
|
+
* @param index - The index of the row for which placeholders need to be generated.
|
|
65
|
+
* @returns The SQL placeholders for the row values.
|
|
66
|
+
*/
|
|
67
|
+
private generatePlaceholderForRowAt;
|
|
68
|
+
/**
|
|
69
|
+
* Constructs the SQL query for inserting rows into the specified table.
|
|
70
|
+
*
|
|
71
|
+
* @param rows - The rows of data to be inserted, consisting of values and records.
|
|
72
|
+
* @param chunkIndex - The starting index for generating query placeholders based on chunk positioning.
|
|
73
|
+
* @returns The complete SQL INSERT INTO query string.
|
|
74
|
+
*/
|
|
75
|
+
private buildInsertQuery;
|
|
76
|
+
/**
|
|
77
|
+
* Method to add vectors to the vector store. It converts the vectors into
|
|
78
|
+
* rows and inserts them into the database.
|
|
79
|
+
*
|
|
80
|
+
* @param vectors - Array of vectors.
|
|
81
|
+
* @param documents - Array of `Document` instances.
|
|
82
|
+
* @returns Promise that resolves when the vectors have been added.
|
|
83
|
+
*/
|
|
84
|
+
addVectors(vectors: number[][], documents: Document[]): Promise<void>;
|
|
85
|
+
/**
|
|
86
|
+
* Method to perform a similarity search in the vector store. It returns
|
|
87
|
+
* the `k` most similar documents to the query vector, along with their
|
|
88
|
+
* similarity scores.
|
|
89
|
+
*
|
|
90
|
+
* @param query - Query vector.
|
|
91
|
+
* @param k - Number of most similar documents to return.
|
|
92
|
+
* @param filter - Optional filter to apply to the search.
|
|
93
|
+
* @returns Promise that resolves with an array of tuples, each containing a `Document` and its similarity score.
|
|
94
|
+
*/
|
|
95
|
+
similaritySearchVectorWithScore(query: number[], k: number, filter?: this["FilterType"]): Promise<[Document, number][]>;
|
|
96
|
+
/**
|
|
97
|
+
* Method to ensure the existence of the table in the database. It creates
|
|
98
|
+
* the table if it does not already exist.
|
|
99
|
+
*
|
|
100
|
+
* @returns Promise that resolves when the table has been ensured.
|
|
101
|
+
*/
|
|
102
|
+
ensureTableInDatabase(): Promise<void>;
|
|
103
|
+
/**
|
|
104
|
+
* Static method to create a new `PGVectorStore` instance from an
|
|
105
|
+
* array of texts and their metadata. It converts the texts into
|
|
106
|
+
* `Document` instances and adds them to the store.
|
|
107
|
+
*
|
|
108
|
+
* @param texts - Array of texts.
|
|
109
|
+
* @param metadatas - Array of metadata objects or a single metadata object.
|
|
110
|
+
* @param embeddings - Embeddings instance.
|
|
111
|
+
* @param dbConfig - `PGVectorStoreArgs` instance.
|
|
112
|
+
* @returns Promise that resolves with a new instance of `PGVectorStore`.
|
|
113
|
+
*/
|
|
114
|
+
static fromTexts(texts: string[], metadatas: object[] | object, embeddings: Embeddings, dbConfig: PGVectorStoreArgs): Promise<PGVectorStore>;
|
|
115
|
+
/**
|
|
116
|
+
* Static method to create a new `PGVectorStore` instance from an
|
|
117
|
+
* array of `Document` instances. It adds the documents to the store.
|
|
118
|
+
*
|
|
119
|
+
* @param docs - Array of `Document` instances.
|
|
120
|
+
* @param embeddings - Embeddings instance.
|
|
121
|
+
* @param dbConfig - `PGVectorStoreArgs` instance.
|
|
122
|
+
* @returns Promise that resolves with a new instance of `PGVectorStore`.
|
|
123
|
+
*/
|
|
124
|
+
static fromDocuments(docs: Document[], embeddings: Embeddings, dbConfig: PGVectorStoreArgs): Promise<PGVectorStore>;
|
|
125
|
+
/**
|
|
126
|
+
* Closes all the clients in the pool and terminates the pool.
|
|
127
|
+
*
|
|
128
|
+
* @returns Promise that resolves when all clients are closed and the pool is terminated.
|
|
129
|
+
*/
|
|
130
|
+
end(): Promise<void>;
|
|
131
|
+
}
|
|
132
|
+
export {};
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
import pg from "pg";
|
|
2
|
+
import { VectorStore } from "./base.js";
|
|
3
|
+
import { Document } from "../document.js";
|
|
4
|
+
import { getEnvironmentVariable } from "../util/env.js";
|
|
5
|
+
/**
|
|
6
|
+
* Class that provides an interface to a Postgres vector database. It
|
|
7
|
+
* extends the `VectorStore` base class and implements methods for adding
|
|
8
|
+
* documents and vectors, performing similarity searches, and ensuring the
|
|
9
|
+
* existence of a table in the database.
|
|
10
|
+
*/
|
|
11
|
+
export class PGVectorStore extends VectorStore {
|
|
12
|
+
_vectorstoreType() {
|
|
13
|
+
return "pgvector";
|
|
14
|
+
}
|
|
15
|
+
constructor(embeddings, config) {
|
|
16
|
+
super(embeddings, config);
|
|
17
|
+
Object.defineProperty(this, "tableName", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
configurable: true,
|
|
20
|
+
writable: true,
|
|
21
|
+
value: void 0
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(this, "idColumnName", {
|
|
24
|
+
enumerable: true,
|
|
25
|
+
configurable: true,
|
|
26
|
+
writable: true,
|
|
27
|
+
value: void 0
|
|
28
|
+
});
|
|
29
|
+
Object.defineProperty(this, "vectorColumnName", {
|
|
30
|
+
enumerable: true,
|
|
31
|
+
configurable: true,
|
|
32
|
+
writable: true,
|
|
33
|
+
value: void 0
|
|
34
|
+
});
|
|
35
|
+
Object.defineProperty(this, "contentColumnName", {
|
|
36
|
+
enumerable: true,
|
|
37
|
+
configurable: true,
|
|
38
|
+
writable: true,
|
|
39
|
+
value: void 0
|
|
40
|
+
});
|
|
41
|
+
Object.defineProperty(this, "metadataColumnName", {
|
|
42
|
+
enumerable: true,
|
|
43
|
+
configurable: true,
|
|
44
|
+
writable: true,
|
|
45
|
+
value: void 0
|
|
46
|
+
});
|
|
47
|
+
Object.defineProperty(this, "filter", {
|
|
48
|
+
enumerable: true,
|
|
49
|
+
configurable: true,
|
|
50
|
+
writable: true,
|
|
51
|
+
value: void 0
|
|
52
|
+
});
|
|
53
|
+
Object.defineProperty(this, "_verbose", {
|
|
54
|
+
enumerable: true,
|
|
55
|
+
configurable: true,
|
|
56
|
+
writable: true,
|
|
57
|
+
value: void 0
|
|
58
|
+
});
|
|
59
|
+
Object.defineProperty(this, "pool", {
|
|
60
|
+
enumerable: true,
|
|
61
|
+
configurable: true,
|
|
62
|
+
writable: true,
|
|
63
|
+
value: void 0
|
|
64
|
+
});
|
|
65
|
+
Object.defineProperty(this, "client", {
|
|
66
|
+
enumerable: true,
|
|
67
|
+
configurable: true,
|
|
68
|
+
writable: true,
|
|
69
|
+
value: void 0
|
|
70
|
+
});
|
|
71
|
+
this.tableName = config.tableName;
|
|
72
|
+
this.filter = config.filter;
|
|
73
|
+
this.vectorColumnName = config.columns?.vectorColumnName ?? "embedding";
|
|
74
|
+
this.contentColumnName = config.columns?.contentColumnName ?? "text";
|
|
75
|
+
this.idColumnName = config.columns?.idColumnName ?? "id";
|
|
76
|
+
this.metadataColumnName = config.columns?.metadataColumnName ?? "metadata";
|
|
77
|
+
const pool = new pg.Pool(config.postgresConnectionOptions);
|
|
78
|
+
this.pool = pool;
|
|
79
|
+
this._verbose =
|
|
80
|
+
getEnvironmentVariable("LANGCHAIN_VERBOSE") === "true" ??
|
|
81
|
+
!!config.verbose;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Static method to create a new `PGVectorStore` instance from a
|
|
85
|
+
* connection. It creates a table if one does not exist, and calls
|
|
86
|
+
* `connect` to return a new instance of `PGVectorStore`.
|
|
87
|
+
*
|
|
88
|
+
* @param embeddings - Embeddings instance.
|
|
89
|
+
* @param fields - `PGVectorStoreArgs` instance.
|
|
90
|
+
* @returns A new instance of `PGVectorStore`.
|
|
91
|
+
*/
|
|
92
|
+
static async initialize(embeddings, config) {
|
|
93
|
+
const postgresqlVectorStore = new PGVectorStore(embeddings, config);
|
|
94
|
+
await postgresqlVectorStore._initializeClient();
|
|
95
|
+
await postgresqlVectorStore.ensureTableInDatabase();
|
|
96
|
+
return postgresqlVectorStore;
|
|
97
|
+
}
|
|
98
|
+
async _initializeClient() {
|
|
99
|
+
this.client = await this.pool.connect();
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Method to add documents to the vector store. It converts the documents into
|
|
103
|
+
* vectors, and adds them to the store.
|
|
104
|
+
*
|
|
105
|
+
* @param documents - Array of `Document` instances.
|
|
106
|
+
* @returns Promise that resolves when the documents have been added.
|
|
107
|
+
*/
|
|
108
|
+
async addDocuments(documents) {
|
|
109
|
+
const texts = documents.map(({ pageContent }) => pageContent);
|
|
110
|
+
return this.addVectors(await this.embeddings.embedDocuments(texts), documents);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Generates the SQL placeholders for a specific row at the provided index.
|
|
114
|
+
*
|
|
115
|
+
* @param index - The index of the row for which placeholders need to be generated.
|
|
116
|
+
* @returns The SQL placeholders for the row values.
|
|
117
|
+
*/
|
|
118
|
+
generatePlaceholderForRowAt(index) {
|
|
119
|
+
const base = index * 3;
|
|
120
|
+
return `($${base + 1}, $${base + 2}, $${base + 3})`;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Constructs the SQL query for inserting rows into the specified table.
|
|
124
|
+
*
|
|
125
|
+
* @param rows - The rows of data to be inserted, consisting of values and records.
|
|
126
|
+
* @param chunkIndex - The starting index for generating query placeholders based on chunk positioning.
|
|
127
|
+
* @returns The complete SQL INSERT INTO query string.
|
|
128
|
+
*/
|
|
129
|
+
buildInsertQuery(rows, chunkIndex) {
|
|
130
|
+
const valuesPlaceholders = rows
|
|
131
|
+
.map((_, j) => this.generatePlaceholderForRowAt(chunkIndex + j))
|
|
132
|
+
.join(", ");
|
|
133
|
+
const text = `
|
|
134
|
+
INSERT INTO ${this.tableName}(
|
|
135
|
+
${this.contentColumnName},
|
|
136
|
+
${this.vectorColumnName},
|
|
137
|
+
${this.metadataColumnName}
|
|
138
|
+
)
|
|
139
|
+
VALUES ${valuesPlaceholders}
|
|
140
|
+
`;
|
|
141
|
+
return text;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Method to add vectors to the vector store. It converts the vectors into
|
|
145
|
+
* rows and inserts them into the database.
|
|
146
|
+
*
|
|
147
|
+
* @param vectors - Array of vectors.
|
|
148
|
+
* @param documents - Array of `Document` instances.
|
|
149
|
+
* @returns Promise that resolves when the vectors have been added.
|
|
150
|
+
*/
|
|
151
|
+
async addVectors(vectors, documents) {
|
|
152
|
+
const rows = vectors.map((embedding, idx) => {
|
|
153
|
+
const embeddingString = `[${embedding.join(",")}]`;
|
|
154
|
+
return [
|
|
155
|
+
documents[idx].pageContent,
|
|
156
|
+
embeddingString,
|
|
157
|
+
documents[idx].metadata,
|
|
158
|
+
];
|
|
159
|
+
});
|
|
160
|
+
const chunkSize = 500;
|
|
161
|
+
for (let i = 0; i < rows.length; i += chunkSize) {
|
|
162
|
+
const chunk = rows.slice(i, i + chunkSize);
|
|
163
|
+
const insertQuery = this.buildInsertQuery(chunk, i);
|
|
164
|
+
const flatValues = chunk.flat();
|
|
165
|
+
try {
|
|
166
|
+
await this.pool.query(insertQuery, flatValues);
|
|
167
|
+
}
|
|
168
|
+
catch (e) {
|
|
169
|
+
console.error(e);
|
|
170
|
+
throw new Error(`Error inserting: ${chunk[1]}`);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Method to perform a similarity search in the vector store. It returns
|
|
176
|
+
* the `k` most similar documents to the query vector, along with their
|
|
177
|
+
* similarity scores.
|
|
178
|
+
*
|
|
179
|
+
* @param query - Query vector.
|
|
180
|
+
* @param k - Number of most similar documents to return.
|
|
181
|
+
* @param filter - Optional filter to apply to the search.
|
|
182
|
+
* @returns Promise that resolves with an array of tuples, each containing a `Document` and its similarity score.
|
|
183
|
+
*/
|
|
184
|
+
async similaritySearchVectorWithScore(query, k, filter) {
|
|
185
|
+
const embeddingString = `[${query.join(",")}]`;
|
|
186
|
+
const _filter = filter ?? "{}";
|
|
187
|
+
const queryString = `
|
|
188
|
+
SELECT *, ${this.vectorColumnName} <=> $1 as "_distance"
|
|
189
|
+
FROM ${this.tableName}
|
|
190
|
+
WHERE ${this.metadataColumnName} @> $2
|
|
191
|
+
ORDER BY "_distance" ASC
|
|
192
|
+
LIMIT $3;`;
|
|
193
|
+
const documents = (await this.pool.query(queryString, [embeddingString, _filter, k])).rows;
|
|
194
|
+
const results = [];
|
|
195
|
+
for (const doc of documents) {
|
|
196
|
+
if (doc._distance != null && doc[this.contentColumnName] != null) {
|
|
197
|
+
const document = new Document({
|
|
198
|
+
pageContent: doc[this.contentColumnName],
|
|
199
|
+
metadata: doc[this.metadataColumnName],
|
|
200
|
+
});
|
|
201
|
+
results.push([document, doc._distance]);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return results;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Method to ensure the existence of the table in the database. It creates
|
|
208
|
+
* the table if it does not already exist.
|
|
209
|
+
*
|
|
210
|
+
* @returns Promise that resolves when the table has been ensured.
|
|
211
|
+
*/
|
|
212
|
+
async ensureTableInDatabase() {
|
|
213
|
+
await this.pool.query("CREATE EXTENSION IF NOT EXISTS vector;");
|
|
214
|
+
await this.pool.query('CREATE EXTENSION IF NOT EXISTS "uuid-ossp";');
|
|
215
|
+
await this.pool.query(`
|
|
216
|
+
CREATE TABLE IF NOT EXISTS ${this.tableName} (
|
|
217
|
+
"${this.idColumnName}" uuid NOT NULL DEFAULT uuid_generate_v4() PRIMARY KEY,
|
|
218
|
+
"${this.contentColumnName}" text,
|
|
219
|
+
"${this.metadataColumnName}" jsonb,
|
|
220
|
+
"${this.vectorColumnName}" vector
|
|
221
|
+
);
|
|
222
|
+
`);
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Static method to create a new `PGVectorStore` instance from an
|
|
226
|
+
* array of texts and their metadata. It converts the texts into
|
|
227
|
+
* `Document` instances and adds them to the store.
|
|
228
|
+
*
|
|
229
|
+
* @param texts - Array of texts.
|
|
230
|
+
* @param metadatas - Array of metadata objects or a single metadata object.
|
|
231
|
+
* @param embeddings - Embeddings instance.
|
|
232
|
+
* @param dbConfig - `PGVectorStoreArgs` instance.
|
|
233
|
+
* @returns Promise that resolves with a new instance of `PGVectorStore`.
|
|
234
|
+
*/
|
|
235
|
+
static async fromTexts(texts, metadatas, embeddings, dbConfig) {
|
|
236
|
+
const docs = [];
|
|
237
|
+
for (let i = 0; i < texts.length; i += 1) {
|
|
238
|
+
const metadata = Array.isArray(metadatas) ? metadatas[i] : metadatas;
|
|
239
|
+
const newDoc = new Document({
|
|
240
|
+
pageContent: texts[i],
|
|
241
|
+
metadata,
|
|
242
|
+
});
|
|
243
|
+
docs.push(newDoc);
|
|
244
|
+
}
|
|
245
|
+
return PGVectorStore.fromDocuments(docs, embeddings, dbConfig);
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Static method to create a new `PGVectorStore` instance from an
|
|
249
|
+
* array of `Document` instances. It adds the documents to the store.
|
|
250
|
+
*
|
|
251
|
+
* @param docs - Array of `Document` instances.
|
|
252
|
+
* @param embeddings - Embeddings instance.
|
|
253
|
+
* @param dbConfig - `PGVectorStoreArgs` instance.
|
|
254
|
+
* @returns Promise that resolves with a new instance of `PGVectorStore`.
|
|
255
|
+
*/
|
|
256
|
+
static async fromDocuments(docs, embeddings, dbConfig) {
|
|
257
|
+
const instance = await PGVectorStore.initialize(embeddings, dbConfig);
|
|
258
|
+
await instance.addDocuments(docs);
|
|
259
|
+
return instance;
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Closes all the clients in the pool and terminates the pool.
|
|
263
|
+
*
|
|
264
|
+
* @returns Promise that resolves when all clients are closed and the pool is terminated.
|
|
265
|
+
*/
|
|
266
|
+
async end() {
|
|
267
|
+
await this.client?.release();
|
|
268
|
+
return this.pool.end();
|
|
269
|
+
}
|
|
270
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('../../dist/document_loaders/web/pdf.cjs');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../../dist/document_loaders/web/pdf.js'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../../dist/document_loaders/web/pdf.js'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('../../dist/experimental/chat_models/bittensor.cjs');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../../dist/experimental/chat_models/bittensor.js'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../../dist/experimental/chat_models/bittensor.js'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "langchain",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.152",
|
|
4
4
|
"description": "Typescript bindings for langchain",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -211,6 +211,9 @@
|
|
|
211
211
|
"vectorstores/opensearch.cjs",
|
|
212
212
|
"vectorstores/opensearch.js",
|
|
213
213
|
"vectorstores/opensearch.d.ts",
|
|
214
|
+
"vectorstores/pgvector.cjs",
|
|
215
|
+
"vectorstores/pgvector.js",
|
|
216
|
+
"vectorstores/pgvector.d.ts",
|
|
214
217
|
"vectorstores/milvus.cjs",
|
|
215
218
|
"vectorstores/milvus.js",
|
|
216
219
|
"vectorstores/milvus.d.ts",
|
|
@@ -310,6 +313,9 @@
|
|
|
310
313
|
"document_loaders/web/notionapi.cjs",
|
|
311
314
|
"document_loaders/web/notionapi.js",
|
|
312
315
|
"document_loaders/web/notionapi.d.ts",
|
|
316
|
+
"document_loaders/web/pdf.cjs",
|
|
317
|
+
"document_loaders/web/pdf.js",
|
|
318
|
+
"document_loaders/web/pdf.d.ts",
|
|
313
319
|
"document_loaders/web/recursive_url.cjs",
|
|
314
320
|
"document_loaders/web/recursive_url.js",
|
|
315
321
|
"document_loaders/web/recursive_url.d.ts",
|
|
@@ -508,6 +514,9 @@
|
|
|
508
514
|
"cache.cjs",
|
|
509
515
|
"cache.js",
|
|
510
516
|
"cache.d.ts",
|
|
517
|
+
"cache/cloudflare_kv.cjs",
|
|
518
|
+
"cache/cloudflare_kv.js",
|
|
519
|
+
"cache/cloudflare_kv.d.ts",
|
|
511
520
|
"cache/momento.cjs",
|
|
512
521
|
"cache/momento.js",
|
|
513
522
|
"cache/momento.d.ts",
|
|
@@ -532,6 +541,9 @@
|
|
|
532
541
|
"stores/file/node.cjs",
|
|
533
542
|
"stores/file/node.js",
|
|
534
543
|
"stores/file/node.d.ts",
|
|
544
|
+
"stores/message/cloudflare_d1.cjs",
|
|
545
|
+
"stores/message/cloudflare_d1.js",
|
|
546
|
+
"stores/message/cloudflare_d1.d.ts",
|
|
535
547
|
"stores/message/in_memory.cjs",
|
|
536
548
|
"stores/message/in_memory.js",
|
|
537
549
|
"stores/message/in_memory.d.ts",
|
|
@@ -592,6 +604,9 @@
|
|
|
592
604
|
"experimental/chat_models/anthropic_functions.cjs",
|
|
593
605
|
"experimental/chat_models/anthropic_functions.js",
|
|
594
606
|
"experimental/chat_models/anthropic_functions.d.ts",
|
|
607
|
+
"experimental/chat_models/bittensor.cjs",
|
|
608
|
+
"experimental/chat_models/bittensor.js",
|
|
609
|
+
"experimental/chat_models/bittensor.d.ts",
|
|
595
610
|
"experimental/llms/bittensor.cjs",
|
|
596
611
|
"experimental/llms/bittensor.js",
|
|
597
612
|
"experimental/llms/bittensor.d.ts",
|
|
@@ -640,6 +655,7 @@
|
|
|
640
655
|
"@aws-sdk/types": "^3.357.0",
|
|
641
656
|
"@azure/storage-blob": "^12.15.0",
|
|
642
657
|
"@clickhouse/client": "^0.0.14",
|
|
658
|
+
"@cloudflare/workers-types": "^4.20230904.0",
|
|
643
659
|
"@elastic/elasticsearch": "^8.4.0",
|
|
644
660
|
"@faker-js/faker": "^7.6.0",
|
|
645
661
|
"@getmetal/metal-sdk": "^4.0.0",
|
|
@@ -759,6 +775,7 @@
|
|
|
759
775
|
"@aws-sdk/signature-v4": "^3.374.0",
|
|
760
776
|
"@azure/storage-blob": "^12.15.0",
|
|
761
777
|
"@clickhouse/client": "^0.0.14",
|
|
778
|
+
"@cloudflare/workers-types": "^4.20230904.0",
|
|
762
779
|
"@elastic/elasticsearch": "^8.4.0",
|
|
763
780
|
"@getmetal/metal-sdk": "*",
|
|
764
781
|
"@getzep/zep-js": "^0.7.0",
|
|
@@ -865,6 +882,9 @@
|
|
|
865
882
|
"@clickhouse/client": {
|
|
866
883
|
"optional": true
|
|
867
884
|
},
|
|
885
|
+
"@cloudflare/workers-types": {
|
|
886
|
+
"optional": true
|
|
887
|
+
},
|
|
868
888
|
"@elastic/elasticsearch": {
|
|
869
889
|
"optional": true
|
|
870
890
|
},
|
|
@@ -1447,6 +1467,11 @@
|
|
|
1447
1467
|
"import": "./vectorstores/opensearch.js",
|
|
1448
1468
|
"require": "./vectorstores/opensearch.cjs"
|
|
1449
1469
|
},
|
|
1470
|
+
"./vectorstores/pgvector": {
|
|
1471
|
+
"types": "./vectorstores/pgvector.d.ts",
|
|
1472
|
+
"import": "./vectorstores/pgvector.js",
|
|
1473
|
+
"require": "./vectorstores/pgvector.cjs"
|
|
1474
|
+
},
|
|
1450
1475
|
"./vectorstores/milvus": {
|
|
1451
1476
|
"types": "./vectorstores/milvus.d.ts",
|
|
1452
1477
|
"import": "./vectorstores/milvus.js",
|
|
@@ -1612,6 +1637,11 @@
|
|
|
1612
1637
|
"import": "./document_loaders/web/notionapi.js",
|
|
1613
1638
|
"require": "./document_loaders/web/notionapi.cjs"
|
|
1614
1639
|
},
|
|
1640
|
+
"./document_loaders/web/pdf": {
|
|
1641
|
+
"types": "./document_loaders/web/pdf.d.ts",
|
|
1642
|
+
"import": "./document_loaders/web/pdf.js",
|
|
1643
|
+
"require": "./document_loaders/web/pdf.cjs"
|
|
1644
|
+
},
|
|
1615
1645
|
"./document_loaders/web/recursive_url": {
|
|
1616
1646
|
"types": "./document_loaders/web/recursive_url.d.ts",
|
|
1617
1647
|
"import": "./document_loaders/web/recursive_url.js",
|
|
@@ -1942,6 +1972,11 @@
|
|
|
1942
1972
|
"import": "./cache.js",
|
|
1943
1973
|
"require": "./cache.cjs"
|
|
1944
1974
|
},
|
|
1975
|
+
"./cache/cloudflare_kv": {
|
|
1976
|
+
"types": "./cache/cloudflare_kv.d.ts",
|
|
1977
|
+
"import": "./cache/cloudflare_kv.js",
|
|
1978
|
+
"require": "./cache/cloudflare_kv.cjs"
|
|
1979
|
+
},
|
|
1945
1980
|
"./cache/momento": {
|
|
1946
1981
|
"types": "./cache/momento.d.ts",
|
|
1947
1982
|
"import": "./cache/momento.js",
|
|
@@ -1982,6 +2017,11 @@
|
|
|
1982
2017
|
"import": "./stores/file/node.js",
|
|
1983
2018
|
"require": "./stores/file/node.cjs"
|
|
1984
2019
|
},
|
|
2020
|
+
"./stores/message/cloudflare_d1": {
|
|
2021
|
+
"types": "./stores/message/cloudflare_d1.d.ts",
|
|
2022
|
+
"import": "./stores/message/cloudflare_d1.js",
|
|
2023
|
+
"require": "./stores/message/cloudflare_d1.cjs"
|
|
2024
|
+
},
|
|
1985
2025
|
"./stores/message/in_memory": {
|
|
1986
2026
|
"types": "./stores/message/in_memory.d.ts",
|
|
1987
2027
|
"import": "./stores/message/in_memory.js",
|
|
@@ -2082,6 +2122,11 @@
|
|
|
2082
2122
|
"import": "./experimental/chat_models/anthropic_functions.js",
|
|
2083
2123
|
"require": "./experimental/chat_models/anthropic_functions.cjs"
|
|
2084
2124
|
},
|
|
2125
|
+
"./experimental/chat_models/bittensor": {
|
|
2126
|
+
"types": "./experimental/chat_models/bittensor.d.ts",
|
|
2127
|
+
"import": "./experimental/chat_models/bittensor.js",
|
|
2128
|
+
"require": "./experimental/chat_models/bittensor.cjs"
|
|
2129
|
+
},
|
|
2085
2130
|
"./experimental/llms/bittensor": {
|
|
2086
2131
|
"types": "./experimental/llms/bittensor.d.ts",
|
|
2087
2132
|
"import": "./experimental/llms/bittensor.js",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('../../dist/stores/message/cloudflare_d1.cjs');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../../dist/stores/message/cloudflare_d1.js'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../../dist/stores/message/cloudflare_d1.js'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('../dist/vectorstores/pgvector.cjs');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../dist/vectorstores/pgvector.js'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../dist/vectorstores/pgvector.js'
|