langchain 0.0.163 → 0.0.165
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/chat_models/portkey.cjs +1 -0
- package/chat_models/portkey.d.ts +1 -0
- package/chat_models/portkey.js +1 -0
- package/dist/chat_models/bedrock.cjs +3 -0
- package/dist/chat_models/bedrock.js +3 -0
- package/dist/chat_models/portkey.cjs +159 -0
- package/dist/chat_models/portkey.d.ts +17 -0
- package/dist/chat_models/portkey.js +155 -0
- package/dist/document_loaders/web/notionapi.cjs +28 -5
- package/dist/document_loaders/web/notionapi.d.ts +2 -0
- package/dist/document_loaders/web/notionapi.js +25 -5
- package/dist/embeddings/minimax.cjs +1 -1
- package/dist/embeddings/minimax.js +1 -1
- package/dist/graphs/neo4j_graph.cjs +86 -10
- package/dist/graphs/neo4j_graph.d.ts +2 -1
- package/dist/graphs/neo4j_graph.js +86 -10
- package/dist/llms/bedrock.cjs +3 -0
- package/dist/llms/bedrock.js +3 -0
- package/dist/llms/portkey.cjs +147 -0
- package/dist/llms/portkey.d.ts +33 -0
- package/dist/llms/portkey.js +138 -0
- package/dist/llms/sagemaker_endpoint.cjs +76 -14
- package/dist/llms/sagemaker_endpoint.d.ts +39 -20
- package/dist/llms/sagemaker_endpoint.js +77 -15
- package/dist/load/import_constants.cjs +3 -0
- package/dist/load/import_constants.js +3 -0
- package/dist/output_parsers/list.cjs +1 -1
- package/dist/output_parsers/list.js +1 -1
- package/dist/util/stream.cjs +4 -4
- package/dist/util/stream.js +4 -4
- package/dist/vectorstores/cassandra.cjs +212 -0
- package/dist/vectorstores/cassandra.d.ts +98 -0
- package/dist/vectorstores/cassandra.js +208 -0
- package/dist/vectorstores/mongodb_atlas.cjs +29 -39
- package/dist/vectorstores/mongodb_atlas.js +29 -39
- package/dist/vectorstores/prisma.d.ts +1 -1
- package/llms/portkey.cjs +1 -0
- package/llms/portkey.d.ts +1 -0
- package/llms/portkey.js +1 -0
- package/package.json +42 -2
- package/vectorstores/cassandra.cjs +1 -0
- package/vectorstores/cassandra.d.ts +1 -0
- package/vectorstores/cassandra.js +1 -0
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { DseClientOptions } from "cassandra-driver";
|
|
2
|
+
import { Embeddings } from "../embeddings/base.js";
|
|
3
|
+
import { VectorStore } from "./base.js";
|
|
4
|
+
import { Document } from "../document.js";
|
|
5
|
+
export interface Column {
|
|
6
|
+
type: string;
|
|
7
|
+
name: string;
|
|
8
|
+
}
|
|
9
|
+
export interface CassandraLibArgs extends DseClientOptions {
|
|
10
|
+
table: string;
|
|
11
|
+
keyspace: string;
|
|
12
|
+
dimensions: number;
|
|
13
|
+
primaryKey: Column;
|
|
14
|
+
metadataColumns: Column[];
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Class for interacting with the Cassandra database. It extends the
|
|
18
|
+
* VectorStore class and provides methods for adding vectors and
|
|
19
|
+
* documents, searching for similar vectors, and creating instances from
|
|
20
|
+
* texts or documents.
|
|
21
|
+
*/
|
|
22
|
+
export declare class CassandraStore extends VectorStore {
|
|
23
|
+
private client;
|
|
24
|
+
private readonly dimensions;
|
|
25
|
+
private readonly keyspace;
|
|
26
|
+
private primaryKey;
|
|
27
|
+
private metadataColumns;
|
|
28
|
+
private readonly table;
|
|
29
|
+
private isInitialized;
|
|
30
|
+
_vectorstoreType(): string;
|
|
31
|
+
constructor(embeddings: Embeddings, args: CassandraLibArgs);
|
|
32
|
+
/**
|
|
33
|
+
* Method to save vectors to the Cassandra database.
|
|
34
|
+
* @param vectors Vectors to save.
|
|
35
|
+
* @param documents The documents associated with the vectors.
|
|
36
|
+
* @returns Promise that resolves when the vectors have been added.
|
|
37
|
+
*/
|
|
38
|
+
addVectors(vectors: number[][], documents: Document[]): Promise<void>;
|
|
39
|
+
/**
|
|
40
|
+
* Method to add documents to the Cassandra database.
|
|
41
|
+
* @param documents The documents to add.
|
|
42
|
+
* @returns Promise that resolves when the documents have been added.
|
|
43
|
+
*/
|
|
44
|
+
addDocuments(documents: Document[]): Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* Method to search for vectors that are similar to a given query vector.
|
|
47
|
+
* @param query The query vector.
|
|
48
|
+
* @param k The number of similar vectors to return.
|
|
49
|
+
* @returns Promise that resolves with an array of tuples, each containing a Document and a score.
|
|
50
|
+
*/
|
|
51
|
+
similaritySearchVectorWithScore(query: number[], k: number): Promise<[Document, number][]>;
|
|
52
|
+
/**
|
|
53
|
+
* Static method to create an instance of CassandraStore from texts.
|
|
54
|
+
* @param texts The texts to use.
|
|
55
|
+
* @param metadatas The metadata associated with the texts.
|
|
56
|
+
* @param embeddings The embeddings to use.
|
|
57
|
+
* @param args The arguments for the CassandraStore.
|
|
58
|
+
* @returns Promise that resolves with a new instance of CassandraStore.
|
|
59
|
+
*/
|
|
60
|
+
static fromTexts(texts: string[], metadatas: object | object[], embeddings: Embeddings, args: CassandraLibArgs): Promise<CassandraStore>;
|
|
61
|
+
/**
|
|
62
|
+
* Static method to create an instance of CassandraStore from documents.
|
|
63
|
+
* @param docs The documents to use.
|
|
64
|
+
* @param embeddings The embeddings to use.
|
|
65
|
+
* @param args The arguments for the CassandraStore.
|
|
66
|
+
* @returns Promise that resolves with a new instance of CassandraStore.
|
|
67
|
+
*/
|
|
68
|
+
static fromDocuments(docs: Document[], embeddings: Embeddings, args: CassandraLibArgs): Promise<CassandraStore>;
|
|
69
|
+
/**
|
|
70
|
+
* Static method to create an instance of CassandraStore from an existing
|
|
71
|
+
* index.
|
|
72
|
+
* @param embeddings The embeddings to use.
|
|
73
|
+
* @param args The arguments for the CassandraStore.
|
|
74
|
+
* @returns Promise that resolves with a new instance of CassandraStore.
|
|
75
|
+
*/
|
|
76
|
+
static fromExistingIndex(embeddings: Embeddings, args: CassandraLibArgs): Promise<CassandraStore>;
|
|
77
|
+
/**
|
|
78
|
+
* Method to initialize the Cassandra database.
|
|
79
|
+
* @returns Promise that resolves when the database has been initialized.
|
|
80
|
+
*/
|
|
81
|
+
private initialize;
|
|
82
|
+
/**
|
|
83
|
+
* Method to build an CQL query for inserting vectors and documents into
|
|
84
|
+
* the Cassandra database.
|
|
85
|
+
* @param vectors The vectors to insert.
|
|
86
|
+
* @param documents The documents to insert.
|
|
87
|
+
* @returns The CQL query string.
|
|
88
|
+
*/
|
|
89
|
+
private buildInsertQuery;
|
|
90
|
+
/**
|
|
91
|
+
* Method to build an CQL query for searching for similar vectors in the
|
|
92
|
+
* Cassandra database.
|
|
93
|
+
* @param query The query vector.
|
|
94
|
+
* @param k The number of similar vectors to return.
|
|
95
|
+
* @returns The CQL query string.
|
|
96
|
+
*/
|
|
97
|
+
private buildSearchQuery;
|
|
98
|
+
}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
/* eslint-disable prefer-template */
|
|
2
|
+
import { Client as CassandraClient } from "cassandra-driver";
|
|
3
|
+
import { VectorStore } from "./base.js";
|
|
4
|
+
import { Document } from "../document.js";
|
|
5
|
+
/**
|
|
6
|
+
* Class for interacting with the Cassandra database. It extends the
|
|
7
|
+
* VectorStore class and provides methods for adding vectors and
|
|
8
|
+
* documents, searching for similar vectors, and creating instances from
|
|
9
|
+
* texts or documents.
|
|
10
|
+
*/
|
|
11
|
+
export class CassandraStore extends VectorStore {
|
|
12
|
+
_vectorstoreType() {
|
|
13
|
+
return "cassandra";
|
|
14
|
+
}
|
|
15
|
+
constructor(embeddings, args) {
|
|
16
|
+
super(embeddings, args);
|
|
17
|
+
Object.defineProperty(this, "client", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
configurable: true,
|
|
20
|
+
writable: true,
|
|
21
|
+
value: void 0
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(this, "dimensions", {
|
|
24
|
+
enumerable: true,
|
|
25
|
+
configurable: true,
|
|
26
|
+
writable: true,
|
|
27
|
+
value: void 0
|
|
28
|
+
});
|
|
29
|
+
Object.defineProperty(this, "keyspace", {
|
|
30
|
+
enumerable: true,
|
|
31
|
+
configurable: true,
|
|
32
|
+
writable: true,
|
|
33
|
+
value: void 0
|
|
34
|
+
});
|
|
35
|
+
Object.defineProperty(this, "primaryKey", {
|
|
36
|
+
enumerable: true,
|
|
37
|
+
configurable: true,
|
|
38
|
+
writable: true,
|
|
39
|
+
value: void 0
|
|
40
|
+
});
|
|
41
|
+
Object.defineProperty(this, "metadataColumns", {
|
|
42
|
+
enumerable: true,
|
|
43
|
+
configurable: true,
|
|
44
|
+
writable: true,
|
|
45
|
+
value: void 0
|
|
46
|
+
});
|
|
47
|
+
Object.defineProperty(this, "table", {
|
|
48
|
+
enumerable: true,
|
|
49
|
+
configurable: true,
|
|
50
|
+
writable: true,
|
|
51
|
+
value: void 0
|
|
52
|
+
});
|
|
53
|
+
Object.defineProperty(this, "isInitialized", {
|
|
54
|
+
enumerable: true,
|
|
55
|
+
configurable: true,
|
|
56
|
+
writable: true,
|
|
57
|
+
value: false
|
|
58
|
+
});
|
|
59
|
+
this.client = new CassandraClient(args);
|
|
60
|
+
this.dimensions = args.dimensions;
|
|
61
|
+
this.keyspace = args.keyspace;
|
|
62
|
+
this.table = args.table;
|
|
63
|
+
this.primaryKey = args.primaryKey;
|
|
64
|
+
this.metadataColumns = args.metadataColumns;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Method to save vectors to the Cassandra database.
|
|
68
|
+
* @param vectors Vectors to save.
|
|
69
|
+
* @param documents The documents associated with the vectors.
|
|
70
|
+
* @returns Promise that resolves when the vectors have been added.
|
|
71
|
+
*/
|
|
72
|
+
async addVectors(vectors, documents) {
|
|
73
|
+
if (vectors.length === 0) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
if (!this.isInitialized) {
|
|
77
|
+
await this.initialize();
|
|
78
|
+
}
|
|
79
|
+
const queries = this.buildInsertQuery(vectors, documents);
|
|
80
|
+
await this.client.batch(queries);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Method to add documents to the Cassandra database.
|
|
84
|
+
* @param documents The documents to add.
|
|
85
|
+
* @returns Promise that resolves when the documents have been added.
|
|
86
|
+
*/
|
|
87
|
+
async addDocuments(documents) {
|
|
88
|
+
return this.addVectors(await this.embeddings.embedDocuments(documents.map((d) => d.pageContent)), documents);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Method to search for vectors that are similar to a given query vector.
|
|
92
|
+
* @param query The query vector.
|
|
93
|
+
* @param k The number of similar vectors to return.
|
|
94
|
+
* @returns Promise that resolves with an array of tuples, each containing a Document and a score.
|
|
95
|
+
*/
|
|
96
|
+
async similaritySearchVectorWithScore(query, k) {
|
|
97
|
+
if (!this.isInitialized) {
|
|
98
|
+
await this.initialize();
|
|
99
|
+
}
|
|
100
|
+
const queryStr = this.buildSearchQuery(query, k);
|
|
101
|
+
const queryResultSet = await this.client.execute(queryStr);
|
|
102
|
+
return queryResultSet?.rows.map((row, index) => {
|
|
103
|
+
const textContent = row.text;
|
|
104
|
+
const sanitizedRow = Object.assign(row, {});
|
|
105
|
+
delete sanitizedRow.vector;
|
|
106
|
+
delete sanitizedRow.text;
|
|
107
|
+
return [
|
|
108
|
+
new Document({ pageContent: textContent, metadata: sanitizedRow }),
|
|
109
|
+
index,
|
|
110
|
+
];
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Static method to create an instance of CassandraStore from texts.
|
|
115
|
+
* @param texts The texts to use.
|
|
116
|
+
* @param metadatas The metadata associated with the texts.
|
|
117
|
+
* @param embeddings The embeddings to use.
|
|
118
|
+
* @param args The arguments for the CassandraStore.
|
|
119
|
+
* @returns Promise that resolves with a new instance of CassandraStore.
|
|
120
|
+
*/
|
|
121
|
+
static async fromTexts(texts, metadatas, embeddings, args) {
|
|
122
|
+
const docs = [];
|
|
123
|
+
for (let index = 0; index < texts.length; index += 1) {
|
|
124
|
+
const metadata = Array.isArray(metadatas) ? metadatas[index] : metadatas;
|
|
125
|
+
const doc = new Document({
|
|
126
|
+
pageContent: texts[index],
|
|
127
|
+
metadata,
|
|
128
|
+
});
|
|
129
|
+
docs.push(doc);
|
|
130
|
+
}
|
|
131
|
+
return CassandraStore.fromDocuments(docs, embeddings, args);
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Static method to create an instance of CassandraStore from documents.
|
|
135
|
+
* @param docs The documents to use.
|
|
136
|
+
* @param embeddings The embeddings to use.
|
|
137
|
+
* @param args The arguments for the CassandraStore.
|
|
138
|
+
* @returns Promise that resolves with a new instance of CassandraStore.
|
|
139
|
+
*/
|
|
140
|
+
static async fromDocuments(docs, embeddings, args) {
|
|
141
|
+
const instance = new this(embeddings, args);
|
|
142
|
+
await instance.addDocuments(docs);
|
|
143
|
+
return instance;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Static method to create an instance of CassandraStore from an existing
|
|
147
|
+
* index.
|
|
148
|
+
* @param embeddings The embeddings to use.
|
|
149
|
+
* @param args The arguments for the CassandraStore.
|
|
150
|
+
* @returns Promise that resolves with a new instance of CassandraStore.
|
|
151
|
+
*/
|
|
152
|
+
static async fromExistingIndex(embeddings, args) {
|
|
153
|
+
const instance = new this(embeddings, args);
|
|
154
|
+
await instance.initialize();
|
|
155
|
+
return instance;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Method to initialize the Cassandra database.
|
|
159
|
+
* @returns Promise that resolves when the database has been initialized.
|
|
160
|
+
*/
|
|
161
|
+
async initialize() {
|
|
162
|
+
await this.client.execute(`CREATE TABLE IF NOT EXISTS ${this.keyspace}.${this.table} (
|
|
163
|
+
${this.primaryKey.name} ${this.primaryKey.type} PRIMARY KEY,
|
|
164
|
+
text TEXT,
|
|
165
|
+
${this.metadataColumns.length > 0
|
|
166
|
+
? this.metadataColumns.map((col) => `${col.name} ${col.type},`)
|
|
167
|
+
: ""}
|
|
168
|
+
vector VECTOR<FLOAT, ${this.dimensions}>
|
|
169
|
+
);`);
|
|
170
|
+
await this.client.execute(`CREATE CUSTOM INDEX IF NOT EXISTS ann_index
|
|
171
|
+
ON ${this.keyspace}.${this.table}(vector) USING 'StorageAttachedIndex';`);
|
|
172
|
+
this.isInitialized = true;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Method to build an CQL query for inserting vectors and documents into
|
|
176
|
+
* the Cassandra database.
|
|
177
|
+
* @param vectors The vectors to insert.
|
|
178
|
+
* @param documents The documents to insert.
|
|
179
|
+
* @returns The CQL query string.
|
|
180
|
+
*/
|
|
181
|
+
buildInsertQuery(vectors, documents) {
|
|
182
|
+
const queries = [];
|
|
183
|
+
for (let index = 0; index < vectors.length; index += 1) {
|
|
184
|
+
const vector = vectors[index];
|
|
185
|
+
const document = documents[index];
|
|
186
|
+
const metadataColNames = Object.keys(document.metadata);
|
|
187
|
+
const metadataVals = Object.values(document.metadata);
|
|
188
|
+
const query = `INSERT INTO ${this.keyspace}.${this.table} (vector, text${metadataColNames.length > 0 ? ", " + metadataColNames.join(", ") : ""}) VALUES ([${vector}], '${document.pageContent}'${metadataVals.length > 0
|
|
189
|
+
? ", " +
|
|
190
|
+
metadataVals
|
|
191
|
+
.map((val) => (typeof val === "number" ? val : `'${val}'`))
|
|
192
|
+
.join(", ")
|
|
193
|
+
: ""});`;
|
|
194
|
+
queries.push(query);
|
|
195
|
+
}
|
|
196
|
+
return queries;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Method to build an CQL query for searching for similar vectors in the
|
|
200
|
+
* Cassandra database.
|
|
201
|
+
* @param query The query vector.
|
|
202
|
+
* @param k The number of similar vectors to return.
|
|
203
|
+
* @returns The CQL query string.
|
|
204
|
+
*/
|
|
205
|
+
buildSearchQuery(query, k) {
|
|
206
|
+
return `SELECT * FROM ${this.keyspace}.${this.table} ORDER BY vector ANN OF [${query}] LIMIT ${k || 1};`;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
@@ -81,57 +81,47 @@ class MongoDBAtlasVectorSearch extends base_js_1.VectorStore {
|
|
|
81
81
|
* @returns Promise that resolves to a list of documents and their corresponding similarity scores.
|
|
82
82
|
*/
|
|
83
83
|
async similaritySearchVectorWithScore(query, k, filter) {
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
path: this.embeddingKey,
|
|
87
|
-
k,
|
|
88
|
-
};
|
|
89
|
-
let preFilter;
|
|
90
|
-
let postFilterPipeline;
|
|
91
|
-
let includeEmbeddings;
|
|
92
|
-
if (filter?.preFilter ||
|
|
84
|
+
const postFilterPipeline = filter?.postFilterPipeline ?? [];
|
|
85
|
+
const preFilter = filter?.preFilter ||
|
|
93
86
|
filter?.postFilterPipeline ||
|
|
94
|
-
filter?.includeEmbeddings
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
87
|
+
filter?.includeEmbeddings
|
|
88
|
+
? filter.preFilter
|
|
89
|
+
: filter;
|
|
90
|
+
const removeEmbeddingsPipeline = !filter?.includeEmbeddings
|
|
91
|
+
? [
|
|
92
|
+
{
|
|
93
|
+
$project: {
|
|
94
|
+
[this.embeddingKey]: 0,
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
]
|
|
98
|
+
: [];
|
|
104
99
|
const pipeline = [
|
|
105
100
|
{
|
|
106
|
-
$
|
|
101
|
+
$vectorSearch: {
|
|
102
|
+
queryVector: query,
|
|
107
103
|
index: this.indexName,
|
|
108
|
-
|
|
104
|
+
path: this.embeddingKey,
|
|
105
|
+
limit: k,
|
|
106
|
+
numCandidates: 10 * k,
|
|
107
|
+
...(preFilter && { filter: preFilter }),
|
|
109
108
|
},
|
|
110
109
|
},
|
|
111
110
|
{
|
|
112
111
|
$set: {
|
|
113
|
-
score: { $meta: "
|
|
112
|
+
score: { $meta: "vectorSearchScore" },
|
|
114
113
|
},
|
|
115
114
|
},
|
|
115
|
+
...removeEmbeddingsPipeline,
|
|
116
|
+
...postFilterPipeline,
|
|
116
117
|
];
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
[this.embeddingKey]: 0,
|
|
121
|
-
},
|
|
122
|
-
};
|
|
123
|
-
pipeline.push(removeEmbeddingsStage);
|
|
124
|
-
}
|
|
125
|
-
if (postFilterPipeline) {
|
|
126
|
-
pipeline.push(...postFilterPipeline);
|
|
127
|
-
}
|
|
128
|
-
const results = this.collection.aggregate(pipeline);
|
|
129
|
-
const ret = [];
|
|
130
|
-
for await (const result of results) {
|
|
118
|
+
const results = this.collection
|
|
119
|
+
.aggregate(pipeline)
|
|
120
|
+
.map((result) => {
|
|
131
121
|
const { score, [this.textKey]: text, ...metadata } = result;
|
|
132
|
-
|
|
133
|
-
}
|
|
134
|
-
return
|
|
122
|
+
return [new document_js_1.Document({ pageContent: text, metadata }), score];
|
|
123
|
+
});
|
|
124
|
+
return results.toArray();
|
|
135
125
|
}
|
|
136
126
|
/**
|
|
137
127
|
* Return documents selected using the maximal marginal relevance.
|
|
@@ -78,57 +78,47 @@ export class MongoDBAtlasVectorSearch extends VectorStore {
|
|
|
78
78
|
* @returns Promise that resolves to a list of documents and their corresponding similarity scores.
|
|
79
79
|
*/
|
|
80
80
|
async similaritySearchVectorWithScore(query, k, filter) {
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
path: this.embeddingKey,
|
|
84
|
-
k,
|
|
85
|
-
};
|
|
86
|
-
let preFilter;
|
|
87
|
-
let postFilterPipeline;
|
|
88
|
-
let includeEmbeddings;
|
|
89
|
-
if (filter?.preFilter ||
|
|
81
|
+
const postFilterPipeline = filter?.postFilterPipeline ?? [];
|
|
82
|
+
const preFilter = filter?.preFilter ||
|
|
90
83
|
filter?.postFilterPipeline ||
|
|
91
|
-
filter?.includeEmbeddings
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
84
|
+
filter?.includeEmbeddings
|
|
85
|
+
? filter.preFilter
|
|
86
|
+
: filter;
|
|
87
|
+
const removeEmbeddingsPipeline = !filter?.includeEmbeddings
|
|
88
|
+
? [
|
|
89
|
+
{
|
|
90
|
+
$project: {
|
|
91
|
+
[this.embeddingKey]: 0,
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
]
|
|
95
|
+
: [];
|
|
101
96
|
const pipeline = [
|
|
102
97
|
{
|
|
103
|
-
$
|
|
98
|
+
$vectorSearch: {
|
|
99
|
+
queryVector: query,
|
|
104
100
|
index: this.indexName,
|
|
105
|
-
|
|
101
|
+
path: this.embeddingKey,
|
|
102
|
+
limit: k,
|
|
103
|
+
numCandidates: 10 * k,
|
|
104
|
+
...(preFilter && { filter: preFilter }),
|
|
106
105
|
},
|
|
107
106
|
},
|
|
108
107
|
{
|
|
109
108
|
$set: {
|
|
110
|
-
score: { $meta: "
|
|
109
|
+
score: { $meta: "vectorSearchScore" },
|
|
111
110
|
},
|
|
112
111
|
},
|
|
112
|
+
...removeEmbeddingsPipeline,
|
|
113
|
+
...postFilterPipeline,
|
|
113
114
|
];
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
[this.embeddingKey]: 0,
|
|
118
|
-
},
|
|
119
|
-
};
|
|
120
|
-
pipeline.push(removeEmbeddingsStage);
|
|
121
|
-
}
|
|
122
|
-
if (postFilterPipeline) {
|
|
123
|
-
pipeline.push(...postFilterPipeline);
|
|
124
|
-
}
|
|
125
|
-
const results = this.collection.aggregate(pipeline);
|
|
126
|
-
const ret = [];
|
|
127
|
-
for await (const result of results) {
|
|
115
|
+
const results = this.collection
|
|
116
|
+
.aggregate(pipeline)
|
|
117
|
+
.map((result) => {
|
|
128
118
|
const { score, [this.textKey]: text, ...metadata } = result;
|
|
129
|
-
|
|
130
|
-
}
|
|
131
|
-
return
|
|
119
|
+
return [new Document({ pageContent: text, metadata }), score];
|
|
120
|
+
});
|
|
121
|
+
return results.toArray();
|
|
132
122
|
}
|
|
133
123
|
/**
|
|
134
124
|
* Return documents selected using the maximal marginal relevance.
|
|
@@ -29,7 +29,7 @@ type ObjectIntersect<A, B> = {
|
|
|
29
29
|
type ModelColumns<TModel extends Record<string, unknown>> = {
|
|
30
30
|
[K in keyof TModel]?: true | ColumnSymbol;
|
|
31
31
|
};
|
|
32
|
-
type PrismaSqlFilter<TModel extends Record<string, unknown>> = {
|
|
32
|
+
export type PrismaSqlFilter<TModel extends Record<string, unknown>> = {
|
|
33
33
|
[K in keyof TModel]?: {
|
|
34
34
|
equals?: TModel[K];
|
|
35
35
|
lt?: TModel[K];
|
package/llms/portkey.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('../dist/llms/portkey.cjs');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../dist/llms/portkey.js'
|
package/llms/portkey.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../dist/llms/portkey.js'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "langchain",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.165",
|
|
4
4
|
"description": "Typescript bindings for langchain",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -172,6 +172,9 @@
|
|
|
172
172
|
"llms/writer.cjs",
|
|
173
173
|
"llms/writer.js",
|
|
174
174
|
"llms/writer.d.ts",
|
|
175
|
+
"llms/portkey.cjs",
|
|
176
|
+
"llms/portkey.js",
|
|
177
|
+
"llms/portkey.d.ts",
|
|
175
178
|
"prompts.cjs",
|
|
176
179
|
"prompts.js",
|
|
177
180
|
"prompts.d.ts",
|
|
@@ -184,6 +187,9 @@
|
|
|
184
187
|
"vectorstores/base.cjs",
|
|
185
188
|
"vectorstores/base.js",
|
|
186
189
|
"vectorstores/base.d.ts",
|
|
190
|
+
"vectorstores/cassandra.cjs",
|
|
191
|
+
"vectorstores/cassandra.js",
|
|
192
|
+
"vectorstores/cassandra.d.ts",
|
|
187
193
|
"vectorstores/elasticsearch.cjs",
|
|
188
194
|
"vectorstores/elasticsearch.js",
|
|
189
195
|
"vectorstores/elasticsearch.d.ts",
|
|
@@ -412,6 +418,9 @@
|
|
|
412
418
|
"chat_models/openai.cjs",
|
|
413
419
|
"chat_models/openai.js",
|
|
414
420
|
"chat_models/openai.d.ts",
|
|
421
|
+
"chat_models/portkey.cjs",
|
|
422
|
+
"chat_models/portkey.js",
|
|
423
|
+
"chat_models/portkey.d.ts",
|
|
415
424
|
"chat_models/anthropic.cjs",
|
|
416
425
|
"chat_models/anthropic.js",
|
|
417
426
|
"chat_models/anthropic.d.ts",
|
|
@@ -693,7 +702,7 @@
|
|
|
693
702
|
"@aws-sdk/client-kendra": "^3.352.0",
|
|
694
703
|
"@aws-sdk/client-lambda": "^3.310.0",
|
|
695
704
|
"@aws-sdk/client-s3": "^3.310.0",
|
|
696
|
-
"@aws-sdk/client-sagemaker-runtime": "^3.
|
|
705
|
+
"@aws-sdk/client-sagemaker-runtime": "^3.414.0",
|
|
697
706
|
"@aws-sdk/client-sfn": "^3.362.0",
|
|
698
707
|
"@aws-sdk/credential-provider-node": "^3.388.0",
|
|
699
708
|
"@aws-sdk/types": "^3.357.0",
|
|
@@ -736,6 +745,7 @@
|
|
|
736
745
|
"@types/html-to-text": "^9",
|
|
737
746
|
"@types/js-yaml": "^4",
|
|
738
747
|
"@types/jsdom": "^21.1.1",
|
|
748
|
+
"@types/lodash": "^4",
|
|
739
749
|
"@types/mozilla-readability": "^0.2.1",
|
|
740
750
|
"@types/object-hash": "^3.0.2",
|
|
741
751
|
"@types/pdf-parse": "^1.1.1",
|
|
@@ -752,6 +762,7 @@
|
|
|
752
762
|
"@zilliz/milvus2-sdk-node": ">=2.2.11",
|
|
753
763
|
"apify-client": "^2.7.1",
|
|
754
764
|
"axios": "^0.26.0",
|
|
765
|
+
"cassandra-driver": "^4.6.4",
|
|
755
766
|
"cheerio": "^1.0.0-rc.12",
|
|
756
767
|
"chromadb": "^1.5.3",
|
|
757
768
|
"cohere-ai": ">=6.0.0",
|
|
@@ -779,6 +790,7 @@
|
|
|
779
790
|
"jest-environment-node": "^29.6.4",
|
|
780
791
|
"jsdom": "^22.1.0",
|
|
781
792
|
"llmonitor": "^0.5.4",
|
|
793
|
+
"lodash": "^4.17.21",
|
|
782
794
|
"mammoth": "^1.5.1",
|
|
783
795
|
"ml-matrix": "^6.10.4",
|
|
784
796
|
"mongodb": "^5.2.0",
|
|
@@ -792,6 +804,7 @@
|
|
|
792
804
|
"pg-copy-streams": "^6.0.5",
|
|
793
805
|
"pickleparser": "^0.1.0",
|
|
794
806
|
"playwright": "^1.32.1",
|
|
807
|
+
"portkey-ai": "^0.1.11",
|
|
795
808
|
"prettier": "^2.8.3",
|
|
796
809
|
"puppeteer": "^19.7.2",
|
|
797
810
|
"redis": "^4.6.6",
|
|
@@ -858,6 +871,7 @@
|
|
|
858
871
|
"@zilliz/milvus2-sdk-node": ">=2.2.7",
|
|
859
872
|
"apify-client": "^2.7.1",
|
|
860
873
|
"axios": "*",
|
|
874
|
+
"cassandra-driver": "^4.6.4",
|
|
861
875
|
"cheerio": "^1.0.0-rc.12",
|
|
862
876
|
"chromadb": "*",
|
|
863
877
|
"cohere-ai": ">=6.0.0",
|
|
@@ -874,6 +888,7 @@
|
|
|
874
888
|
"ioredis": "^5.3.2",
|
|
875
889
|
"jsdom": "*",
|
|
876
890
|
"llmonitor": "*",
|
|
891
|
+
"lodash": "^4.17.21",
|
|
877
892
|
"mammoth": "*",
|
|
878
893
|
"mongodb": "^5.2.0",
|
|
879
894
|
"mysql2": "^3.3.3",
|
|
@@ -886,6 +901,7 @@
|
|
|
886
901
|
"pg-copy-streams": "^6.0.5",
|
|
887
902
|
"pickleparser": "^0.1.0",
|
|
888
903
|
"playwright": "^1.32.1",
|
|
904
|
+
"portkey-ai": "^0.1.11",
|
|
889
905
|
"puppeteer": "^19.7.2",
|
|
890
906
|
"redis": "^4.6.4",
|
|
891
907
|
"replicate": "^0.18.0",
|
|
@@ -1031,6 +1047,9 @@
|
|
|
1031
1047
|
"axios": {
|
|
1032
1048
|
"optional": true
|
|
1033
1049
|
},
|
|
1050
|
+
"cassandra-driver": {
|
|
1051
|
+
"optional": true
|
|
1052
|
+
},
|
|
1034
1053
|
"cheerio": {
|
|
1035
1054
|
"optional": true
|
|
1036
1055
|
},
|
|
@@ -1079,6 +1098,9 @@
|
|
|
1079
1098
|
"llmonitor": {
|
|
1080
1099
|
"optional": true
|
|
1081
1100
|
},
|
|
1101
|
+
"lodash": {
|
|
1102
|
+
"optional": true
|
|
1103
|
+
},
|
|
1082
1104
|
"mammoth": {
|
|
1083
1105
|
"optional": true
|
|
1084
1106
|
},
|
|
@@ -1115,6 +1137,9 @@
|
|
|
1115
1137
|
"playwright": {
|
|
1116
1138
|
"optional": true
|
|
1117
1139
|
},
|
|
1140
|
+
"portkey-ai": {
|
|
1141
|
+
"optional": true
|
|
1142
|
+
},
|
|
1118
1143
|
"puppeteer": {
|
|
1119
1144
|
"optional": true
|
|
1120
1145
|
},
|
|
@@ -1470,6 +1495,11 @@
|
|
|
1470
1495
|
"import": "./llms/writer.js",
|
|
1471
1496
|
"require": "./llms/writer.cjs"
|
|
1472
1497
|
},
|
|
1498
|
+
"./llms/portkey": {
|
|
1499
|
+
"types": "./llms/portkey.d.ts",
|
|
1500
|
+
"import": "./llms/portkey.js",
|
|
1501
|
+
"require": "./llms/portkey.cjs"
|
|
1502
|
+
},
|
|
1473
1503
|
"./prompts": {
|
|
1474
1504
|
"types": "./prompts.d.ts",
|
|
1475
1505
|
"import": "./prompts.js",
|
|
@@ -1490,6 +1520,11 @@
|
|
|
1490
1520
|
"import": "./vectorstores/base.js",
|
|
1491
1521
|
"require": "./vectorstores/base.cjs"
|
|
1492
1522
|
},
|
|
1523
|
+
"./vectorstores/cassandra": {
|
|
1524
|
+
"types": "./vectorstores/cassandra.d.ts",
|
|
1525
|
+
"import": "./vectorstores/cassandra.js",
|
|
1526
|
+
"require": "./vectorstores/cassandra.cjs"
|
|
1527
|
+
},
|
|
1493
1528
|
"./vectorstores/elasticsearch": {
|
|
1494
1529
|
"types": "./vectorstores/elasticsearch.d.ts",
|
|
1495
1530
|
"import": "./vectorstores/elasticsearch.js",
|
|
@@ -1870,6 +1905,11 @@
|
|
|
1870
1905
|
"import": "./chat_models/openai.js",
|
|
1871
1906
|
"require": "./chat_models/openai.cjs"
|
|
1872
1907
|
},
|
|
1908
|
+
"./chat_models/portkey": {
|
|
1909
|
+
"types": "./chat_models/portkey.d.ts",
|
|
1910
|
+
"import": "./chat_models/portkey.js",
|
|
1911
|
+
"require": "./chat_models/portkey.cjs"
|
|
1912
|
+
},
|
|
1873
1913
|
"./chat_models/anthropic": {
|
|
1874
1914
|
"types": "./chat_models/anthropic.d.ts",
|
|
1875
1915
|
"import": "./chat_models/anthropic.js",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('../dist/vectorstores/cassandra.cjs');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../dist/vectorstores/cassandra.js'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../dist/vectorstores/cassandra.js'
|