langchain 0.0.160 → 0.0.161

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/dist/embeddings/bedrock.cjs +73 -0
  2. package/dist/embeddings/bedrock.d.ts +47 -0
  3. package/dist/embeddings/bedrock.js +69 -0
  4. package/dist/experimental/hubs/makersuite/googlemakersuitehub.cjs +297 -0
  5. package/dist/experimental/hubs/makersuite/googlemakersuitehub.d.ts +183 -0
  6. package/dist/experimental/hubs/makersuite/googlemakersuitehub.js +291 -0
  7. package/dist/load/import_constants.cjs +2 -0
  8. package/dist/load/import_constants.js +2 -0
  9. package/dist/load/import_map.cjs +4 -1
  10. package/dist/load/import_map.d.ts +3 -0
  11. package/dist/load/import_map.js +3 -0
  12. package/dist/retrievers/chaindesk.cjs +71 -0
  13. package/dist/retrievers/chaindesk.d.ts +18 -0
  14. package/dist/retrievers/chaindesk.js +67 -0
  15. package/dist/retrievers/contextual_compression.cjs +2 -2
  16. package/dist/retrievers/contextual_compression.js +2 -2
  17. package/dist/retrievers/databerry.cjs +1 -0
  18. package/dist/retrievers/databerry.d.ts +1 -0
  19. package/dist/retrievers/databerry.js +1 -0
  20. package/dist/retrievers/document_compressors/embeddings_filter.cjs +78 -0
  21. package/dist/retrievers/document_compressors/embeddings_filter.d.ts +39 -0
  22. package/dist/retrievers/document_compressors/embeddings_filter.js +74 -0
  23. package/dist/retrievers/document_compressors/index.cjs +33 -1
  24. package/dist/retrievers/document_compressors/index.d.ts +14 -1
  25. package/dist/retrievers/document_compressors/index.js +31 -0
  26. package/dist/retrievers/document_compressors/test/document_compressor.int.test.cjs +28 -0
  27. package/dist/retrievers/document_compressors/test/document_compressor.int.test.d.ts +1 -0
  28. package/dist/retrievers/document_compressors/test/document_compressor.int.test.js +26 -0
  29. package/dist/retrievers/tavily_search_api.cjs +144 -0
  30. package/dist/retrievers/tavily_search_api.d.ts +38 -0
  31. package/dist/retrievers/tavily_search_api.js +140 -0
  32. package/dist/schema/runnable/base.cjs +3 -0
  33. package/dist/schema/runnable/base.d.ts +1 -0
  34. package/dist/schema/runnable/base.js +3 -0
  35. package/dist/text_splitter.cjs +22 -8
  36. package/dist/text_splitter.d.ts +1 -0
  37. package/dist/text_splitter.js +22 -8
  38. package/dist/types/googlevertexai-types.d.ts +7 -5
  39. package/dist/util/googlevertexai-connection.cjs +35 -27
  40. package/dist/util/googlevertexai-connection.d.ts +12 -8
  41. package/dist/util/googlevertexai-connection.js +33 -26
  42. package/dist/util/googlevertexai-webauth.d.ts +2 -2
  43. package/dist/vectorstores/googlevertexai.d.ts +4 -4
  44. package/embeddings/bedrock.cjs +1 -0
  45. package/embeddings/bedrock.d.ts +1 -0
  46. package/embeddings/bedrock.js +1 -0
  47. package/experimental/hubs/makersuite/googlemakersuitehub.cjs +1 -0
  48. package/experimental/hubs/makersuite/googlemakersuitehub.d.ts +1 -0
  49. package/experimental/hubs/makersuite/googlemakersuitehub.js +1 -0
  50. package/package.json +46 -1
  51. package/retrievers/chaindesk.cjs +1 -0
  52. package/retrievers/chaindesk.d.ts +1 -0
  53. package/retrievers/chaindesk.js +1 -0
  54. package/retrievers/document_compressors/embeddings_filter.cjs +1 -0
  55. package/retrievers/document_compressors/embeddings_filter.d.ts +1 -0
  56. package/retrievers/document_compressors/embeddings_filter.js +1 -0
  57. package/retrievers/tavily_search_api.cjs +1 -0
  58. package/retrievers/tavily_search_api.d.ts +1 -0
  59. package/retrievers/tavily_search_api.js +1 -0
