langchain 0.0.159 → 0.0.160
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.
|
@@ -27,11 +27,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
29
|
exports.PineconeStore = void 0;
|
|
30
|
+
/* eslint-disable no-process-env */
|
|
30
31
|
const uuid = __importStar(require("uuid"));
|
|
31
32
|
const flat_1 = __importDefault(require("flat"));
|
|
32
33
|
const base_js_1 = require("./base.cjs");
|
|
33
34
|
const document_js_1 = require("../document.cjs");
|
|
34
|
-
const chunk_js_1 = require("../util/chunk.cjs");
|
|
35
35
|
const async_caller_js_1 = require("../util/async_caller.cjs");
|
|
36
36
|
/**
|
|
37
37
|
* Class that extends the VectorStore class and provides methods to
|
|
@@ -135,16 +135,13 @@ class PineconeStore extends base_js_1.VectorStore {
|
|
|
135
135
|
values,
|
|
136
136
|
};
|
|
137
137
|
});
|
|
138
|
+
const namespace = this.pineconeIndex.namespace(this.namespace ?? "");
|
|
138
139
|
// Pinecone recommends a limit of 100 vectors per upsert request
|
|
139
|
-
const chunkSize =
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
namespace: this.namespace,
|
|
145
|
-
},
|
|
146
|
-
})));
|
|
147
|
-
await Promise.all(batchRequests);
|
|
140
|
+
const chunkSize = 50;
|
|
141
|
+
for (let i = 0; i < pineconeVectors.length; i += chunkSize) {
|
|
142
|
+
const chunk = pineconeVectors.slice(i, i + chunkSize);
|
|
143
|
+
await namespace.upsert(chunk);
|
|
144
|
+
}
|
|
148
145
|
return documentIds;
|
|
149
146
|
}
|
|
150
147
|
/**
|
|
@@ -153,23 +150,17 @@ class PineconeStore extends base_js_1.VectorStore {
|
|
|
153
150
|
* @returns Promise that resolves when the delete operation is complete.
|
|
154
151
|
*/
|
|
155
152
|
async delete(params) {
|
|
156
|
-
const {
|
|
153
|
+
const { deleteAll, ids } = params;
|
|
154
|
+
const namespace = this.pineconeIndex.namespace(this.namespace ?? "");
|
|
157
155
|
if (deleteAll) {
|
|
158
|
-
await
|
|
159
|
-
deleteAll: true,
|
|
160
|
-
namespace,
|
|
161
|
-
...rest,
|
|
162
|
-
});
|
|
156
|
+
await namespace.deleteAll();
|
|
163
157
|
}
|
|
164
158
|
else if (ids) {
|
|
165
159
|
const batchSize = 1000;
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
...rest,
|
|
171
|
-
})));
|
|
172
|
-
await Promise.all(batchRequests);
|
|
160
|
+
for (let i = 0; i < ids.length; i += batchSize) {
|
|
161
|
+
const batchIds = ids.slice(i, i + batchSize);
|
|
162
|
+
await namespace.deleteMany(batchIds);
|
|
163
|
+
}
|
|
173
164
|
}
|
|
174
165
|
else {
|
|
175
166
|
throw new Error("Either ids or delete_all must be provided.");
|
|
@@ -188,14 +179,12 @@ class PineconeStore extends base_js_1.VectorStore {
|
|
|
188
179
|
throw new Error("cannot provide both `filter` and `this.filter`");
|
|
189
180
|
}
|
|
190
181
|
const _filter = filter ?? this.filter;
|
|
191
|
-
const
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
filter: _filter,
|
|
198
|
-
},
|
|
182
|
+
const namespace = this.pineconeIndex.namespace(this.namespace ?? "");
|
|
183
|
+
const results = await namespace.query({
|
|
184
|
+
includeMetadata: true,
|
|
185
|
+
topK: k,
|
|
186
|
+
vector: query,
|
|
187
|
+
filter: _filter,
|
|
199
188
|
});
|
|
200
189
|
const result = [];
|
|
201
190
|
if (results.matches) {
|
|
@@ -229,9 +218,7 @@ class PineconeStore extends base_js_1.VectorStore {
|
|
|
229
218
|
docs.push(newDoc);
|
|
230
219
|
}
|
|
231
220
|
const args = {
|
|
232
|
-
pineconeIndex:
|
|
233
|
-
? dbConfig.pineconeIndex
|
|
234
|
-
: dbConfig.pineconeClient,
|
|
221
|
+
pineconeIndex: dbConfig.pineconeIndex,
|
|
235
222
|
textKey: dbConfig.textKey,
|
|
236
223
|
namespace: dbConfig.namespace,
|
|
237
224
|
};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
+
import { Index as PineconeIndex } from "@pinecone-database/pinecone";
|
|
1
2
|
import { VectorStore } from "./base.js";
|
|
2
3
|
import { Embeddings } from "../embeddings/base.js";
|
|
3
4
|
import { Document } from "../document.js";
|
|
4
|
-
import { AsyncCaller
|
|
5
|
+
import { AsyncCaller } from "../util/async_caller.js";
|
|
5
6
|
type PineconeMetadata = Record<string, any>;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
pineconeIndex: VectorOperationsApi;
|
|
7
|
+
export interface PineconeLibArgs {
|
|
8
|
+
pineconeIndex: PineconeIndex;
|
|
9
9
|
textKey?: string;
|
|
10
10
|
namespace?: string;
|
|
11
11
|
filter?: PineconeMetadata;
|
|
@@ -27,7 +27,7 @@ export declare class PineconeStore extends VectorStore {
|
|
|
27
27
|
FilterType: PineconeMetadata;
|
|
28
28
|
textKey: string;
|
|
29
29
|
namespace?: string;
|
|
30
|
-
pineconeIndex:
|
|
30
|
+
pineconeIndex: PineconeIndex;
|
|
31
31
|
filter?: PineconeMetadata;
|
|
32
32
|
caller: AsyncCaller;
|
|
33
33
|
_vectorstoreType(): string;
|
|
@@ -76,10 +76,7 @@ export declare class PineconeStore extends VectorStore {
|
|
|
76
76
|
* @returns Promise that resolves with a new instance of the PineconeStore class.
|
|
77
77
|
*/
|
|
78
78
|
static fromTexts(texts: string[], metadatas: object[] | object, embeddings: Embeddings, dbConfig: {
|
|
79
|
-
|
|
80
|
-
* @deprecated Use pineconeIndex instead
|
|
81
|
-
*/
|
|
82
|
-
pineconeClient: VectorOperationsApi;
|
|
79
|
+
pineconeIndex: PineconeIndex;
|
|
83
80
|
textKey?: string;
|
|
84
81
|
namespace?: string | undefined;
|
|
85
82
|
} | PineconeLibArgs): Promise<PineconeStore>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
/* eslint-disable no-process-env */
|
|
1
2
|
import * as uuid from "uuid";
|
|
2
3
|
import flatten from "flat";
|
|
3
4
|
import { VectorStore } from "./base.js";
|
|
4
5
|
import { Document } from "../document.js";
|
|
5
|
-
import { chunkArray } from "../util/chunk.js";
|
|
6
6
|
import { AsyncCaller } from "../util/async_caller.js";
|
|
7
7
|
/**
|
|
8
8
|
* Class that extends the VectorStore class and provides methods to
|
|
@@ -106,16 +106,13 @@ export class PineconeStore extends VectorStore {
|
|
|
106
106
|
values,
|
|
107
107
|
};
|
|
108
108
|
});
|
|
109
|
+
const namespace = this.pineconeIndex.namespace(this.namespace ?? "");
|
|
109
110
|
// Pinecone recommends a limit of 100 vectors per upsert request
|
|
110
|
-
const chunkSize =
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
namespace: this.namespace,
|
|
116
|
-
},
|
|
117
|
-
})));
|
|
118
|
-
await Promise.all(batchRequests);
|
|
111
|
+
const chunkSize = 50;
|
|
112
|
+
for (let i = 0; i < pineconeVectors.length; i += chunkSize) {
|
|
113
|
+
const chunk = pineconeVectors.slice(i, i + chunkSize);
|
|
114
|
+
await namespace.upsert(chunk);
|
|
115
|
+
}
|
|
119
116
|
return documentIds;
|
|
120
117
|
}
|
|
121
118
|
/**
|
|
@@ -124,23 +121,17 @@ export class PineconeStore extends VectorStore {
|
|
|
124
121
|
* @returns Promise that resolves when the delete operation is complete.
|
|
125
122
|
*/
|
|
126
123
|
async delete(params) {
|
|
127
|
-
const {
|
|
124
|
+
const { deleteAll, ids } = params;
|
|
125
|
+
const namespace = this.pineconeIndex.namespace(this.namespace ?? "");
|
|
128
126
|
if (deleteAll) {
|
|
129
|
-
await
|
|
130
|
-
deleteAll: true,
|
|
131
|
-
namespace,
|
|
132
|
-
...rest,
|
|
133
|
-
});
|
|
127
|
+
await namespace.deleteAll();
|
|
134
128
|
}
|
|
135
129
|
else if (ids) {
|
|
136
130
|
const batchSize = 1000;
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
...rest,
|
|
142
|
-
})));
|
|
143
|
-
await Promise.all(batchRequests);
|
|
131
|
+
for (let i = 0; i < ids.length; i += batchSize) {
|
|
132
|
+
const batchIds = ids.slice(i, i + batchSize);
|
|
133
|
+
await namespace.deleteMany(batchIds);
|
|
134
|
+
}
|
|
144
135
|
}
|
|
145
136
|
else {
|
|
146
137
|
throw new Error("Either ids or delete_all must be provided.");
|
|
@@ -159,14 +150,12 @@ export class PineconeStore extends VectorStore {
|
|
|
159
150
|
throw new Error("cannot provide both `filter` and `this.filter`");
|
|
160
151
|
}
|
|
161
152
|
const _filter = filter ?? this.filter;
|
|
162
|
-
const
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
filter: _filter,
|
|
169
|
-
},
|
|
153
|
+
const namespace = this.pineconeIndex.namespace(this.namespace ?? "");
|
|
154
|
+
const results = await namespace.query({
|
|
155
|
+
includeMetadata: true,
|
|
156
|
+
topK: k,
|
|
157
|
+
vector: query,
|
|
158
|
+
filter: _filter,
|
|
170
159
|
});
|
|
171
160
|
const result = [];
|
|
172
161
|
if (results.matches) {
|
|
@@ -200,9 +189,7 @@ export class PineconeStore extends VectorStore {
|
|
|
200
189
|
docs.push(newDoc);
|
|
201
190
|
}
|
|
202
191
|
const args = {
|
|
203
|
-
pineconeIndex:
|
|
204
|
-
? dbConfig.pineconeIndex
|
|
205
|
-
: dbConfig.pineconeClient,
|
|
192
|
+
pineconeIndex: dbConfig.pineconeIndex,
|
|
206
193
|
textKey: dbConfig.textKey,
|
|
207
194
|
namespace: dbConfig.namespace,
|
|
208
195
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "langchain",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.160",
|
|
4
4
|
"description": "Typescript bindings for langchain",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -697,7 +697,7 @@
|
|
|
697
697
|
"@mozilla/readability": "^0.4.4",
|
|
698
698
|
"@notionhq/client": "^2.2.10",
|
|
699
699
|
"@opensearch-project/opensearch": "^2.2.0",
|
|
700
|
-
"@pinecone-database/pinecone": "^
|
|
700
|
+
"@pinecone-database/pinecone": "^1.1.0",
|
|
701
701
|
"@planetscale/database": "^1.8.0",
|
|
702
702
|
"@qdrant/js-client-rest": "^1.2.0",
|
|
703
703
|
"@raycast/api": "^1.55.2",
|
|
@@ -820,7 +820,7 @@
|
|
|
820
820
|
"@mozilla/readability": "*",
|
|
821
821
|
"@notionhq/client": "^2.2.10",
|
|
822
822
|
"@opensearch-project/opensearch": "*",
|
|
823
|
-
"@pinecone-database/pinecone": "
|
|
823
|
+
"@pinecone-database/pinecone": "^1.1.0",
|
|
824
824
|
"@planetscale/database": "^1.8.0",
|
|
825
825
|
"@qdrant/js-client-rest": "^1.2.0",
|
|
826
826
|
"@raycast/api": "^1.55.2",
|