langchain 0.0.164 → 0.0.166
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/cache/momento.cjs +7 -7
- package/dist/cache/momento.d.ts +1 -1
- package/dist/cache/momento.js +1 -1
- 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/fs/unstructured.cjs +40 -0
- package/dist/document_loaders/fs/unstructured.d.ts +27 -0
- package/dist/document_loaders/fs/unstructured.js +40 -0
- package/dist/embeddings/minimax.cjs +1 -1
- package/dist/embeddings/minimax.js +1 -1
- package/dist/experimental/chat_models/anthropic_functions.cjs +34 -2
- package/dist/experimental/chat_models/anthropic_functions.d.ts +15 -5
- package/dist/experimental/chat_models/anthropic_functions.js +34 -2
- 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 +4 -0
- package/dist/load/import_constants.js +4 -0
- package/dist/load/import_map.cjs +3 -1
- package/dist/load/import_map.d.ts +2 -0
- package/dist/load/import_map.js +2 -0
- package/dist/output_parsers/list.cjs +1 -1
- package/dist/output_parsers/list.js +1 -1
- package/dist/prompts/chat.cjs +19 -2
- package/dist/prompts/chat.d.ts +1 -0
- package/dist/prompts/chat.js +19 -2
- package/dist/retrievers/self_query/base.cjs +4 -1
- package/dist/retrievers/self_query/base.d.ts +3 -2
- package/dist/retrievers/self_query/base.js +4 -1
- package/dist/retrievers/self_query/index.cjs +2 -2
- package/dist/retrievers/self_query/index.d.ts +2 -0
- package/dist/retrievers/self_query/index.js +2 -2
- package/dist/runnables/remote.cjs +225 -0
- package/dist/runnables/remote.d.ts +28 -0
- package/dist/runnables/remote.js +221 -0
- package/dist/schema/index.cjs +1 -1
- package/dist/schema/index.d.ts +1 -1
- package/dist/schema/index.js +1 -1
- package/dist/schema/runnable/base.cjs +4 -4
- package/dist/schema/runnable/base.d.ts +9 -7
- package/dist/schema/runnable/base.js +4 -4
- package/dist/schema/runnable/remote.cjs +225 -0
- package/dist/schema/runnable/remote.d.ts +28 -0
- package/dist/schema/runnable/remote.js +221 -0
- package/dist/stores/message/momento.cjs +11 -11
- package/dist/stores/message/momento.d.ts +1 -1
- package/dist/stores/message/momento.js +1 -1
- package/dist/util/time.cjs +14 -0
- package/dist/util/time.d.ts +6 -0
- package/dist/util/time.js +10 -0
- 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/momento_vector_index.cjs +292 -0
- package/dist/vectorstores/momento_vector_index.d.ts +135 -0
- package/dist/vectorstores/momento_vector_index.js +265 -0
- package/dist/vectorstores/mongodb_atlas.cjs +29 -39
- package/dist/vectorstores/mongodb_atlas.js +29 -39
- package/dist/vectorstores/supabase.cjs +37 -8
- package/dist/vectorstores/supabase.d.ts +28 -1
- package/dist/vectorstores/supabase.js +37 -8
- package/llms/portkey.cjs +1 -0
- package/llms/portkey.d.ts +1 -0
- package/llms/portkey.js +1 -0
- package/package.json +77 -4
- package/runnables/remote.cjs +1 -0
- package/runnables/remote.d.ts +1 -0
- package/runnables/remote.js +1 -0
- package/util/time.cjs +1 -0
- package/util/time.d.ts +1 -0
- package/util/time.js +1 -0
- package/vectorstores/cassandra.cjs +1 -0
- package/vectorstores/cassandra.d.ts +1 -0
- package/vectorstores/cassandra.js +1 -0
- package/vectorstores/momento_vector_index.cjs +1 -0
- package/vectorstores/momento_vector_index.d.ts +1 -0
- package/vectorstores/momento_vector_index.js +1 -0
|
@@ -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.
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.SupabaseVectorStore = void 0;
|
|
4
4
|
const base_js_1 = require("./base.cjs");
|
|
5
5
|
const document_js_1 = require("../document.cjs");
|
|
6
|
+
const math_js_1 = require("../util/math.cjs");
|
|
6
7
|
/**
|
|
7
8
|
* Class for interacting with a Supabase database to store and manage
|
|
8
9
|
* vectors.
|
|
@@ -103,14 +104,7 @@ class SupabaseVectorStore extends base_js_1.VectorStore {
|
|
|
103
104
|
await this.client.from(this.tableName).delete().eq("id", id);
|
|
104
105
|
}
|
|
105
106
|
}
|
|
106
|
-
|
|
107
|
-
* Performs a similarity search on the vector store.
|
|
108
|
-
* @param query The query vector.
|
|
109
|
-
* @param k The number of results to return.
|
|
110
|
-
* @param filter Optional filter to apply to the search.
|
|
111
|
-
* @returns A promise that resolves with the search results when the search is complete.
|
|
112
|
-
*/
|
|
113
|
-
async similaritySearchVectorWithScore(query, k, filter) {
|
|
107
|
+
async _searchSupabase(query, k, filter) {
|
|
114
108
|
if (filter && this.filter) {
|
|
115
109
|
throw new Error("cannot provide both `filter` and `this.filter`");
|
|
116
110
|
}
|
|
@@ -135,6 +129,17 @@ class SupabaseVectorStore extends base_js_1.VectorStore {
|
|
|
135
129
|
if (error) {
|
|
136
130
|
throw new Error(`Error searching for documents: ${error.code} ${error.message} ${error.details}`);
|
|
137
131
|
}
|
|
132
|
+
return searches;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Performs a similarity search on the vector store.
|
|
136
|
+
* @param query The query vector.
|
|
137
|
+
* @param k The number of results to return.
|
|
138
|
+
* @param filter Optional filter to apply to the search.
|
|
139
|
+
* @returns A promise that resolves with the search results when the search is complete.
|
|
140
|
+
*/
|
|
141
|
+
async similaritySearchVectorWithScore(query, k, filter) {
|
|
142
|
+
const searches = await this._searchSupabase(query, k, filter);
|
|
138
143
|
const result = searches.map((resp) => [
|
|
139
144
|
new document_js_1.Document({
|
|
140
145
|
metadata: resp.metadata,
|
|
@@ -144,6 +149,30 @@ class SupabaseVectorStore extends base_js_1.VectorStore {
|
|
|
144
149
|
]);
|
|
145
150
|
return result;
|
|
146
151
|
}
|
|
152
|
+
/**
|
|
153
|
+
* Return documents selected using the maximal marginal relevance.
|
|
154
|
+
* Maximal marginal relevance optimizes for similarity to the query AND diversity
|
|
155
|
+
* among selected documents.
|
|
156
|
+
*
|
|
157
|
+
* @param {string} query - Text to look up documents similar to.
|
|
158
|
+
* @param {number} options.k - Number of documents to return.
|
|
159
|
+
* @param {number} options.fetchK=20- Number of documents to fetch before passing to the MMR algorithm.
|
|
160
|
+
* @param {number} options.lambda=0.5 - Number between 0 and 1 that determines the degree of diversity among the results,
|
|
161
|
+
* where 0 corresponds to maximum diversity and 1 to minimum diversity.
|
|
162
|
+
* @param {SupabaseLibArgs} options.filter - Optional filter to apply to the search.
|
|
163
|
+
*
|
|
164
|
+
* @returns {Promise<Document[]>} - List of documents selected by maximal marginal relevance.
|
|
165
|
+
*/
|
|
166
|
+
async maxMarginalRelevanceSearch(query, options) {
|
|
167
|
+
const queryEmbedding = await this.embeddings.embedQuery(query);
|
|
168
|
+
const searches = await this._searchSupabase(queryEmbedding, options.fetchK ?? 20, options.filter);
|
|
169
|
+
const embeddingList = searches.map((searchResp) => searchResp.embedding);
|
|
170
|
+
const mmrIndexes = (0, math_js_1.maximalMarginalRelevance)(queryEmbedding, embeddingList, options.lambda, options.k);
|
|
171
|
+
return mmrIndexes.map((idx) => new document_js_1.Document({
|
|
172
|
+
metadata: searches[idx].metadata,
|
|
173
|
+
pageContent: searches[idx].content,
|
|
174
|
+
}));
|
|
175
|
+
}
|
|
147
176
|
/**
|
|
148
177
|
* Creates a new SupabaseVectorStore instance from an array of texts.
|
|
149
178
|
* @param texts The texts to create documents from.
|
|
@@ -1,11 +1,21 @@
|
|
|
1
1
|
import type { SupabaseClient } from "@supabase/supabase-js";
|
|
2
2
|
import type { PostgrestFilterBuilder } from "@supabase/postgrest-js";
|
|
3
|
-
import { VectorStore } from "./base.js";
|
|
3
|
+
import { MaxMarginalRelevanceSearchOptions, VectorStore } from "./base.js";
|
|
4
4
|
import { Embeddings } from "../embeddings/base.js";
|
|
5
5
|
import { Document } from "../document.js";
|
|
6
6
|
export type SupabaseMetadata = Record<string, any>;
|
|
7
7
|
export type SupabaseFilter = PostgrestFilterBuilder<any, any, any>;
|
|
8
8
|
export type SupabaseFilterRPCCall = (rpcCall: SupabaseFilter) => SupabaseFilter;
|
|
9
|
+
/**
|
|
10
|
+
* Interface for the response returned when searching embeddings.
|
|
11
|
+
*/
|
|
12
|
+
interface SearchEmbeddingsResponse {
|
|
13
|
+
id: number;
|
|
14
|
+
content: string;
|
|
15
|
+
metadata: object;
|
|
16
|
+
embedding: number[];
|
|
17
|
+
similarity: number;
|
|
18
|
+
}
|
|
9
19
|
/**
|
|
10
20
|
* Interface for the arguments required to initialize a Supabase library.
|
|
11
21
|
*/
|
|
@@ -56,6 +66,7 @@ export declare class SupabaseVectorStore extends VectorStore {
|
|
|
56
66
|
delete(params: {
|
|
57
67
|
ids: string[] | number[];
|
|
58
68
|
}): Promise<void>;
|
|
69
|
+
protected _searchSupabase(query: number[], k: number, filter?: this["FilterType"]): Promise<SearchEmbeddingsResponse[]>;
|
|
59
70
|
/**
|
|
60
71
|
* Performs a similarity search on the vector store.
|
|
61
72
|
* @param query The query vector.
|
|
@@ -64,6 +75,21 @@ export declare class SupabaseVectorStore extends VectorStore {
|
|
|
64
75
|
* @returns A promise that resolves with the search results when the search is complete.
|
|
65
76
|
*/
|
|
66
77
|
similaritySearchVectorWithScore(query: number[], k: number, filter?: this["FilterType"]): Promise<[Document, number][]>;
|
|
78
|
+
/**
|
|
79
|
+
* Return documents selected using the maximal marginal relevance.
|
|
80
|
+
* Maximal marginal relevance optimizes for similarity to the query AND diversity
|
|
81
|
+
* among selected documents.
|
|
82
|
+
*
|
|
83
|
+
* @param {string} query - Text to look up documents similar to.
|
|
84
|
+
* @param {number} options.k - Number of documents to return.
|
|
85
|
+
* @param {number} options.fetchK=20- Number of documents to fetch before passing to the MMR algorithm.
|
|
86
|
+
* @param {number} options.lambda=0.5 - Number between 0 and 1 that determines the degree of diversity among the results,
|
|
87
|
+
* where 0 corresponds to maximum diversity and 1 to minimum diversity.
|
|
88
|
+
* @param {SupabaseLibArgs} options.filter - Optional filter to apply to the search.
|
|
89
|
+
*
|
|
90
|
+
* @returns {Promise<Document[]>} - List of documents selected by maximal marginal relevance.
|
|
91
|
+
*/
|
|
92
|
+
maxMarginalRelevanceSearch(query: string, options: MaxMarginalRelevanceSearchOptions<this["FilterType"]>): Promise<Document[]>;
|
|
67
93
|
/**
|
|
68
94
|
* Creates a new SupabaseVectorStore instance from an array of texts.
|
|
69
95
|
* @param texts The texts to create documents from.
|
|
@@ -89,3 +115,4 @@ export declare class SupabaseVectorStore extends VectorStore {
|
|
|
89
115
|
*/
|
|
90
116
|
static fromExistingIndex(embeddings: Embeddings, dbConfig: SupabaseLibArgs): Promise<SupabaseVectorStore>;
|
|
91
117
|
}
|
|
118
|
+
export {};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { VectorStore } from "./base.js";
|
|
2
2
|
import { Document } from "../document.js";
|
|
3
|
+
import { maximalMarginalRelevance } from "../util/math.js";
|
|
3
4
|
/**
|
|
4
5
|
* Class for interacting with a Supabase database to store and manage
|
|
5
6
|
* vectors.
|
|
@@ -100,14 +101,7 @@ export class SupabaseVectorStore extends VectorStore {
|
|
|
100
101
|
await this.client.from(this.tableName).delete().eq("id", id);
|
|
101
102
|
}
|
|
102
103
|
}
|
|
103
|
-
|
|
104
|
-
* Performs a similarity search on the vector store.
|
|
105
|
-
* @param query The query vector.
|
|
106
|
-
* @param k The number of results to return.
|
|
107
|
-
* @param filter Optional filter to apply to the search.
|
|
108
|
-
* @returns A promise that resolves with the search results when the search is complete.
|
|
109
|
-
*/
|
|
110
|
-
async similaritySearchVectorWithScore(query, k, filter) {
|
|
104
|
+
async _searchSupabase(query, k, filter) {
|
|
111
105
|
if (filter && this.filter) {
|
|
112
106
|
throw new Error("cannot provide both `filter` and `this.filter`");
|
|
113
107
|
}
|
|
@@ -132,6 +126,17 @@ export class SupabaseVectorStore extends VectorStore {
|
|
|
132
126
|
if (error) {
|
|
133
127
|
throw new Error(`Error searching for documents: ${error.code} ${error.message} ${error.details}`);
|
|
134
128
|
}
|
|
129
|
+
return searches;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Performs a similarity search on the vector store.
|
|
133
|
+
* @param query The query vector.
|
|
134
|
+
* @param k The number of results to return.
|
|
135
|
+
* @param filter Optional filter to apply to the search.
|
|
136
|
+
* @returns A promise that resolves with the search results when the search is complete.
|
|
137
|
+
*/
|
|
138
|
+
async similaritySearchVectorWithScore(query, k, filter) {
|
|
139
|
+
const searches = await this._searchSupabase(query, k, filter);
|
|
135
140
|
const result = searches.map((resp) => [
|
|
136
141
|
new Document({
|
|
137
142
|
metadata: resp.metadata,
|
|
@@ -141,6 +146,30 @@ export class SupabaseVectorStore extends VectorStore {
|
|
|
141
146
|
]);
|
|
142
147
|
return result;
|
|
143
148
|
}
|
|
149
|
+
/**
|
|
150
|
+
* Return documents selected using the maximal marginal relevance.
|
|
151
|
+
* Maximal marginal relevance optimizes for similarity to the query AND diversity
|
|
152
|
+
* among selected documents.
|
|
153
|
+
*
|
|
154
|
+
* @param {string} query - Text to look up documents similar to.
|
|
155
|
+
* @param {number} options.k - Number of documents to return.
|
|
156
|
+
* @param {number} options.fetchK=20- Number of documents to fetch before passing to the MMR algorithm.
|
|
157
|
+
* @param {number} options.lambda=0.5 - Number between 0 and 1 that determines the degree of diversity among the results,
|
|
158
|
+
* where 0 corresponds to maximum diversity and 1 to minimum diversity.
|
|
159
|
+
* @param {SupabaseLibArgs} options.filter - Optional filter to apply to the search.
|
|
160
|
+
*
|
|
161
|
+
* @returns {Promise<Document[]>} - List of documents selected by maximal marginal relevance.
|
|
162
|
+
*/
|
|
163
|
+
async maxMarginalRelevanceSearch(query, options) {
|
|
164
|
+
const queryEmbedding = await this.embeddings.embedQuery(query);
|
|
165
|
+
const searches = await this._searchSupabase(queryEmbedding, options.fetchK ?? 20, options.filter);
|
|
166
|
+
const embeddingList = searches.map((searchResp) => searchResp.embedding);
|
|
167
|
+
const mmrIndexes = maximalMarginalRelevance(queryEmbedding, embeddingList, options.lambda, options.k);
|
|
168
|
+
return mmrIndexes.map((idx) => new Document({
|
|
169
|
+
metadata: searches[idx].metadata,
|
|
170
|
+
pageContent: searches[idx].content,
|
|
171
|
+
}));
|
|
172
|
+
}
|
|
144
173
|
/**
|
|
145
174
|
* Creates a new SupabaseVectorStore instance from an array of texts.
|
|
146
175
|
* @param texts The texts to create documents from.
|
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.166",
|
|
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",
|
|
@@ -211,6 +217,9 @@
|
|
|
211
217
|
"vectorstores/lancedb.cjs",
|
|
212
218
|
"vectorstores/lancedb.js",
|
|
213
219
|
"vectorstores/lancedb.d.ts",
|
|
220
|
+
"vectorstores/momento_vector_index.cjs",
|
|
221
|
+
"vectorstores/momento_vector_index.js",
|
|
222
|
+
"vectorstores/momento_vector_index.d.ts",
|
|
214
223
|
"vectorstores/mongo.cjs",
|
|
215
224
|
"vectorstores/mongo.js",
|
|
216
225
|
"vectorstores/mongo.d.ts",
|
|
@@ -412,6 +421,9 @@
|
|
|
412
421
|
"chat_models/openai.cjs",
|
|
413
422
|
"chat_models/openai.js",
|
|
414
423
|
"chat_models/openai.d.ts",
|
|
424
|
+
"chat_models/portkey.cjs",
|
|
425
|
+
"chat_models/portkey.js",
|
|
426
|
+
"chat_models/portkey.d.ts",
|
|
415
427
|
"chat_models/anthropic.cjs",
|
|
416
428
|
"chat_models/anthropic.js",
|
|
417
429
|
"chat_models/anthropic.d.ts",
|
|
@@ -628,6 +640,9 @@
|
|
|
628
640
|
"util/math.cjs",
|
|
629
641
|
"util/math.js",
|
|
630
642
|
"util/math.d.ts",
|
|
643
|
+
"util/time.cjs",
|
|
644
|
+
"util/time.js",
|
|
645
|
+
"util/time.d.ts",
|
|
631
646
|
"experimental/autogpt.cjs",
|
|
632
647
|
"experimental/autogpt.js",
|
|
633
648
|
"experimental/autogpt.d.ts",
|
|
@@ -658,6 +673,9 @@
|
|
|
658
673
|
"evaluation.cjs",
|
|
659
674
|
"evaluation.js",
|
|
660
675
|
"evaluation.d.ts",
|
|
676
|
+
"runnables/remote.cjs",
|
|
677
|
+
"runnables/remote.js",
|
|
678
|
+
"runnables/remote.d.ts",
|
|
661
679
|
"index.cjs",
|
|
662
680
|
"index.js",
|
|
663
681
|
"index.d.ts"
|
|
@@ -693,7 +711,7 @@
|
|
|
693
711
|
"@aws-sdk/client-kendra": "^3.352.0",
|
|
694
712
|
"@aws-sdk/client-lambda": "^3.310.0",
|
|
695
713
|
"@aws-sdk/client-s3": "^3.310.0",
|
|
696
|
-
"@aws-sdk/client-sagemaker-runtime": "^3.
|
|
714
|
+
"@aws-sdk/client-sagemaker-runtime": "^3.414.0",
|
|
697
715
|
"@aws-sdk/client-sfn": "^3.362.0",
|
|
698
716
|
"@aws-sdk/credential-provider-node": "^3.388.0",
|
|
699
717
|
"@aws-sdk/types": "^3.357.0",
|
|
@@ -705,7 +723,8 @@
|
|
|
705
723
|
"@faker-js/faker": "^7.6.0",
|
|
706
724
|
"@getmetal/metal-sdk": "^4.0.0",
|
|
707
725
|
"@getzep/zep-js": "^0.7.0",
|
|
708
|
-
"@gomomento/sdk": "^1.
|
|
726
|
+
"@gomomento/sdk": "^1.41.2",
|
|
727
|
+
"@gomomento/sdk-core": "^1.41.2",
|
|
709
728
|
"@google-ai/generativelanguage": "^0.2.1",
|
|
710
729
|
"@google-cloud/storage": "^6.10.1",
|
|
711
730
|
"@huggingface/inference": "^1.5.1",
|
|
@@ -736,6 +755,7 @@
|
|
|
736
755
|
"@types/html-to-text": "^9",
|
|
737
756
|
"@types/js-yaml": "^4",
|
|
738
757
|
"@types/jsdom": "^21.1.1",
|
|
758
|
+
"@types/lodash": "^4",
|
|
739
759
|
"@types/mozilla-readability": "^0.2.1",
|
|
740
760
|
"@types/object-hash": "^3.0.2",
|
|
741
761
|
"@types/pdf-parse": "^1.1.1",
|
|
@@ -752,6 +772,7 @@
|
|
|
752
772
|
"@zilliz/milvus2-sdk-node": ">=2.2.11",
|
|
753
773
|
"apify-client": "^2.7.1",
|
|
754
774
|
"axios": "^0.26.0",
|
|
775
|
+
"cassandra-driver": "^4.6.4",
|
|
755
776
|
"cheerio": "^1.0.0-rc.12",
|
|
756
777
|
"chromadb": "^1.5.3",
|
|
757
778
|
"cohere-ai": ">=6.0.0",
|
|
@@ -779,6 +800,7 @@
|
|
|
779
800
|
"jest-environment-node": "^29.6.4",
|
|
780
801
|
"jsdom": "^22.1.0",
|
|
781
802
|
"llmonitor": "^0.5.4",
|
|
803
|
+
"lodash": "^4.17.21",
|
|
782
804
|
"mammoth": "^1.5.1",
|
|
783
805
|
"ml-matrix": "^6.10.4",
|
|
784
806
|
"mongodb": "^5.2.0",
|
|
@@ -792,6 +814,7 @@
|
|
|
792
814
|
"pg-copy-streams": "^6.0.5",
|
|
793
815
|
"pickleparser": "^0.1.0",
|
|
794
816
|
"playwright": "^1.32.1",
|
|
817
|
+
"portkey-ai": "^0.1.11",
|
|
795
818
|
"prettier": "^2.8.3",
|
|
796
819
|
"puppeteer": "^19.7.2",
|
|
797
820
|
"redis": "^4.6.6",
|
|
@@ -830,7 +853,9 @@
|
|
|
830
853
|
"@elastic/elasticsearch": "^8.4.0",
|
|
831
854
|
"@getmetal/metal-sdk": "*",
|
|
832
855
|
"@getzep/zep-js": "^0.7.0",
|
|
833
|
-
"@gomomento/sdk": "^1.
|
|
856
|
+
"@gomomento/sdk": "^1.41.2",
|
|
857
|
+
"@gomomento/sdk-core": "^1.41.2",
|
|
858
|
+
"@gomomento/sdk-web": "^1.41.2",
|
|
834
859
|
"@google-ai/generativelanguage": "^0.2.1",
|
|
835
860
|
"@google-cloud/storage": "^6.10.1",
|
|
836
861
|
"@huggingface/inference": "^1.5.1",
|
|
@@ -858,6 +883,7 @@
|
|
|
858
883
|
"@zilliz/milvus2-sdk-node": ">=2.2.7",
|
|
859
884
|
"apify-client": "^2.7.1",
|
|
860
885
|
"axios": "*",
|
|
886
|
+
"cassandra-driver": "^4.6.4",
|
|
861
887
|
"cheerio": "^1.0.0-rc.12",
|
|
862
888
|
"chromadb": "*",
|
|
863
889
|
"cohere-ai": ">=6.0.0",
|
|
@@ -874,6 +900,7 @@
|
|
|
874
900
|
"ioredis": "^5.3.2",
|
|
875
901
|
"jsdom": "*",
|
|
876
902
|
"llmonitor": "*",
|
|
903
|
+
"lodash": "^4.17.21",
|
|
877
904
|
"mammoth": "*",
|
|
878
905
|
"mongodb": "^5.2.0",
|
|
879
906
|
"mysql2": "^3.3.3",
|
|
@@ -886,6 +913,7 @@
|
|
|
886
913
|
"pg-copy-streams": "^6.0.5",
|
|
887
914
|
"pickleparser": "^0.1.0",
|
|
888
915
|
"playwright": "^1.32.1",
|
|
916
|
+
"portkey-ai": "^0.1.11",
|
|
889
917
|
"puppeteer": "^19.7.2",
|
|
890
918
|
"redis": "^4.6.4",
|
|
891
919
|
"replicate": "^0.18.0",
|
|
@@ -950,6 +978,12 @@
|
|
|
950
978
|
"@gomomento/sdk": {
|
|
951
979
|
"optional": true
|
|
952
980
|
},
|
|
981
|
+
"@gomomento/sdk-core": {
|
|
982
|
+
"optional": true
|
|
983
|
+
},
|
|
984
|
+
"@gomomento/sdk-web": {
|
|
985
|
+
"optional": true
|
|
986
|
+
},
|
|
953
987
|
"@google-ai/generativelanguage": {
|
|
954
988
|
"optional": true
|
|
955
989
|
},
|
|
@@ -1031,6 +1065,9 @@
|
|
|
1031
1065
|
"axios": {
|
|
1032
1066
|
"optional": true
|
|
1033
1067
|
},
|
|
1068
|
+
"cassandra-driver": {
|
|
1069
|
+
"optional": true
|
|
1070
|
+
},
|
|
1034
1071
|
"cheerio": {
|
|
1035
1072
|
"optional": true
|
|
1036
1073
|
},
|
|
@@ -1079,6 +1116,9 @@
|
|
|
1079
1116
|
"llmonitor": {
|
|
1080
1117
|
"optional": true
|
|
1081
1118
|
},
|
|
1119
|
+
"lodash": {
|
|
1120
|
+
"optional": true
|
|
1121
|
+
},
|
|
1082
1122
|
"mammoth": {
|
|
1083
1123
|
"optional": true
|
|
1084
1124
|
},
|
|
@@ -1115,6 +1155,9 @@
|
|
|
1115
1155
|
"playwright": {
|
|
1116
1156
|
"optional": true
|
|
1117
1157
|
},
|
|
1158
|
+
"portkey-ai": {
|
|
1159
|
+
"optional": true
|
|
1160
|
+
},
|
|
1118
1161
|
"puppeteer": {
|
|
1119
1162
|
"optional": true
|
|
1120
1163
|
},
|
|
@@ -1470,6 +1513,11 @@
|
|
|
1470
1513
|
"import": "./llms/writer.js",
|
|
1471
1514
|
"require": "./llms/writer.cjs"
|
|
1472
1515
|
},
|
|
1516
|
+
"./llms/portkey": {
|
|
1517
|
+
"types": "./llms/portkey.d.ts",
|
|
1518
|
+
"import": "./llms/portkey.js",
|
|
1519
|
+
"require": "./llms/portkey.cjs"
|
|
1520
|
+
},
|
|
1473
1521
|
"./prompts": {
|
|
1474
1522
|
"types": "./prompts.d.ts",
|
|
1475
1523
|
"import": "./prompts.js",
|
|
@@ -1490,6 +1538,11 @@
|
|
|
1490
1538
|
"import": "./vectorstores/base.js",
|
|
1491
1539
|
"require": "./vectorstores/base.cjs"
|
|
1492
1540
|
},
|
|
1541
|
+
"./vectorstores/cassandra": {
|
|
1542
|
+
"types": "./vectorstores/cassandra.d.ts",
|
|
1543
|
+
"import": "./vectorstores/cassandra.js",
|
|
1544
|
+
"require": "./vectorstores/cassandra.cjs"
|
|
1545
|
+
},
|
|
1493
1546
|
"./vectorstores/elasticsearch": {
|
|
1494
1547
|
"types": "./vectorstores/elasticsearch.d.ts",
|
|
1495
1548
|
"import": "./vectorstores/elasticsearch.js",
|
|
@@ -1535,6 +1588,11 @@
|
|
|
1535
1588
|
"import": "./vectorstores/lancedb.js",
|
|
1536
1589
|
"require": "./vectorstores/lancedb.cjs"
|
|
1537
1590
|
},
|
|
1591
|
+
"./vectorstores/momento_vector_index": {
|
|
1592
|
+
"types": "./vectorstores/momento_vector_index.d.ts",
|
|
1593
|
+
"import": "./vectorstores/momento_vector_index.js",
|
|
1594
|
+
"require": "./vectorstores/momento_vector_index.cjs"
|
|
1595
|
+
},
|
|
1538
1596
|
"./vectorstores/mongo": {
|
|
1539
1597
|
"types": "./vectorstores/mongo.d.ts",
|
|
1540
1598
|
"import": "./vectorstores/mongo.js",
|
|
@@ -1870,6 +1928,11 @@
|
|
|
1870
1928
|
"import": "./chat_models/openai.js",
|
|
1871
1929
|
"require": "./chat_models/openai.cjs"
|
|
1872
1930
|
},
|
|
1931
|
+
"./chat_models/portkey": {
|
|
1932
|
+
"types": "./chat_models/portkey.d.ts",
|
|
1933
|
+
"import": "./chat_models/portkey.js",
|
|
1934
|
+
"require": "./chat_models/portkey.cjs"
|
|
1935
|
+
},
|
|
1873
1936
|
"./chat_models/anthropic": {
|
|
1874
1937
|
"types": "./chat_models/anthropic.d.ts",
|
|
1875
1938
|
"import": "./chat_models/anthropic.js",
|
|
@@ -2230,6 +2293,11 @@
|
|
|
2230
2293
|
"import": "./util/math.js",
|
|
2231
2294
|
"require": "./util/math.cjs"
|
|
2232
2295
|
},
|
|
2296
|
+
"./util/time": {
|
|
2297
|
+
"types": "./util/time.d.ts",
|
|
2298
|
+
"import": "./util/time.js",
|
|
2299
|
+
"require": "./util/time.cjs"
|
|
2300
|
+
},
|
|
2233
2301
|
"./experimental/autogpt": {
|
|
2234
2302
|
"types": "./experimental/autogpt.d.ts",
|
|
2235
2303
|
"import": "./experimental/autogpt.js",
|
|
@@ -2280,6 +2348,11 @@
|
|
|
2280
2348
|
"import": "./evaluation.js",
|
|
2281
2349
|
"require": "./evaluation.cjs"
|
|
2282
2350
|
},
|
|
2351
|
+
"./runnables/remote": {
|
|
2352
|
+
"types": "./runnables/remote.d.ts",
|
|
2353
|
+
"import": "./runnables/remote.js",
|
|
2354
|
+
"require": "./runnables/remote.cjs"
|
|
2355
|
+
},
|
|
2283
2356
|
"./package.json": "./package.json"
|
|
2284
2357
|
}
|
|
2285
2358
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('../dist/runnables/remote.cjs');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../dist/runnables/remote.js'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../dist/runnables/remote.js'
|
package/util/time.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('../dist/util/time.cjs');
|
package/util/time.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../dist/util/time.js'
|
package/util/time.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../dist/util/time.js'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('../dist/vectorstores/cassandra.cjs');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../dist/vectorstores/cassandra.js'
|