@@ -0,0 +1,291 @@
1
+ import { GoogleAuth } from "google-auth-library";
2
+ import { GooglePaLM } from "../../../llms/googlepalm.js";
3
+ import { ChatGooglePaLM } from "../../../chat_models/googlepalm.js";
4
+ import { PromptTemplate } from "../../../prompts/index.js";
5
+ import { AsyncCaller, } from "../../../util/async_caller.js";
6
+ import { GoogleConnection } from "../../../util/googlevertexai-connection.js";
7
+ /**
8
+ * A class that represents the Prompt that has been created by MakerSuite
9
+ * and loaded from Google Drive. It exposes methods to turn this prompt
10
+ * into a Template, a Model, and into a chain consisting of these two elements.
11
+ * In general, this class should be created by the MakerSuiteHub class and
12
+ * not instantiated manually.
13
+ */
14
+ export class MakerSuitePrompt {
15
+ constructor(promptData) {
16
+ Object.defineProperty(this, "promptType", {
17
+ enumerable: true,
18
+ configurable: true,
19
+ writable: true,
20
+ value: void 0
21
+ });
22
+ Object.defineProperty(this, "promptData", {
23
+ enumerable: true,
24
+ configurable: true,
25
+ writable: true,
26
+ value: void 0
27
+ });
28
+ this.promptData = promptData;
29
+ this._determinePromptType();
30
+ }
31
+ _determinePromptType() {
32
+ if (Object.hasOwn(this.promptData, "textPrompt")) {
33
+ this.promptType = "text";
34
+ }
35
+ else if (Object.hasOwn(this.promptData, "dataPrompt")) {
36
+ this.promptType = "data";
37
+ }
38
+ else if (Object.hasOwn(this.promptData, "multiturnPrompt")) {
39
+ this.promptType = "chat";
40
+ }
41
+ else {
42
+ const error = new Error("Unable to identify prompt type.");
43
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
44
+ error.promptData = this.promptData;
45
+ throw error;
46
+ }
47
+ }
48
+ _promptValueText() {
49
+ return (this.promptData?.textPrompt?.value ?? "");
50
+ }
51
+ _promptValueData() {
52
+ const promptData = this
53
+ .promptData;
54
+ const dataPrompt = promptData?.dataPrompt;
55
+ let prompt = `${dataPrompt?.preamble}\n` || "";
56
+ dataPrompt?.rows.forEach((row) => {
57
+ // Add the data for each row, as long as it is listed as used
58
+ if (dataPrompt?.rowsUsed.includes(row.rowId)) {
59
+ // Add each input column
60
+ dataPrompt?.columns.forEach((column) => {
61
+ if (column.isInput) {
62
+ prompt += `${column.displayName} ${row.columnBindings[column.columnId]}\n`;
63
+ }
64
+ });
65
+ // Add each output column
66
+ dataPrompt?.columns.forEach((column) => {
67
+ if (!column.isInput) {
68
+ prompt += `${column.displayName} ${row.columnBindings[column.columnId]}\n`;
69
+ }
70
+ });
71
+ }
72
+ });
73
+ // Add the input column prompts
74
+ dataPrompt?.columns.forEach((column) => {
75
+ if (column.isInput) {
76
+ prompt += `${column.displayName} {${column.displayName.replace(":", "")}}\n`;
77
+ }
78
+ });
79
+ // Add just the first output column
80
+ const firstOutput = dataPrompt?.columns.find((column) => !column.isInput);
81
+ prompt += `${firstOutput?.displayName} `;
82
+ return prompt;
83
+ }
84
+ _promptValueChat() {
85
+ return (this.promptData?.multiturnPrompt
86
+ ?.preamble ?? "");
87
+ }
88
+ _promptValue() {
89
+ switch (this.promptType) {
90
+ case "text":
91
+ return this._promptValueText();
92
+ case "data":
93
+ return this._promptValueData();
94
+ case "chat":
95
+ return this._promptValueChat();
96
+ default:
97
+ throw new Error(`Invalid promptType: ${this.promptType}`);
98
+ }
99
+ }
100
+ /**
101
+ * Create a template from the prompt, including any "test input" specified
102
+ * in MakerSuite as a template parameter.
103
+ */
104
+ toTemplate() {
105
+ const value = this._promptValue();
106
+ const promptString = value.replaceAll(/{{.*:(.+):.*}}/g, "{$1}");
107
+ return PromptTemplate.fromTemplate(promptString);
108
+ }
109
+ _modelName() {
110
+ let ret = this.promptData?.runSettings?.model;
111
+ if (!ret) {
112
+ ret =
113
+ this.promptType === "chat"
114
+ ? "models/chat-bison-001"
115
+ : "models/text-bison-001";
116
+ }
117
+ return ret;
118
+ }
119
+ _examples() {
120
+ const promptData = this
121
+ .promptData;
122
+ const ret = promptData?.multiturnPrompt?.primingExchanges
123
+ .map((exchange) => {
124
+ const example = {};
125
+ if (exchange?.request) {
126
+ example.input = {
127
+ content: exchange.request,
128
+ };
129
+ }
130
+ if (exchange?.response) {
131
+ example.output = {
132
+ content: exchange.response,
133
+ };
134
+ }
135
+ return example;
136
+ })
137
+ .filter((value) => Object.keys(value).length);
138
+ return ret;
139
+ }
140
+ /**
141
+ * Create a model from the prompt with all the parameters (model name,
142
+ * temperature, etc) set as they were in MakerSuite.
143
+ */
144
+ toModel() {
145
+ const modelName = this._modelName();
146
+ const modelSettings = {
147
+ modelName,
148
+ ...this.promptData?.runSettings,
149
+ };
150
+ if (this.promptType === "chat") {
151
+ const examples = this._examples();
152
+ return new ChatGooglePaLM({
153
+ examples,
154
+ ...modelSettings,
155
+ });
156
+ }
157
+ else {
158
+ return new GooglePaLM(modelSettings);
159
+ }
160
+ }
161
+ /**
162
+ * Create a RunnableSequence based on the template and model that can
163
+ * be created from this prompt. The template will have parameters available
164
+ * based on the "test input" that was set in MakerSuite, and the model
165
+ * will have the parameters (model name, temperature, etc) from those in
166
+ * MakerSuite.
167
+ */
168
+ toChain() {
169
+ return this.toTemplate().pipe(this.toModel());
170
+ }
171
+ }
172
+ export class DriveFileReadConnection extends GoogleConnection {
173
+ constructor(fields, caller) {
174
+ super(caller, new GoogleAuth({
175
+ scopes: "https://www.googleapis.com/auth/drive.readonly",
176
+ ...fields.authOptions,
177
+ }));
178
+ Object.defineProperty(this, "endpoint", {
179
+ enumerable: true,
180
+ configurable: true,
181
+ writable: true,
182
+ value: void 0
183
+ });
184
+ Object.defineProperty(this, "apiVersion", {
185
+ enumerable: true,
186
+ configurable: true,
187
+ writable: true,
188
+ value: void 0
189
+ });
190
+ Object.defineProperty(this, "fileId", {
191
+ enumerable: true,
192
+ configurable: true,
193
+ writable: true,
194
+ value: void 0
195
+ });
196
+ this.endpoint = fields.endpoint ?? "www.googleapis.com";
197
+ this.apiVersion = fields.apiVersion ?? "v3";
198
+ this.fileId = fields.fileId;
199
+ }
200
+ async buildUrl() {
201
+ return `https://${this.endpoint}/drive/${this.apiVersion}/files/${this.fileId}?alt=media`;
202
+ }
203
+ buildMethod() {
204
+ return "GET";
205
+ }
206
+ async request(options) {
207
+ return this._request(undefined, options ?? {});
208
+ }
209
+ }
210
+ /**
211
+ * A class allowing access to MakerSuite prompts that have been saved in
212
+ * Google Drive.
213
+ * MakerSuite prompts are pulled based on their Google Drive ID (which is available
214
+ * from Google Drive or as part of the URL when the prompt is open in MakerSuite).
215
+ * There is a basic cache that will store the prompt in memory for a time specified
216
+ * in milliseconds. This defaults to 0, indicating the prompt should always be
217
+ * pulled from Google Drive.
218
+ */
219
+ export class MakerSuiteHub {
220
+ constructor(config) {
221
+ Object.defineProperty(this, "cache", {
222
+ enumerable: true,
223
+ configurable: true,
224
+ writable: true,
225
+ value: {}
226
+ });
227
+ Object.defineProperty(this, "cacheTimeout", {
228
+ enumerable: true,
229
+ configurable: true,
230
+ writable: true,
231
+ value: void 0
232
+ });
233
+ Object.defineProperty(this, "caller", {
234
+ enumerable: true,
235
+ configurable: true,
236
+ writable: true,
237
+ value: void 0
238
+ });
239
+ this.cacheTimeout = config?.cacheTimeout ?? 0;
240
+ this.caller = config?.caller ?? new AsyncCaller({});
241
+ }
242
+ /**
243
+ * Is the current cache entry valid, or does it need to be refreshed.
244
+ * It will need to be refreshed under any of the following conditions:
245
+ * - It does not currently exist in the cache
246
+ * - The cacheTimeout is 0
247
+ * - The cache was last updated longer ago than the cacheTimeout allows
248
+ * @param entry - The cache entry, including when this prompt was last refreshed
249
+ */
250
+ isValid(entry) {
251
+ // If we don't have a record, it can't be valid
252
+ // And if the cache timeout is 0, we will always refresh, so the cache is invalid
253
+ if (!entry || this.cacheTimeout === 0) {
254
+ return false;
255
+ }
256
+ const now = Date.now();
257
+ const expiration = entry.updated + this.cacheTimeout;
258
+ return expiration > now;
259
+ }
260
+ /**
261
+ * Get a MakerSuitePrompt that is specified by the Google Drive ID.
262
+ * This will always be loaded from Google Drive.
263
+ * @param id
264
+ * @return A MakerSuitePrompt which can be used to create a template, model, or chain.
265
+ */
266
+ async forcePull(id) {
267
+ const fields = {
268
+ fileId: id,
269
+ };
270
+ const connection = new DriveFileReadConnection(fields, this.caller);
271
+ const result = await connection.request();
272
+ const ret = new MakerSuitePrompt(result.data);
273
+ this.cache[id] = {
274
+ prompt: ret,
275
+ updated: Date.now(),
276
+ };
277
+ return ret;
278
+ }
279
+ /**
280
+ * Get a MakerSuitePrompt that is specified by the Google Drive ID. This may be
281
+ * loaded from Google Drive or, if there is a valid copy in the cache, the cached
282
+ * copy will be returned.
283
+ * @param id
284
+ * @return A MakerSuitePrompt which can be used to create a template, model, or chain.
285
+ */
286
+ async pull(id) {
287
+ const entry = this.cache[id];
288
+ const ret = this.isValid(entry) ? entry.prompt : await this.forcePull(id);
289
+ return ret;
290
+ }
291
+ }
@@ -17,6 +17,7 @@ exports.optionalImportEntrypoints = [
17
17
  "langchain/chains/query_constructor/ir",
18
18
  "langchain/chains/sql_db",
19
19
  "langchain/chains/graph_qa/cypher",
20
+ "langchain/embeddings/bedrock",
20
21
  "langchain/embeddings/cloudflare_workersai",
21
22
  "langchain/embeddings/cohere",
22
23
  "langchain/embeddings/tensorflow",
@@ -140,4 +141,5 @@ exports.optionalImportEntrypoints = [
140
141
  "langchain/experimental/multimodal_embeddings/googlevertexai",
141
142
  "langchain/experimental/chat_models/anthropic_functions",
142
143
  "langchain/experimental/llms/bittensor",
144
+ "langchain/experimental/hubs/makersuite/googlemakersuitehub",
143
145
  ];
@@ -14,6 +14,7 @@ export const optionalImportEntrypoints = [
14
14
  "langchain/chains/query_constructor/ir",
15
15
  "langchain/chains/sql_db",
16
16
  "langchain/chains/graph_qa/cypher",
17
+ "langchain/embeddings/bedrock",
17
18
  "langchain/embeddings/cloudflare_workersai",
18
19
  "langchain/embeddings/cohere",
19
20
  "langchain/embeddings/tensorflow",
@@ -137,4 +138,5 @@ export const optionalImportEntrypoints = [
137
138
  "langchain/experimental/multimodal_embeddings/googlevertexai",
138
139
  "langchain/experimental/chat_models/anthropic_functions",
139
140
  "langchain/experimental/llms/bittensor",
141
+ "langchain/experimental/hubs/makersuite/googlemakersuitehub",
140
142
  ];
@@ -25,7 +25,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
25
25
  };
26
26
  Object.defineProperty(exports, "__esModule", { value: true });
27
27
  exports.retrievers__remote = exports.output_parsers = exports.callbacks = exports.schema__storage = exports.schema__runnable = exports.schema__retriever = exports.schema__query_constructor = exports.schema__output_parser = exports.schema__document = exports.schema = exports.chat_models__minimax = exports.chat_models__ollama = exports.chat_models__baiduwenxin = exports.chat_models__fireworks = exports.chat_models__anthropic = exports.chat_models__openai = exports.chat_models__base = exports.document_transformers__openai_functions = exports.document_loaders__web__sort_xyz_blockchain = exports.document_loaders__web__serpapi = exports.document_loaders__web__searchapi = exports.document_loaders__base = exports.document = exports.memory = exports.text_splitter = exports.vectorstores__xata = exports.vectorstores__vectara = exports.vectorstores__prisma = exports.vectorstores__memory = exports.vectorstores__base = exports.prompts = exports.llms__fireworks = exports.llms__ollama = exports.llms__aleph_alpha = exports.llms__ai21 = exports.llms__openai = exports.llms__base = exports.embeddings__minimax = exports.embeddings__openai = exports.embeddings__ollama = exports.embeddings__fake = exports.embeddings__cache_backed = exports.embeddings__base = exports.chains__openai_functions = exports.chains = exports.tools = exports.base_language = exports.agents__toolkits = exports.agents = exports.load__serializable = void 0;
28
- exports.evaluation = exports.experimental__chat_models__bittensor = exports.experimental__plan_and_execute = exports.experimental__generative_agents = exports.experimental__babyagi = exports.experimental__autogpt = exports.util__math = exports.storage__in_memory = exports.stores__message__in_memory = exports.stores__file__in_memory = exports.stores__doc__in_memory = exports.cache = exports.retrievers__vespa = exports.retrievers__score_threshold = exports.retrievers__hyde = exports.retrievers__document_compressors__chain_extract = exports.retrievers__time_weighted = exports.retrievers__parent_document = exports.retrievers__multi_vector = exports.retrievers__multi_query = exports.retrievers__document_compressors = exports.retrievers__contextual_compression = exports.retrievers__databerry = void 0;
28
+ exports.evaluation = exports.experimental__chat_models__bittensor = exports.experimental__plan_and_execute = exports.experimental__generative_agents = exports.experimental__babyagi = exports.experimental__autogpt = exports.util__math = exports.storage__in_memory = exports.stores__message__in_memory = exports.stores__file__in_memory = exports.stores__doc__in_memory = exports.cache = exports.retrievers__vespa = exports.retrievers__score_threshold = exports.retrievers__hyde = exports.retrievers__document_compressors__embeddings_filter = exports.retrievers__document_compressors__chain_extract = exports.retrievers__time_weighted = exports.retrievers__tavily_search_api = exports.retrievers__parent_document = exports.retrievers__multi_vector = exports.retrievers__multi_query = exports.retrievers__document_compressors = exports.retrievers__contextual_compression = exports.retrievers__databerry = exports.retrievers__chaindesk = void 0;
29
29
  exports.load__serializable = __importStar(require("../load/serializable.cjs"));
30
30
  exports.agents = __importStar(require("../agents/index.cjs"));
31
31
  exports.agents__toolkits = __importStar(require("../agents/toolkits/index.cjs"));
@@ -76,14 +76,17 @@ exports.schema__storage = __importStar(require("../schema/storage.cjs"));
76
76
  exports.callbacks = __importStar(require("../callbacks/index.cjs"));
77
77
  exports.output_parsers = __importStar(require("../output_parsers/index.cjs"));
78
78
  exports.retrievers__remote = __importStar(require("../retrievers/remote/index.cjs"));
79
+ exports.retrievers__chaindesk = __importStar(require("../retrievers/chaindesk.cjs"));
79
80
  exports.retrievers__databerry = __importStar(require("../retrievers/databerry.cjs"));
80
81
  exports.retrievers__contextual_compression = __importStar(require("../retrievers/contextual_compression.cjs"));
81
82
  exports.retrievers__document_compressors = __importStar(require("../retrievers/document_compressors/index.cjs"));
82
83
  exports.retrievers__multi_query = __importStar(require("../retrievers/multi_query.cjs"));
83
84
  exports.retrievers__multi_vector = __importStar(require("../retrievers/multi_vector.cjs"));
84
85
  exports.retrievers__parent_document = __importStar(require("../retrievers/parent_document.cjs"));
86
+ exports.retrievers__tavily_search_api = __importStar(require("../retrievers/tavily_search_api.cjs"));
85
87
  exports.retrievers__time_weighted = __importStar(require("../retrievers/time_weighted.cjs"));
86
88
  exports.retrievers__document_compressors__chain_extract = __importStar(require("../retrievers/document_compressors/chain_extract.cjs"));
89
+ exports.retrievers__document_compressors__embeddings_filter = __importStar(require("../retrievers/document_compressors/embeddings_filter.cjs"));
87
90
  exports.retrievers__hyde = __importStar(require("../retrievers/hyde.cjs"));
88
91
  exports.retrievers__score_threshold = __importStar(require("../retrievers/score_threshold.cjs"));
89
92
  exports.retrievers__vespa = __importStar(require("../retrievers/vespa.cjs"));
@@ -48,14 +48,17 @@ export * as schema__storage from "../schema/storage.js";
48
48
  export * as callbacks from "../callbacks/index.js";
49
49
  export * as output_parsers from "../output_parsers/index.js";
50
50
  export * as retrievers__remote from "../retrievers/remote/index.js";
51
+ export * as retrievers__chaindesk from "../retrievers/chaindesk.js";
51
52
  export * as retrievers__databerry from "../retrievers/databerry.js";
52
53
  export * as retrievers__contextual_compression from "../retrievers/contextual_compression.js";
53
54
  export * as retrievers__document_compressors from "../retrievers/document_compressors/index.js";
54
55
  export * as retrievers__multi_query from "../retrievers/multi_query.js";
55
56
  export * as retrievers__multi_vector from "../retrievers/multi_vector.js";
56
57
  export * as retrievers__parent_document from "../retrievers/parent_document.js";
58
+ export * as retrievers__tavily_search_api from "../retrievers/tavily_search_api.js";
57
59
  export * as retrievers__time_weighted from "../retrievers/time_weighted.js";
58
60
  export * as retrievers__document_compressors__chain_extract from "../retrievers/document_compressors/chain_extract.js";
61
+ export * as retrievers__document_compressors__embeddings_filter from "../retrievers/document_compressors/embeddings_filter.js";
59
62
  export * as retrievers__hyde from "../retrievers/hyde.js";
60
63
  export * as retrievers__score_threshold from "../retrievers/score_threshold.js";
61
64
  export * as retrievers__vespa from "../retrievers/vespa.js";
@@ -49,14 +49,17 @@ export * as schema__storage from "../schema/storage.js";
49
49
  export * as callbacks from "../callbacks/index.js";
50
50
  export * as output_parsers from "../output_parsers/index.js";
51
51
  export * as retrievers__remote from "../retrievers/remote/index.js";
52
+ export * as retrievers__chaindesk from "../retrievers/chaindesk.js";
52
53
  export * as retrievers__databerry from "../retrievers/databerry.js";
53
54
  export * as retrievers__contextual_compression from "../retrievers/contextual_compression.js";
54
55
  export * as retrievers__document_compressors from "../retrievers/document_compressors/index.js";
55
56
  export * as retrievers__multi_query from "../retrievers/multi_query.js";
56
57
  export * as retrievers__multi_vector from "../retrievers/multi_vector.js";
57
58
  export * as retrievers__parent_document from "../retrievers/parent_document.js";
59
+ export * as retrievers__tavily_search_api from "../retrievers/tavily_search_api.js";
58
60
  export * as retrievers__time_weighted from "../retrievers/time_weighted.js";
59
61
  export * as retrievers__document_compressors__chain_extract from "../retrievers/document_compressors/chain_extract.js";
62
+ export * as retrievers__document_compressors__embeddings_filter from "../retrievers/document_compressors/embeddings_filter.js";
60
63
  export * as retrievers__hyde from "../retrievers/hyde.js";
61
64
  export * as retrievers__score_threshold from "../retrievers/score_threshold.js";
62
65
  export * as retrievers__vespa from "../retrievers/vespa.js";
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ChaindeskRetriever = void 0;
4
+ const retriever_js_1 = require("../schema/retriever.cjs");
5
+ const document_js_1 = require("../document.cjs");
6
+ const async_caller_js_1 = require("../util/async_caller.cjs");
7
+ class ChaindeskRetriever extends retriever_js_1.BaseRetriever {
8
+ static lc_name() {
9
+ return "ChaindeskRetriever";
10
+ }
11
+ constructor({ datastoreId, apiKey, topK, ...rest }) {
12
+ super();
13
+ Object.defineProperty(this, "lc_namespace", {
14
+ enumerable: true,
15
+ configurable: true,
16
+ writable: true,
17
+ value: ["langchain", "retrievers", "chaindesk"]
18
+ });
19
+ Object.defineProperty(this, "caller", {
20
+ enumerable: true,
21
+ configurable: true,
22
+ writable: true,
23
+ value: void 0
24
+ });
25
+ Object.defineProperty(this, "datastoreId", {
26
+ enumerable: true,
27
+ configurable: true,
28
+ writable: true,
29
+ value: void 0
30
+ });
31
+ Object.defineProperty(this, "topK", {
32
+ enumerable: true,
33
+ configurable: true,
34
+ writable: true,
35
+ value: void 0
36
+ });
37
+ Object.defineProperty(this, "apiKey", {
38
+ enumerable: true,
39
+ configurable: true,
40
+ writable: true,
41
+ value: void 0
42
+ });
43
+ this.caller = new async_caller_js_1.AsyncCaller(rest);
44
+ this.datastoreId = datastoreId;
45
+ this.apiKey = apiKey;
46
+ this.topK = topK;
47
+ }
48
+ async getRelevantDocuments(query) {
49
+ const r = await this.caller.call(fetch, `https://app.chaindesk.ai/api/datastores/${this.datastoreId}/query`, {
50
+ method: "POST",
51
+ body: JSON.stringify({
52
+ query,
53
+ ...(this.topK ? { topK: this.topK } : {}),
54
+ }),
55
+ headers: {
56
+ "Content-Type": "application/json",
57
+ ...(this.apiKey ? { Authorization: `Bearer ${this.apiKey}` } : {}),
58
+ },
59
+ });
60
+ const { results } = (await r.json());
61
+ return results.map(({ text, score, source, ...rest }) => new document_js_1.Document({
62
+ pageContent: text,
63
+ metadata: {
64
+ score,
65
+ source,
66
+ ...rest,
67
+ },
68
+ }));
69
+ }
70
+ }
71
+ exports.ChaindeskRetriever = ChaindeskRetriever;
@@ -0,0 +1,18 @@
1
+ import { BaseRetriever, type BaseRetrieverInput } from "../schema/retriever.js";
2
+ import { Document } from "../document.js";
3
+ import { AsyncCaller, type AsyncCallerParams } from "../util/async_caller.js";
4
+ export interface ChaindeskRetrieverArgs extends AsyncCallerParams, BaseRetrieverInput {
5
+ datastoreId: string;
6
+ topK?: number;
7
+ apiKey?: string;
8
+ }
9
+ export declare class ChaindeskRetriever extends BaseRetriever {
10
+ static lc_name(): string;
11
+ lc_namespace: string[];
12
+ caller: AsyncCaller;
13
+ datastoreId: string;
14
+ topK?: number;
15
+ apiKey?: string;
16
+ constructor({ datastoreId, apiKey, topK, ...rest }: ChaindeskRetrieverArgs);
17
+ getRelevantDocuments(query: string): Promise<Document[]>;
18
+ }
@@ -0,0 +1,67 @@
1
+ import { BaseRetriever } from "../schema/retriever.js";
2
+ import { Document } from "../document.js";
3
+ import { AsyncCaller } from "../util/async_caller.js";
4
+ export class ChaindeskRetriever extends BaseRetriever {
5
+ static lc_name() {
6
+ return "ChaindeskRetriever";
7
+ }
8
+ constructor({ datastoreId, apiKey, topK, ...rest }) {
9
+ super();
10
+ Object.defineProperty(this, "lc_namespace", {
11
+ enumerable: true,
12
+ configurable: true,
13
+ writable: true,
14
+ value: ["langchain", "retrievers", "chaindesk"]
15
+ });
16
+ Object.defineProperty(this, "caller", {
17
+ enumerable: true,
18
+ configurable: true,
19
+ writable: true,
20
+ value: void 0
21
+ });
22
+ Object.defineProperty(this, "datastoreId", {
23
+ enumerable: true,
24
+ configurable: true,
25
+ writable: true,
26
+ value: void 0
27
+ });
28
+ Object.defineProperty(this, "topK", {
29
+ enumerable: true,
30
+ configurable: true,
31
+ writable: true,
32
+ value: void 0
33
+ });
34
+ Object.defineProperty(this, "apiKey", {
35
+ enumerable: true,
36
+ configurable: true,
37
+ writable: true,
38
+ value: void 0
39
+ });
40
+ this.caller = new AsyncCaller(rest);
41
+ this.datastoreId = datastoreId;
42
+ this.apiKey = apiKey;
43
+ this.topK = topK;
44
+ }
45
+ async getRelevantDocuments(query) {
46
+ const r = await this.caller.call(fetch, `https://app.chaindesk.ai/api/datastores/${this.datastoreId}/query`, {
47
+ method: "POST",
48
+ body: JSON.stringify({
49
+ query,
50
+ ...(this.topK ? { topK: this.topK } : {}),
51
+ }),
52
+ headers: {
53
+ "Content-Type": "application/json",
54
+ ...(this.apiKey ? { Authorization: `Bearer ${this.apiKey}` } : {}),
55
+ },
56
+ });
57
+ const { results } = (await r.json());
58
+ return results.map(({ text, score, source, ...rest }) => new Document({
59
+ pageContent: text,
60
+ metadata: {
61
+ score,
62
+ source,
63
+ ...rest,
64
+ },
65
+ }));
66
+ }
67
+ }
@@ -35,8 +35,8 @@ class ContextualCompressionRetriever extends retriever_js_1.BaseRetriever {
35
35
  this.baseRetriever = fields.baseRetriever;
36
36
  }
37
37
  async _getRelevantDocuments(query, runManager) {
38
- const docs = await this.baseRetriever._getRelevantDocuments(query, runManager);
39
- const compressedDocs = await this.baseCompressor.compressDocuments(docs, query);
38
+ const docs = await this.baseRetriever.getRelevantDocuments(query, runManager?.getChild("base_retriever"));
39
+ const compressedDocs = await this.baseCompressor.compressDocuments(docs, query, runManager?.getChild("base_compressor"));
40
40
  return compressedDocs;
41
41
  }
42
42
  }
@@ -32,8 +32,8 @@ export class ContextualCompressionRetriever extends BaseRetriever {
32
32
  this.baseRetriever = fields.baseRetriever;
33
33
  }
34
34
  async _getRelevantDocuments(query, runManager) {
35
- const docs = await this.baseRetriever._getRelevantDocuments(query, runManager);
36
- const compressedDocs = await this.baseCompressor.compressDocuments(docs, query);
35
+ const docs = await this.baseRetriever.getRelevantDocuments(query, runManager?.getChild("base_retriever"));
36
+ const compressedDocs = await this.baseCompressor.compressDocuments(docs, query, runManager?.getChild("base_compressor"));
37
37
  return compressedDocs;
38
38
  }
39
39
  }
@@ -9,6 +9,7 @@ const async_caller_js_1 = require("../util/async_caller.cjs");
9
9
  * API. It extends the BaseRetriever class, which is an abstract base
10
10
  * class for a document retrieval system in LangChain.
11
11
  */
12
+ /** @deprecated Use "langchain/retrievers/chaindesk" instead */
12
13
  class DataberryRetriever extends retriever_js_1.BaseRetriever {
13
14
  static lc_name() {
14
15
  return "DataberryRetriever";
@@ -15,6 +15,7 @@ export interface DataberryRetrieverArgs extends AsyncCallerParams, BaseRetriever
15
15
  * API. It extends the BaseRetriever class, which is an abstract base
16
16
  * class for a document retrieval system in LangChain.
17
17
  */
18
+ /** @deprecated Use "langchain/retrievers/chaindesk" instead */
18
19
  export declare class DataberryRetriever extends BaseRetriever {
19
20
  static lc_name(): string;
20
21
  lc_namespace: string[];
@@ -6,6 +6,7 @@ import { AsyncCaller } from "../util/async_caller.js";
6
6
  * API. It extends the BaseRetriever class, which is an abstract base
7
7
  * class for a document retrieval system in LangChain.
8
8
  */
9
+ /** @deprecated Use "langchain/retrievers/chaindesk" instead */
9
10
  export class DataberryRetriever extends BaseRetriever {
10
11
  static lc_name() {
11
12
  return "DataberryRetriever";