langchain 0.0.135 → 0.0.137

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 (46) hide show
  1. package/dist/chains/question_answering/map_reduce_prompts.d.ts +2 -2
  2. package/dist/chains/retrieval_qa.cjs +1 -1
  3. package/dist/chains/retrieval_qa.js +1 -1
  4. package/dist/document_loaders/web/recursive_url.cjs +1 -1
  5. package/dist/document_loaders/web/recursive_url.js +1 -1
  6. package/dist/llms/llama_cpp.cjs +132 -0
  7. package/dist/llms/llama_cpp.d.ts +73 -0
  8. package/dist/llms/llama_cpp.js +128 -0
  9. package/dist/load/import_constants.cjs +1 -0
  10. package/dist/load/import_constants.js +1 -0
  11. package/dist/load/import_map.cjs +3 -2
  12. package/dist/load/import_map.d.ts +1 -0
  13. package/dist/load/import_map.js +1 -0
  14. package/dist/output_parsers/prompts.d.ts +1 -1
  15. package/dist/prompts/prompt.cjs +3 -1
  16. package/dist/prompts/prompt.d.ts +12 -1
  17. package/dist/prompts/prompt.js +3 -1
  18. package/dist/retrievers/multi_vector.cjs +72 -0
  19. package/dist/retrievers/multi_vector.d.ts +30 -0
  20. package/dist/retrievers/multi_vector.js +68 -0
  21. package/dist/retrievers/parent_document.cjs +9 -1
  22. package/dist/retrievers/parent_document.d.ts +2 -0
  23. package/dist/retrievers/parent_document.js +9 -1
  24. package/dist/schema/retriever.cjs +1 -4
  25. package/dist/schema/retriever.d.ts +2 -5
  26. package/dist/schema/retriever.js +1 -4
  27. package/dist/tools/index.cjs +3 -1
  28. package/dist/tools/index.d.ts +1 -0
  29. package/dist/tools/index.js +1 -0
  30. package/dist/tools/wolframalpha.cjs +40 -0
  31. package/dist/tools/wolframalpha.d.ts +12 -0
  32. package/dist/tools/wolframalpha.js +36 -0
  33. package/dist/vectorstores/chroma.cjs +8 -0
  34. package/dist/vectorstores/chroma.d.ts +4 -1
  35. package/dist/vectorstores/chroma.js +8 -0
  36. package/dist/vectorstores/redis.cjs +9 -1
  37. package/dist/vectorstores/redis.js +9 -1
  38. package/dist/vectorstores/vectara.cjs +1 -1
  39. package/dist/vectorstores/vectara.js +1 -1
  40. package/llms/llama_cpp.cjs +1 -0
  41. package/llms/llama_cpp.d.ts +1 -0
  42. package/llms/llama_cpp.js +1 -0
  43. package/package.json +22 -1
  44. package/retrievers/multi_vector.cjs +1 -0
  45. package/retrievers/multi_vector.d.ts +1 -0
  46. package/retrievers/multi_vector.js +1 -0
@@ -1,6 +1,6 @@
1
1
  import { PromptTemplate } from "../../prompts/prompt.js";
2
2
  import { ConditionalPromptSelector } from "../../prompts/selectors/conditional.js";
3
- export declare const DEFAULT_COMBINE_QA_PROMPT: PromptTemplate<any, any>;
3
+ export declare const DEFAULT_COMBINE_QA_PROMPT: PromptTemplate<import("../../prompts/prompt.js").ParamsFromFString<"Use the following portion of a long document to see if any of the text is relevant to answer the question. \nReturn any relevant text verbatim.\n{context}\nQuestion: {question}\nRelevant text, if any:">, any>;
4
4
  export declare const COMBINE_QA_PROMPT_SELECTOR: ConditionalPromptSelector;
5
- export declare const COMBINE_PROMPT: PromptTemplate<any, any>;
5
+ export declare const COMBINE_PROMPT: PromptTemplate<import("../../prompts/prompt.js").ParamsFromFString<"Given the following extracted parts of a long document and a question, create a final answer. \nIf you don't know the answer, just say that you don't know. Don't try to make up an answer.\n\nQUESTION: Which state/country's law governs the interpretation of the contract?\n=========\nContent: This Agreement is governed by English law and the parties submit to the exclusive jurisdiction of the English courts in relation to any dispute (contractual or non-contractual) concerning this Agreement save that either party may apply to any court for an injunction or other relief to protect its Intellectual Property Rights.\n\nContent: No Waiver. Failure or delay in exercising any right or remedy under this Agreement shall not constitute a waiver of such (or any other) right or remedy.\n\n11.7 Severability. The invalidity, illegality or unenforceability of any term (or part of a term) of this Agreement shall not affect the continuation in force of the remainder of the term (if any) and this Agreement.\n\n11.8 No Agency. Except as expressly stated otherwise, nothing in this Agreement shall create an agency, partnership or joint venture of any kind between the parties.\n\n11.9 No Third-Party Beneficiaries.\n\nContent: (b) if Google believes, in good faith, that the Distributor has violated or caused Google to violate any Anti-Bribery Laws (as defined in Clause 8.5) or that such a violation is reasonably likely to occur,\n=========\nFINAL ANSWER: This Agreement is governed by English law.\n\nQUESTION: What did the president say about Michael Jackson?\n=========\nContent: Madam Speaker, Madam Vice President, our First Lady and Second Gentleman. Members of Congress and the Cabinet. Justices of the Supreme Court. My fellow Americans. \n\nLast year COVID-19 kept us apart. This year we are finally together again. \n\nTonight, we meet as Democrats Republicans and Independents. But most importantly as Americans. \n\nWith a duty to one another to the American people to the Constitution. \n\nAnd with an unwavering resolve that freedom will always triumph over tyranny. \n\nSix days ago, Russia’s Vladimir Putin sought to shake the foundations of the free world thinking he could make it bend to his menacing ways. But he badly miscalculated. \n\nHe thought he could roll into Ukraine and the world would roll over. Instead he met a wall of strength he never imagined. \n\nHe met the Ukrainian people. \n\nFrom President Zelenskyy to every Ukrainian, their fearlessness, their courage, their determination, inspires the world. \n\nGroups of citizens blocking tanks with their bodies. Everyone from students to retirees teachers turned soldiers defending their homeland.\n\nContent: And we won’t stop. \n\nWe have lost so much to COVID-19. Time with one another. And worst of all, so much loss of life. \n\nLet’s use this moment to reset. Let’s stop looking at COVID-19 as a partisan dividing line and see it for what it is: A God-awful disease. \n\nLet’s stop seeing each other as enemies, and start seeing each other for who we really are: Fellow Americans. \n\nWe can’t change how divided we’ve been. But we can change how we move forward—on COVID-19 and other issues we must face together. \n\nI recently visited the New York City Police Department days after the funerals of Officer Wilbert Mora and his partner, Officer Jason Rivera. \n\nThey were responding to a 9-1-1 call when a man shot and killed them with a stolen gun. \n\nOfficer Mora was 27 years old. \n\nOfficer Rivera was 22. \n\nBoth Dominican Americans who’d grown up on the same streets they later chose to patrol as police officers. \n\nI spoke with their families and told them that we are forever in debt for their sacrifice, and we will carry on their mission to restore the trust and safety every community deserves.\n\nContent: And a proud Ukrainian people, who have known 30 years of independence, have repeatedly shown that they will not tolerate anyone who tries to take their country backwards. \n\nTo all Americans, I will be honest with you, as I’ve always promised. A Russian dictator, invading a foreign country, has costs around the world. \n\nAnd I’m taking robust action to make sure the pain of our sanctions is targeted at Russia’s economy. And I will use every tool at our disposal to protect American businesses and consumers. \n\nTonight, I can announce that the United States has worked with 30 other countries to release 60 Million barrels of oil from reserves around the world. \n\nAmerica will lead that effort, releasing 30 Million barrels from our own Strategic Petroleum Reserve. And we stand ready to do more if necessary, unified with our allies. \n\nThese steps will help blunt gas prices here at home. And I know the news about what’s happening can seem alarming. \n\nBut I want you to know that we are going to be okay.\n\nContent: More support for patients and families. \n\nTo get there, I call on Congress to fund ARPA-H, the Advanced Research Projects Agency for Health. \n\nIt’s based on DARPA—the Defense Department project that led to the Internet, GPS, and so much more. \n\nARPA-H will have a singular purpose—to drive breakthroughs in cancer, Alzheimer’s, diabetes, and more. \n\nA unity agenda for the nation. \n\nWe can do this. \n\nMy fellow Americans—tonight , we have gathered in a sacred space—the citadel of our democracy. \n\nIn this Capitol, generation after generation, Americans have debated great questions amid great strife, and have done great things. \n\nWe have fought for freedom, expanded liberty, defeated totalitarianism and terror. \n\nAnd built the strongest, freest, and most prosperous nation the world has ever known. \n\nNow is the hour. \n\nOur moment of responsibility. \n\nOur test of resolve and conscience, of history itself. \n\nIt is in this moment that our character is formed. Our purpose is found. Our future is forged. \n\nWell I know this nation.\n=========\nFINAL ANSWER: The president did not mention Michael Jackson.\n\nQUESTION: {question}\n=========\n{summaries}\n=========\nFINAL ANSWER:">, any>;
6
6
  export declare const COMBINE_PROMPT_SELECTOR: ConditionalPromptSelector;
@@ -56,7 +56,7 @@ class RetrievalQAChain extends base_js_1.BaseChain {
56
56
  }
57
57
  const question = values[this.inputKey];
58
58
  const docs = await this.retriever.getRelevantDocuments(question, runManager?.getChild("retriever"));
59
- const inputs = { question, input_documents: docs };
59
+ const inputs = { question, input_documents: docs, ...values };
60
60
  const result = await this.combineDocumentsChain.call(inputs, runManager?.getChild("combine_documents"));
61
61
  if (this.returnSourceDocuments) {
62
62
  return {
@@ -53,7 +53,7 @@ export class RetrievalQAChain extends BaseChain {
53
53
  }
54
54
  const question = values[this.inputKey];
55
55
  const docs = await this.retriever.getRelevantDocuments(question, runManager?.getChild("retriever"));
56
- const inputs = { question, input_documents: docs };
56
+ const inputs = { question, input_documents: docs, ...values };
57
57
  const result = await this.combineDocumentsChain.call(inputs, runManager?.getChild("combine_documents"));
58
58
  if (this.returnSourceDocuments) {
59
59
  return {
@@ -133,7 +133,7 @@ class RecursiveUrlLoader extends base_js_1.BaseDocumentLoader {
133
133
  };
134
134
  }
135
135
  async getChildUrlsRecursive(inputUrl, visited = new Set(), depth = 0) {
136
- if (depth > this.maxDepth)
136
+ if (depth >= this.maxDepth)
137
137
  return [];
138
138
  let url = inputUrl;
139
139
  if (!inputUrl.endsWith("/"))
@@ -130,7 +130,7 @@ export class RecursiveUrlLoader extends BaseDocumentLoader {
130
130
  };
131
131
  }
132
132
  async getChildUrlsRecursive(inputUrl, visited = new Set(), depth = 0) {
133
- if (depth > this.maxDepth)
133
+ if (depth >= this.maxDepth)
134
134
  return [];
135
135
  let url = inputUrl;
136
136
  if (!inputUrl.endsWith("/"))
@@ -0,0 +1,132 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LlamaCpp = void 0;
4
+ const node_llama_cpp_1 = require("node-llama-cpp");
5
+ const base_js_1 = require("./base.cjs");
6
+ /**
7
+ * To use this model you need to have the `node-llama-cpp` module installed.
8
+ * This can be installed using `npm install -S node-llama-cpp` and the minimum
9
+ * version supported in version 2.0.0.
10
+ * This also requires that have a locally built version of Llama2 installed.
11
+ */
12
+ class LlamaCpp extends base_js_1.LLM {
13
+ static lc_name() {
14
+ return "LlamaCpp";
15
+ }
16
+ constructor(inputs) {
17
+ super(inputs);
18
+ Object.defineProperty(this, "batchSize", {
19
+ enumerable: true,
20
+ configurable: true,
21
+ writable: true,
22
+ value: void 0
23
+ });
24
+ Object.defineProperty(this, "contextSize", {
25
+ enumerable: true,
26
+ configurable: true,
27
+ writable: true,
28
+ value: void 0
29
+ });
30
+ Object.defineProperty(this, "embedding", {
31
+ enumerable: true,
32
+ configurable: true,
33
+ writable: true,
34
+ value: void 0
35
+ });
36
+ Object.defineProperty(this, "f16Kv", {
37
+ enumerable: true,
38
+ configurable: true,
39
+ writable: true,
40
+ value: void 0
41
+ });
42
+ Object.defineProperty(this, "gpuLayers", {
43
+ enumerable: true,
44
+ configurable: true,
45
+ writable: true,
46
+ value: void 0
47
+ });
48
+ Object.defineProperty(this, "logitsAll", {
49
+ enumerable: true,
50
+ configurable: true,
51
+ writable: true,
52
+ value: void 0
53
+ });
54
+ Object.defineProperty(this, "lowVram", {
55
+ enumerable: true,
56
+ configurable: true,
57
+ writable: true,
58
+ value: void 0
59
+ });
60
+ Object.defineProperty(this, "seed", {
61
+ enumerable: true,
62
+ configurable: true,
63
+ writable: true,
64
+ value: void 0
65
+ });
66
+ Object.defineProperty(this, "useMlock", {
67
+ enumerable: true,
68
+ configurable: true,
69
+ writable: true,
70
+ value: void 0
71
+ });
72
+ Object.defineProperty(this, "useMmap", {
73
+ enumerable: true,
74
+ configurable: true,
75
+ writable: true,
76
+ value: void 0
77
+ });
78
+ Object.defineProperty(this, "vocabOnly", {
79
+ enumerable: true,
80
+ configurable: true,
81
+ writable: true,
82
+ value: void 0
83
+ });
84
+ Object.defineProperty(this, "modelPath", {
85
+ enumerable: true,
86
+ configurable: true,
87
+ writable: true,
88
+ value: void 0
89
+ });
90
+ Object.defineProperty(this, "_model", {
91
+ enumerable: true,
92
+ configurable: true,
93
+ writable: true,
94
+ value: void 0
95
+ });
96
+ Object.defineProperty(this, "_context", {
97
+ enumerable: true,
98
+ configurable: true,
99
+ writable: true,
100
+ value: void 0
101
+ });
102
+ this.batchSize = inputs.batchSize;
103
+ this.contextSize = inputs.contextSize;
104
+ this.embedding = inputs.embedding;
105
+ this.f16Kv = inputs.f16Kv;
106
+ this.gpuLayers = inputs.gpuLayers;
107
+ this.logitsAll = inputs.logitsAll;
108
+ this.lowVram = inputs.lowVram;
109
+ this.modelPath = inputs.modelPath;
110
+ this.seed = inputs.seed;
111
+ this.useMlock = inputs.useMlock;
112
+ this.useMmap = inputs.useMmap;
113
+ this.vocabOnly = inputs.vocabOnly;
114
+ this._model = new node_llama_cpp_1.LlamaModel(inputs);
115
+ this._context = new node_llama_cpp_1.LlamaContext({ model: this._model });
116
+ }
117
+ _llmType() {
118
+ return "llama2_cpp";
119
+ }
120
+ /** @ignore */
121
+ async _call(prompt, options) {
122
+ const session = new node_llama_cpp_1.LlamaChatSession({ context: this._context });
123
+ try {
124
+ const compleation = await session.prompt(prompt, options);
125
+ return compleation;
126
+ }
127
+ catch (e) {
128
+ throw new Error("Error getting prompt compleation.");
129
+ }
130
+ }
131
+ }
132
+ exports.LlamaCpp = LlamaCpp;
@@ -0,0 +1,73 @@
1
+ import { LlamaModel, LlamaContext } from "node-llama-cpp";
2
+ import { LLM, BaseLLMCallOptions, BaseLLMParams } from "./base.js";
3
+ /**
4
+ * Note that the modelPath is the only required parameter. For testing you
5
+ * can set this in the environment variable `LLAMA_PATH`.
6
+ */
7
+ export interface LlamaCppInputs extends BaseLLMParams {
8
+ /** Prompt processing batch size. */
9
+ batchSize?: number;
10
+ /** Text context size. */
11
+ contextSize?: number;
12
+ /** Embedding mode only. */
13
+ embedding?: boolean;
14
+ /** Use fp16 for KV cache. */
15
+ f16Kv?: boolean;
16
+ /** Number of layers to store in VRAM. */
17
+ gpuLayers?: number;
18
+ /** The llama_eval() call computes all logits, not just the last one. */
19
+ logitsAll?: boolean;
20
+ /** If true, reduce VRAM usage at the cost of performance. */
21
+ lowVram?: boolean;
22
+ /** Path to the model on the filesystem. */
23
+ modelPath: string;
24
+ /** If null, a random seed will be used. */
25
+ seed?: null | number;
26
+ /** The randomness of the responses, e.g. 0.1 deterministic, 1.5 creative, 0.8 balanced, 0 disables. */
27
+ temperature?: number;
28
+ /** Consider the n most likely tokens, where n is 1 to vocabulary size, 0 disables (uses full vocabulary). Note: only applies when `temperature` > 0. */
29
+ topK?: number;
30
+ /** Selects the smallest token set whose probability exceeds P, where P is between 0 - 1, 1 disables. Note: only applies when `temperature` > 0. */
31
+ topP?: number;
32
+ /** Force system to keep model in RAM. */
33
+ useMlock?: boolean;
34
+ /** Use mmap if possible. */
35
+ useMmap?: boolean;
36
+ /** Only load the vocabulary, no weights. */
37
+ vocabOnly?: boolean;
38
+ }
39
+ export interface LlamaCppCallOptions extends BaseLLMCallOptions {
40
+ /** The maximum number of tokens the response should contain. */
41
+ maxTokens?: number;
42
+ /** A function called when matching the provided token array */
43
+ onToken?: (tokens: number[]) => void;
44
+ }
45
+ /**
46
+ * To use this model you need to have the `node-llama-cpp` module installed.
47
+ * This can be installed using `npm install -S node-llama-cpp` and the minimum
48
+ * version supported in version 2.0.0.
49
+ * This also requires that have a locally built version of Llama2 installed.
50
+ */
51
+ export declare class LlamaCpp extends LLM<LlamaCppCallOptions> {
52
+ CallOptions: LlamaCppCallOptions;
53
+ static inputs: LlamaCppInputs;
54
+ batchSize?: number;
55
+ contextSize?: number;
56
+ embedding?: boolean;
57
+ f16Kv?: boolean;
58
+ gpuLayers?: number;
59
+ logitsAll?: boolean;
60
+ lowVram?: boolean;
61
+ seed?: null | number;
62
+ useMlock?: boolean;
63
+ useMmap?: boolean;
64
+ vocabOnly?: boolean;
65
+ modelPath: string;
66
+ _model: LlamaModel;
67
+ _context: LlamaContext;
68
+ static lc_name(): string;
69
+ constructor(inputs: LlamaCppInputs);
70
+ _llmType(): string;
71
+ /** @ignore */
72
+ _call(prompt: string, options?: this["ParsedCallOptions"]): Promise<string>;
73
+ }
@@ -0,0 +1,128 @@
1
+ import { LlamaModel, LlamaContext, LlamaChatSession } from "node-llama-cpp";
2
+ import { LLM } from "./base.js";
3
+ /**
4
+ * To use this model you need to have the `node-llama-cpp` module installed.
5
+ * This can be installed using `npm install -S node-llama-cpp` and the minimum
6
+ * version supported in version 2.0.0.
7
+ * This also requires that have a locally built version of Llama2 installed.
8
+ */
9
+ export class LlamaCpp extends LLM {
10
+ static lc_name() {
11
+ return "LlamaCpp";
12
+ }
13
+ constructor(inputs) {
14
+ super(inputs);
15
+ Object.defineProperty(this, "batchSize", {
16
+ enumerable: true,
17
+ configurable: true,
18
+ writable: true,
19
+ value: void 0
20
+ });
21
+ Object.defineProperty(this, "contextSize", {
22
+ enumerable: true,
23
+ configurable: true,
24
+ writable: true,
25
+ value: void 0
26
+ });
27
+ Object.defineProperty(this, "embedding", {
28
+ enumerable: true,
29
+ configurable: true,
30
+ writable: true,
31
+ value: void 0
32
+ });
33
+ Object.defineProperty(this, "f16Kv", {
34
+ enumerable: true,
35
+ configurable: true,
36
+ writable: true,
37
+ value: void 0
38
+ });
39
+ Object.defineProperty(this, "gpuLayers", {
40
+ enumerable: true,
41
+ configurable: true,
42
+ writable: true,
43
+ value: void 0
44
+ });
45
+ Object.defineProperty(this, "logitsAll", {
46
+ enumerable: true,
47
+ configurable: true,
48
+ writable: true,
49
+ value: void 0
50
+ });
51
+ Object.defineProperty(this, "lowVram", {
52
+ enumerable: true,
53
+ configurable: true,
54
+ writable: true,
55
+ value: void 0
56
+ });
57
+ Object.defineProperty(this, "seed", {
58
+ enumerable: true,
59
+ configurable: true,
60
+ writable: true,
61
+ value: void 0
62
+ });
63
+ Object.defineProperty(this, "useMlock", {
64
+ enumerable: true,
65
+ configurable: true,
66
+ writable: true,
67
+ value: void 0
68
+ });
69
+ Object.defineProperty(this, "useMmap", {
70
+ enumerable: true,
71
+ configurable: true,
72
+ writable: true,
73
+ value: void 0
74
+ });
75
+ Object.defineProperty(this, "vocabOnly", {
76
+ enumerable: true,
77
+ configurable: true,
78
+ writable: true,
79
+ value: void 0
80
+ });
81
+ Object.defineProperty(this, "modelPath", {
82
+ enumerable: true,
83
+ configurable: true,
84
+ writable: true,
85
+ value: void 0
86
+ });
87
+ Object.defineProperty(this, "_model", {
88
+ enumerable: true,
89
+ configurable: true,
90
+ writable: true,
91
+ value: void 0
92
+ });
93
+ Object.defineProperty(this, "_context", {
94
+ enumerable: true,
95
+ configurable: true,
96
+ writable: true,
97
+ value: void 0
98
+ });
99
+ this.batchSize = inputs.batchSize;
100
+ this.contextSize = inputs.contextSize;
101
+ this.embedding = inputs.embedding;
102
+ this.f16Kv = inputs.f16Kv;
103
+ this.gpuLayers = inputs.gpuLayers;
104
+ this.logitsAll = inputs.logitsAll;
105
+ this.lowVram = inputs.lowVram;
106
+ this.modelPath = inputs.modelPath;
107
+ this.seed = inputs.seed;
108
+ this.useMlock = inputs.useMlock;
109
+ this.useMmap = inputs.useMmap;
110
+ this.vocabOnly = inputs.vocabOnly;
111
+ this._model = new LlamaModel(inputs);
112
+ this._context = new LlamaContext({ model: this._model });
113
+ }
114
+ _llmType() {
115
+ return "llama2_cpp";
116
+ }
117
+ /** @ignore */
118
+ async _call(prompt, options) {
119
+ const session = new LlamaChatSession({ context: this._context });
120
+ try {
121
+ const compleation = await session.prompt(prompt, options);
122
+ return compleation;
123
+ }
124
+ catch (e) {
125
+ throw new Error("Error getting prompt compleation.");
126
+ }
127
+ }
128
+ }
@@ -29,6 +29,7 @@ exports.optionalImportEntrypoints = [
29
29
  "langchain/llms/googlepalm",
30
30
  "langchain/llms/sagemaker_endpoint",
31
31
  "langchain/llms/bedrock",
32
+ "langchain/llms/llama_cpp",
32
33
  "langchain/llms/writer",
33
34
  "langchain/prompts/load",
34
35
  "langchain/vectorstores/analyticdb",
@@ -26,6 +26,7 @@ export const optionalImportEntrypoints = [
26
26
  "langchain/llms/googlepalm",
27
27
  "langchain/llms/sagemaker_endpoint",
28
28
  "langchain/llms/bedrock",
29
+ "langchain/llms/llama_cpp",
29
30
  "langchain/llms/writer",
30
31
  "langchain/prompts/load",
31
32
  "langchain/vectorstores/analyticdb",
@@ -24,8 +24,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
24
24
  return result;
25
25
  };
26
26
  Object.defineProperty(exports, "__esModule", { value: true });
27
- exports.retrievers__hyde = exports.retrievers__document_compressors__chain_extract = exports.retrievers__time_weighted = exports.retrievers__parent_document = exports.retrievers__document_compressors = exports.retrievers__contextual_compression = exports.retrievers__databerry = 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 = exports.chat_models__ollama = exports.chat_models__baiduwenxin = 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__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__ollama = exports.llms__aleph_alpha = exports.llms__ai21 = exports.llms__openai = exports.llms__base = exports.embeddings__openai = 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__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 = void 0;
27
+ exports.retrievers__document_compressors__chain_extract = exports.retrievers__time_weighted = exports.retrievers__parent_document = exports.retrievers__multi_vector = exports.retrievers__document_compressors = exports.retrievers__contextual_compression = exports.retrievers__databerry = 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 = exports.chat_models__ollama = exports.chat_models__baiduwenxin = 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__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__ollama = exports.llms__aleph_alpha = exports.llms__ai21 = exports.llms__openai = exports.llms__base = exports.embeddings__openai = 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__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 = 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"));
@@ -72,6 +72,7 @@ exports.retrievers__remote = __importStar(require("../retrievers/remote/index.cj
72
72
  exports.retrievers__databerry = __importStar(require("../retrievers/databerry.cjs"));
73
73
  exports.retrievers__contextual_compression = __importStar(require("../retrievers/contextual_compression.cjs"));
74
74
  exports.retrievers__document_compressors = __importStar(require("../retrievers/document_compressors/index.cjs"));
75
+ exports.retrievers__multi_vector = __importStar(require("../retrievers/multi_vector.cjs"));
75
76
  exports.retrievers__parent_document = __importStar(require("../retrievers/parent_document.cjs"));
76
77
  exports.retrievers__time_weighted = __importStar(require("../retrievers/time_weighted.cjs"));
77
78
  exports.retrievers__document_compressors__chain_extract = __importStar(require("../retrievers/document_compressors/chain_extract.cjs"));
@@ -44,6 +44,7 @@ export * as retrievers__remote from "../retrievers/remote/index.js";
44
44
  export * as retrievers__databerry from "../retrievers/databerry.js";
45
45
  export * as retrievers__contextual_compression from "../retrievers/contextual_compression.js";
46
46
  export * as retrievers__document_compressors from "../retrievers/document_compressors/index.js";
47
+ export * as retrievers__multi_vector from "../retrievers/multi_vector.js";
47
48
  export * as retrievers__parent_document from "../retrievers/parent_document.js";
48
49
  export * as retrievers__time_weighted from "../retrievers/time_weighted.js";
49
50
  export * as retrievers__document_compressors__chain_extract from "../retrievers/document_compressors/chain_extract.js";
@@ -45,6 +45,7 @@ export * as retrievers__remote from "../retrievers/remote/index.js";
45
45
  export * as retrievers__databerry from "../retrievers/databerry.js";
46
46
  export * as retrievers__contextual_compression from "../retrievers/contextual_compression.js";
47
47
  export * as retrievers__document_compressors from "../retrievers/document_compressors/index.js";
48
+ export * as retrievers__multi_vector from "../retrievers/multi_vector.js";
48
49
  export * as retrievers__parent_document from "../retrievers/parent_document.js";
49
50
  export * as retrievers__time_weighted from "../retrievers/time_weighted.js";
50
51
  export * as retrievers__document_compressors__chain_extract from "../retrievers/document_compressors/chain_extract.js";
@@ -1,3 +1,3 @@
1
1
  import { PromptTemplate } from "../prompts/prompt.js";
2
2
  export declare const NAIVE_FIX_TEMPLATE = "Instructions:\n--------------\n{instructions}\n--------------\nCompletion:\n--------------\n{completion}\n--------------\n\nAbove, the Completion did not satisfy the constraints given in the Instructions.\nError:\n--------------\n{error}\n--------------\n\nPlease try again. Please only respond with an answer that satisfies the constraints laid out in the Instructions:";
3
- export declare const NAIVE_FIX_PROMPT: PromptTemplate<any, any>;
3
+ export declare const NAIVE_FIX_PROMPT: PromptTemplate<import("../prompts/prompt.js").ParamsFromFString<"Instructions:\n--------------\n{instructions}\n--------------\nCompletion:\n--------------\n{completion}\n--------------\n\nAbove, the Completion did not satisfy the constraints given in the Instructions.\nError:\n--------------\n{error}\n--------------\n\nPlease try again. Please only respond with an answer that satisfies the constraints laid out in the Instructions:">, any>;
@@ -88,8 +88,10 @@ class PromptTemplate extends base_js_1.BaseStringPromptTemplate {
88
88
  /**
89
89
  * Load prompt template from a template f-string
90
90
  */
91
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
92
91
  static fromTemplate(template, { templateFormat = "f-string", ...rest } = {}) {
92
+ if (templateFormat === "jinja2") {
93
+ throw new Error("jinja2 templates are not currently supported.");
94
+ }
93
95
  const names = new Set();
94
96
  (0, template_js_1.parseTemplate)(template, templateFormat).forEach((node) => {
95
97
  if (node.type === "variable") {
@@ -24,6 +24,16 @@ export interface PromptTemplateInput<RunInput extends InputValues = any, Partial
24
24
  */
25
25
  validateTemplate?: boolean;
26
26
  }
27
+ type NonAlphanumeric = " " | "\t" | "\n" | "\r" | '"' | "'" | "{" | "[" | "(" | "`" | ":" | ";";
28
+ /**
29
+ * Recursive type to extract template parameters from a string.
30
+ * @template T - The input string.
31
+ * @template Result - The resulting array of extracted template parameters.
32
+ */
33
+ type ExtractTemplateParamsRecursive<T extends string, Result extends string[] = []> = T extends `${string}{${infer Param}}${infer Rest}` ? Param extends `${NonAlphanumeric}${string}` ? ExtractTemplateParamsRecursive<Rest, Result> : ExtractTemplateParamsRecursive<Rest, [...Result, Param]> : Result;
34
+ export type ParamsFromFString<T extends string> = {
35
+ [Key in ExtractTemplateParamsRecursive<T>[number]]: string;
36
+ };
27
37
  /**
28
38
  * Schema to represent a basic prompt for an LLM.
29
39
  * @augments BasePromptTemplate
@@ -69,7 +79,7 @@ export declare class PromptTemplate<RunInput extends InputValues = any, PartialV
69
79
  /**
70
80
  * Load prompt template from a template f-string
71
81
  */
72
- static fromTemplate<RunInput extends InputValues = any>(template: string, { templateFormat, ...rest }?: Omit<PromptTemplateInput, "template" | "inputVariables">): PromptTemplate<RunInput, any>;
82
+ static fromTemplate<RunInput extends InputValues = Symbol, T extends string = string>(template: T, { templateFormat, ...rest }?: Omit<PromptTemplateInput<RunInput, string>, "template" | "inputVariables">): PromptTemplate<RunInput extends Symbol ? ParamsFromFString<T> : RunInput, any>;
73
83
  /**
74
84
  * Partially applies values to the prompt template.
75
85
  * @param values The values to be partially applied to the prompt template.
@@ -79,3 +89,4 @@ export declare class PromptTemplate<RunInput extends InputValues = any, PartialV
79
89
  serialize(): SerializedPromptTemplate;
80
90
  static deserialize(data: SerializedPromptTemplate): Promise<PromptTemplate>;
81
91
  }
92
+ export {};
@@ -85,8 +85,10 @@ export class PromptTemplate extends BaseStringPromptTemplate {
85
85
  /**
86
86
  * Load prompt template from a template f-string
87
87
  */
88
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
89
88
  static fromTemplate(template, { templateFormat = "f-string", ...rest } = {}) {
89
+ if (templateFormat === "jinja2") {
90
+ throw new Error("jinja2 templates are not currently supported.");
91
+ }
90
92
  const names = new Set();
91
93
  parseTemplate(template, templateFormat).forEach((node) => {
92
94
  if (node.type === "variable") {
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MultiVectorRetriever = void 0;
4
+ const retriever_js_1 = require("../schema/retriever.cjs");
5
+ /**
6
+ * A retriever that retrieves documents from a vector store and a document
7
+ * store. It uses the vector store to find relevant documents based on a
8
+ * query, and then retrieves the full documents from the document store.
9
+ */
10
+ class MultiVectorRetriever extends retriever_js_1.BaseRetriever {
11
+ static lc_name() {
12
+ return "MultiVectorRetriever";
13
+ }
14
+ constructor(args) {
15
+ super(args);
16
+ Object.defineProperty(this, "lc_namespace", {
17
+ enumerable: true,
18
+ configurable: true,
19
+ writable: true,
20
+ value: ["langchain", "retrievers", "multi_vector"]
21
+ });
22
+ Object.defineProperty(this, "vectorstore", {
23
+ enumerable: true,
24
+ configurable: true,
25
+ writable: true,
26
+ value: void 0
27
+ });
28
+ Object.defineProperty(this, "docstore", {
29
+ enumerable: true,
30
+ configurable: true,
31
+ writable: true,
32
+ value: void 0
33
+ });
34
+ Object.defineProperty(this, "idKey", {
35
+ enumerable: true,
36
+ configurable: true,
37
+ writable: true,
38
+ value: void 0
39
+ });
40
+ Object.defineProperty(this, "childK", {
41
+ enumerable: true,
42
+ configurable: true,
43
+ writable: true,
44
+ value: void 0
45
+ });
46
+ Object.defineProperty(this, "parentK", {
47
+ enumerable: true,
48
+ configurable: true,
49
+ writable: true,
50
+ value: void 0
51
+ });
52
+ this.vectorstore = args.vectorstore;
53
+ this.docstore = args.docstore;
54
+ this.idKey = args.idKey ?? "doc_id";
55
+ this.childK = args.childK;
56
+ this.parentK = args.parentK;
57
+ }
58
+ async _getRelevantDocuments(query) {
59
+ const subDocs = await this.vectorstore.similaritySearch(query, this.childK);
60
+ const ids = [];
61
+ for (const doc of subDocs) {
62
+ if (doc.metadata[this.idKey] && !ids.includes(doc.metadata[this.idKey])) {
63
+ ids.push(doc.metadata[this.idKey]);
64
+ }
65
+ }
66
+ const docs = await this.docstore.mget(ids);
67
+ return docs
68
+ .filter((doc) => doc !== undefined)
69
+ .slice(0, this.parentK);
70
+ }
71
+ }
72
+ exports.MultiVectorRetriever = MultiVectorRetriever;
@@ -0,0 +1,30 @@
1
+ import { BaseStore } from "../schema/storage.js";
2
+ import { Document } from "../document.js";
3
+ import { BaseRetriever, BaseRetrieverInput } from "../schema/retriever.js";
4
+ import { VectorStore } from "../vectorstores/base.js";
5
+ /**
6
+ * Arguments for the MultiVectorRetriever class.
7
+ */
8
+ export interface MultiVectorRetrieverInput extends BaseRetrieverInput {
9
+ vectorstore: VectorStore;
10
+ docstore: BaseStore<string, Document>;
11
+ idKey?: string;
12
+ childK?: number;
13
+ parentK?: number;
14
+ }
15
+ /**
16
+ * A retriever that retrieves documents from a vector store and a document
17
+ * store. It uses the vector store to find relevant documents based on a
18
+ * query, and then retrieves the full documents from the document store.
19
+ */
20
+ export declare class MultiVectorRetriever extends BaseRetriever {
21
+ static lc_name(): string;
22
+ lc_namespace: string[];
23
+ vectorstore: VectorStore;
24
+ docstore: BaseStore<string, Document>;
25
+ protected idKey: string;
26
+ protected childK?: number;
27
+ protected parentK?: number;
28
+ constructor(args: MultiVectorRetrieverInput);
29
+ _getRelevantDocuments(query: string): Promise<Document[]>;
30
+ }
@@ -0,0 +1,68 @@
1
+ import { BaseRetriever } from "../schema/retriever.js";
2
+ /**
3
+ * A retriever that retrieves documents from a vector store and a document
4
+ * store. It uses the vector store to find relevant documents based on a
5
+ * query, and then retrieves the full documents from the document store.
6
+ */
7
+ export class MultiVectorRetriever extends BaseRetriever {
8
+ static lc_name() {
9
+ return "MultiVectorRetriever";
10
+ }
11
+ constructor(args) {
12
+ super(args);
13
+ Object.defineProperty(this, "lc_namespace", {
14
+ enumerable: true,
15
+ configurable: true,
16
+ writable: true,
17
+ value: ["langchain", "retrievers", "multi_vector"]
18
+ });
19
+ Object.defineProperty(this, "vectorstore", {
20
+ enumerable: true,
21
+ configurable: true,
22
+ writable: true,
23
+ value: void 0
24
+ });
25
+ Object.defineProperty(this, "docstore", {
26
+ enumerable: true,
27
+ configurable: true,
28
+ writable: true,
29
+ value: void 0
30
+ });
31
+ Object.defineProperty(this, "idKey", {
32
+ enumerable: true,
33
+ configurable: true,
34
+ writable: true,
35
+ value: void 0
36
+ });
37
+ Object.defineProperty(this, "childK", {
38
+ enumerable: true,
39
+ configurable: true,
40
+ writable: true,
41
+ value: void 0
42
+ });
43
+ Object.defineProperty(this, "parentK", {
44
+ enumerable: true,
45
+ configurable: true,
46
+ writable: true,
47
+ value: void 0
48
+ });
49
+ this.vectorstore = args.vectorstore;
50
+ this.docstore = args.docstore;
51
+ this.idKey = args.idKey ?? "doc_id";
52
+ this.childK = args.childK;
53
+ this.parentK = args.parentK;
54
+ }
55
+ async _getRelevantDocuments(query) {
56
+ const subDocs = await this.vectorstore.similaritySearch(query, this.childK);
57
+ const ids = [];
58
+ for (const doc of subDocs) {
59
+ if (doc.metadata[this.idKey] && !ids.includes(doc.metadata[this.idKey])) {
60
+ ids.push(doc.metadata[this.idKey]);
61
+ }
62
+ }
63
+ const docs = await this.docstore.mget(ids);
64
+ return docs
65
+ .filter((doc) => doc !== undefined)
66
+ .slice(0, this.parentK);
67
+ }
68
+ }
@@ -27,6 +27,7 @@ exports.ParentDocumentRetriever = void 0;
27
27
  const uuid = __importStar(require("uuid"));
28
28
  const retriever_js_1 = require("../schema/retriever.cjs");
29
29
  const document_js_1 = require("../document.cjs");
30
+ // TODO: Change this to subclass MultiVectorRetriever
30
31
  /**
31
32
  * A type of document retriever that splits input documents into smaller chunks
32
33
  * while separately storing and preserving the original documents.
@@ -84,12 +85,19 @@ class ParentDocumentRetriever extends retriever_js_1.BaseRetriever {
84
85
  writable: true,
85
86
  value: void 0
86
87
  });
88
+ Object.defineProperty(this, "parentK", {
89
+ enumerable: true,
90
+ configurable: true,
91
+ writable: true,
92
+ value: void 0
93
+ });
87
94
  this.vectorstore = fields.vectorstore;
88
95
  this.docstore = fields.docstore;
89
96
  this.childSplitter = fields.childSplitter;
90
97
  this.parentSplitter = fields.parentSplitter;
91
98
  this.idKey = fields.idKey ?? this.idKey;
92
99
  this.childK = fields.childK;
100
+ this.parentK = fields.parentK;
93
101
  }
94
102
  async _getRelevantDocuments(query) {
95
103
  const subDocs = await this.vectorstore.similaritySearch(query, this.childK);
@@ -107,7 +115,7 @@ class ParentDocumentRetriever extends retriever_js_1.BaseRetriever {
107
115
  parentDocs.push(parentDoc);
108
116
  }
109
117
  }
110
- return parentDocs;
118
+ return parentDocs.slice(0, this.parentK);
111
119
  }
112
120
  /**
113
121
  * Adds documents to the docstore and vectorstores.
@@ -14,6 +14,7 @@ export interface ParentDocumentRetrieverFields extends BaseRetrieverInput {
14
14
  parentSplitter?: TextSplitter;
15
15
  idKey?: string;
16
16
  childK?: number;
17
+ parentK?: number;
17
18
  }
18
19
  /**
19
20
  * A type of document retriever that splits input documents into smaller chunks
@@ -33,6 +34,7 @@ export declare class ParentDocumentRetriever extends BaseRetriever {
33
34
  protected parentSplitter?: TextSplitter;
34
35
  protected idKey: string;
35
36
  protected childK?: number;
37
+ protected parentK?: number;
36
38
  constructor(fields: ParentDocumentRetrieverFields);
37
39
  _getRelevantDocuments(query: string): Promise<Document[]>;
38
40
  /**
@@ -1,6 +1,7 @@
1
1
  import * as uuid from "uuid";
2
2
  import { BaseRetriever } from "../schema/retriever.js";
3
3
  import { Document } from "../document.js";
4
+ // TODO: Change this to subclass MultiVectorRetriever
4
5
  /**
5
6
  * A type of document retriever that splits input documents into smaller chunks
6
7
  * while separately storing and preserving the original documents.
@@ -58,12 +59,19 @@ export class ParentDocumentRetriever extends BaseRetriever {
58
59
  writable: true,
59
60
  value: void 0
60
61
  });
62
+ Object.defineProperty(this, "parentK", {
63
+ enumerable: true,
64
+ configurable: true,
65
+ writable: true,
66
+ value: void 0
67
+ });
61
68
  this.vectorstore = fields.vectorstore;
62
69
  this.docstore = fields.docstore;
63
70
  this.childSplitter = fields.childSplitter;
64
71
  this.parentSplitter = fields.parentSplitter;
65
72
  this.idKey = fields.idKey ?? this.idKey;
66
73
  this.childK = fields.childK;
74
+ this.parentK = fields.parentK;
67
75
  }
68
76
  async _getRelevantDocuments(query) {
69
77
  const subDocs = await this.vectorstore.similaritySearch(query, this.childK);
@@ -81,7 +89,7 @@ export class ParentDocumentRetriever extends BaseRetriever {
81
89
  parentDocs.push(parentDoc);
82
90
  }
83
91
  }
84
- return parentDocs;
92
+ return parentDocs.slice(0, this.parentK);
85
93
  }
86
94
  /**
87
95
  * Adds documents to the docstore and vectorstores.
@@ -6,10 +6,7 @@ const runnable_js_1 = require("./runnable.cjs");
6
6
  /**
7
7
  * Abstract base class for a Document retrieval system. A retrieval system
8
8
  * is defined as something that can take string queries and return the
9
- * most 'relevant' Documents from some source. It extends the `Runnable`
10
- * class, which means it is a unit of work that can be invoked, batched,
11
- * streamed, or transformed. In the context of `BaseRetriever`, it is
12
- * invoked with a string input and returns an array of `Document` objects.
9
+ * most 'relevant' Documents from some source.
13
10
  */
14
11
  class BaseRetriever extends runnable_js_1.Runnable {
15
12
  constructor(fields) {
@@ -2,7 +2,7 @@ import { BaseCallbackConfig, CallbackManagerForRetrieverRun, Callbacks } from ".
2
2
  import { Document } from "../document.js";
3
3
  import { Runnable, RunnableConfig } from "./runnable.js";
4
4
  /**
5
- * Base Index class. All indexes should extend this class.
5
+ * Base Retriever class. All indexes should extend this class.
6
6
  */
7
7
  export interface BaseRetrieverInput {
8
8
  callbacks?: Callbacks;
@@ -13,10 +13,7 @@ export interface BaseRetrieverInput {
13
13
  /**
14
14
  * Abstract base class for a Document retrieval system. A retrieval system
15
15
  * is defined as something that can take string queries and return the
16
- * most 'relevant' Documents from some source. It extends the `Runnable`
17
- * class, which means it is a unit of work that can be invoked, batched,
18
- * streamed, or transformed. In the context of `BaseRetriever`, it is
19
- * invoked with a string input and returns an array of `Document` objects.
16
+ * most 'relevant' Documents from some source.
20
17
  */
21
18
  export declare abstract class BaseRetriever extends Runnable<string, Document[]> {
22
19
  callbacks?: Callbacks;
@@ -3,10 +3,7 @@ import { Runnable } from "./runnable.js";
3
3
  /**
4
4
  * Abstract base class for a Document retrieval system. A retrieval system
5
5
  * is defined as something that can take string queries and return the
6
- * most 'relevant' Documents from some source. It extends the `Runnable`
7
- * class, which means it is a unit of work that can be invoked, batched,
8
- * streamed, or transformed. In the context of `BaseRetriever`, it is
9
- * invoked with a string input and returns an array of `Document` objects.
6
+ * most 'relevant' Documents from some source.
10
7
  */
11
8
  export class BaseRetriever extends Runnable {
12
9
  constructor(fields) {
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SearxngSearch = exports.DataForSeoAPISearch = exports.WikipediaQueryRun = exports.BraveSearch = exports.WriteFileTool = exports.ReadFileTool = exports.AIPluginTool = exports.GoogleCustomSearch = exports.Serper = exports.ZapierNLAWrapper = exports.ZapierNLARunAction = exports.VectorStoreQATool = exports.RequestsPostTool = exports.RequestsGetTool = exports.JsonGetValueTool = exports.JsonListKeysTool = exports.JsonSpec = exports.ChainTool = exports.IFTTTWebhook = exports.DynamicStructuredTool = exports.DynamicTool = exports.StructuredTool = exports.Tool = exports.BingSerpAPI = exports.DadJokeAPI = exports.SerpAPI = void 0;
3
+ exports.SearxngSearch = exports.DataForSeoAPISearch = exports.WolframAlphaTool = exports.WikipediaQueryRun = exports.BraveSearch = exports.WriteFileTool = exports.ReadFileTool = exports.AIPluginTool = exports.GoogleCustomSearch = exports.Serper = exports.ZapierNLAWrapper = exports.ZapierNLARunAction = exports.VectorStoreQATool = exports.RequestsPostTool = exports.RequestsGetTool = exports.JsonGetValueTool = exports.JsonListKeysTool = exports.JsonSpec = exports.ChainTool = exports.IFTTTWebhook = exports.DynamicStructuredTool = exports.DynamicTool = exports.StructuredTool = exports.Tool = exports.BingSerpAPI = exports.DadJokeAPI = exports.SerpAPI = void 0;
4
4
  var serpapi_js_1 = require("./serpapi.cjs");
5
5
  Object.defineProperty(exports, "SerpAPI", { enumerable: true, get: function () { return serpapi_js_1.SerpAPI; } });
6
6
  var dadjokeapi_js_1 = require("./dadjokeapi.cjs");
@@ -42,6 +42,8 @@ var brave_search_js_1 = require("./brave_search.cjs");
42
42
  Object.defineProperty(exports, "BraveSearch", { enumerable: true, get: function () { return brave_search_js_1.BraveSearch; } });
43
43
  var wikipedia_query_run_js_1 = require("./wikipedia_query_run.cjs");
44
44
  Object.defineProperty(exports, "WikipediaQueryRun", { enumerable: true, get: function () { return wikipedia_query_run_js_1.WikipediaQueryRun; } });
45
+ var wolframalpha_js_1 = require("./wolframalpha.cjs");
46
+ Object.defineProperty(exports, "WolframAlphaTool", { enumerable: true, get: function () { return wolframalpha_js_1.WolframAlphaTool; } });
45
47
  var dataforseo_api_search_js_1 = require("./dataforseo_api_search.cjs");
46
48
  Object.defineProperty(exports, "DataForSeoAPISearch", { enumerable: true, get: function () { return dataforseo_api_search_js_1.DataForSeoAPISearch; } });
47
49
  var searxng_search_js_1 = require("./searxng_search.cjs");
@@ -15,5 +15,6 @@ export { AIPluginTool } from "./aiplugin.js";
15
15
  export { ReadFileTool, WriteFileTool } from "./fs.js";
16
16
  export { BraveSearch, BraveSearchParams } from "./brave_search.js";
17
17
  export { WikipediaQueryRun, WikipediaQueryRunParams, } from "./wikipedia_query_run.js";
18
+ export { WolframAlphaTool } from "./wolframalpha.js";
18
19
  export { DataForSeoAPISearch, DataForSeoApiConfig, } from "./dataforseo_api_search.js";
19
20
  export { SearxngSearch } from "./searxng_search.js";
@@ -15,5 +15,6 @@ export { AIPluginTool } from "./aiplugin.js";
15
15
  export { ReadFileTool, WriteFileTool } from "./fs.js";
16
16
  export { BraveSearch } from "./brave_search.js";
17
17
  export { WikipediaQueryRun, } from "./wikipedia_query_run.js";
18
+ export { WolframAlphaTool } from "./wolframalpha.js";
18
19
  export { DataForSeoAPISearch, } from "./dataforseo_api_search.js";
19
20
  export { SearxngSearch } from "./searxng_search.js";
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WolframAlphaTool = void 0;
4
+ const base_js_1 = require("./base.cjs");
5
+ class WolframAlphaTool extends base_js_1.Tool {
6
+ constructor(fields) {
7
+ super(fields);
8
+ Object.defineProperty(this, "appid", {
9
+ enumerable: true,
10
+ configurable: true,
11
+ writable: true,
12
+ value: void 0
13
+ });
14
+ Object.defineProperty(this, "name", {
15
+ enumerable: true,
16
+ configurable: true,
17
+ writable: true,
18
+ value: "wolfram_alpha"
19
+ });
20
+ Object.defineProperty(this, "description", {
21
+ enumerable: true,
22
+ configurable: true,
23
+ writable: true,
24
+ value: `A wrapper around Wolfram Alpha. Useful for when you need to answer questions about Math, Science, Technology, Culture, Society and Everyday Life. Input should be a search query.`
25
+ });
26
+ this.appid = fields.appid;
27
+ }
28
+ get lc_namespace() {
29
+ return [...super.lc_namespace, "wolframalpha"];
30
+ }
31
+ static lc_name() {
32
+ return "WolframAlphaTool";
33
+ }
34
+ async _call(query) {
35
+ const url = `https://www.wolframalpha.com/api/v1/llm-api?appid=${this.appid}&input=${query}`;
36
+ const res = await fetch(url);
37
+ return res.text();
38
+ }
39
+ }
40
+ exports.WolframAlphaTool = WolframAlphaTool;
@@ -0,0 +1,12 @@
1
+ import { Tool, ToolParams } from "./base.js";
2
+ export declare class WolframAlphaTool extends Tool {
3
+ appid: string;
4
+ name: string;
5
+ description: string;
6
+ constructor(fields: ToolParams & {
7
+ appid: string;
8
+ });
9
+ get lc_namespace(): string[];
10
+ static lc_name(): string;
11
+ _call(query: string): Promise<string>;
12
+ }
@@ -0,0 +1,36 @@
1
+ import { Tool } from "./base.js";
2
+ export class WolframAlphaTool extends Tool {
3
+ constructor(fields) {
4
+ super(fields);
5
+ Object.defineProperty(this, "appid", {
6
+ enumerable: true,
7
+ configurable: true,
8
+ writable: true,
9
+ value: void 0
10
+ });
11
+ Object.defineProperty(this, "name", {
12
+ enumerable: true,
13
+ configurable: true,
14
+ writable: true,
15
+ value: "wolfram_alpha"
16
+ });
17
+ Object.defineProperty(this, "description", {
18
+ enumerable: true,
19
+ configurable: true,
20
+ writable: true,
21
+ value: `A wrapper around Wolfram Alpha. Useful for when you need to answer questions about Math, Science, Technology, Culture, Society and Everyday Life. Input should be a search query.`
22
+ });
23
+ this.appid = fields.appid;
24
+ }
25
+ get lc_namespace() {
26
+ return [...super.lc_namespace, "wolframalpha"];
27
+ }
28
+ static lc_name() {
29
+ return "WolframAlphaTool";
30
+ }
31
+ async _call(query) {
32
+ const url = `https://www.wolframalpha.com/api/v1/llm-api?appid=${this.appid}&input=${query}`;
33
+ const res = await fetch(url);
34
+ return res.text();
35
+ }
36
+ }
@@ -56,6 +56,12 @@ class Chroma extends base_js_1.VectorStore {
56
56
  writable: true,
57
57
  value: void 0
58
58
  });
59
+ Object.defineProperty(this, "collectionMetadata", {
60
+ enumerable: true,
61
+ configurable: true,
62
+ writable: true,
63
+ value: void 0
64
+ });
59
65
  Object.defineProperty(this, "numDimensions", {
60
66
  enumerable: true,
61
67
  configurable: true,
@@ -77,6 +83,7 @@ class Chroma extends base_js_1.VectorStore {
77
83
  this.numDimensions = args.numDimensions;
78
84
  this.embeddings = embeddings;
79
85
  this.collectionName = ensureCollectionName(args.collectionName);
86
+ this.collectionMetadata = args.collectionMetadata;
80
87
  if ("index" in args) {
81
88
  this.index = args.index;
82
89
  }
@@ -111,6 +118,7 @@ class Chroma extends base_js_1.VectorStore {
111
118
  try {
112
119
  this.collection = await this.index.getOrCreateCollection({
113
120
  name: this.collectionName,
121
+ ...(this.collectionMetadata && { metadata: this.collectionMetadata }),
114
122
  });
115
123
  }
116
124
  catch (err) {
@@ -1,5 +1,5 @@
1
1
  import type { ChromaClient as ChromaClientT, Collection } from "chromadb";
2
- import type { Where } from "chromadb/dist/main/types.js";
2
+ import type { CollectionMetadata, Where } from "chromadb/dist/main/types.js";
3
3
  import { Embeddings } from "../embeddings/base.js";
4
4
  import { VectorStore } from "./base.js";
5
5
  import { Document } from "../document.js";
@@ -17,11 +17,13 @@ export type ChromaLibArgs = {
17
17
  numDimensions?: number;
18
18
  collectionName?: string;
19
19
  filter?: object;
20
+ collectionMetadata?: CollectionMetadata;
20
21
  } | {
21
22
  index?: ChromaClientT;
22
23
  numDimensions?: number;
23
24
  collectionName?: string;
24
25
  filter?: object;
26
+ collectionMetadata?: CollectionMetadata;
25
27
  };
26
28
  /**
27
29
  * Defines the parameters for the `delete` method in the `Chroma` class.
@@ -42,6 +44,7 @@ export declare class Chroma extends VectorStore {
42
44
  index?: ChromaClientT;
43
45
  collection?: Collection;
44
46
  collectionName: string;
47
+ collectionMetadata?: CollectionMetadata;
45
48
  numDimensions?: number;
46
49
  url: string;
47
50
  filter?: object;
@@ -30,6 +30,12 @@ export class Chroma extends VectorStore {
30
30
  writable: true,
31
31
  value: void 0
32
32
  });
33
+ Object.defineProperty(this, "collectionMetadata", {
34
+ enumerable: true,
35
+ configurable: true,
36
+ writable: true,
37
+ value: void 0
38
+ });
33
39
  Object.defineProperty(this, "numDimensions", {
34
40
  enumerable: true,
35
41
  configurable: true,
@@ -51,6 +57,7 @@ export class Chroma extends VectorStore {
51
57
  this.numDimensions = args.numDimensions;
52
58
  this.embeddings = embeddings;
53
59
  this.collectionName = ensureCollectionName(args.collectionName);
60
+ this.collectionMetadata = args.collectionMetadata;
54
61
  if ("index" in args) {
55
62
  this.index = args.index;
56
63
  }
@@ -85,6 +92,7 @@ export class Chroma extends VectorStore {
85
92
  try {
86
93
  this.collection = await this.index.getOrCreateCollection({
87
94
  name: this.collectionName,
95
+ ...(this.collectionMetadata && { metadata: this.collectionMetadata }),
88
96
  });
89
97
  }
90
98
  catch (err) {
@@ -99,9 +99,13 @@ class RedisVectorStore extends base_js_1.VectorStore {
99
99
  async addVectors(vectors, documents, { keys, batchSize = 1000 } = {}) {
100
100
  // check if the index exists and create it if it doesn't
101
101
  await this.createIndex(vectors[0].length);
102
+ const info = await this.redisClient.ft.info(this.indexName);
103
+ const lastKeyCount = parseInt(info.numDocs, 10) || 0;
102
104
  const multi = this.redisClient.multi();
103
105
  vectors.map(async (vector, idx) => {
104
- const key = keys && keys.length ? keys[idx] : `${this.keyPrefix}${idx}`;
106
+ const key = keys && keys.length
107
+ ? keys[idx]
108
+ : `${this.keyPrefix}${idx + lastKeyCount}`;
105
109
  const metadata = documents[idx] && documents[idx].metadata
106
110
  ? documents[idx].metadata
107
111
  : {};
@@ -195,6 +199,10 @@ class RedisVectorStore extends base_js_1.VectorStore {
195
199
  await this.redisClient.ft.info(this.indexName);
196
200
  }
197
201
  catch (err) {
202
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
203
+ if (err?.message.includes("unknown command")) {
204
+ throw new Error("Failed to run FT.INFO command. Please ensure that you are running a RediSearch-capable Redis instance: https://js.langchain.com/docs/modules/data_connection/vectorstores/integrations/redis#setup");
205
+ }
198
206
  // index doesn't exist
199
207
  return false;
200
208
  }
@@ -96,9 +96,13 @@ export class RedisVectorStore extends VectorStore {
96
96
  async addVectors(vectors, documents, { keys, batchSize = 1000 } = {}) {
97
97
  // check if the index exists and create it if it doesn't
98
98
  await this.createIndex(vectors[0].length);
99
+ const info = await this.redisClient.ft.info(this.indexName);
100
+ const lastKeyCount = parseInt(info.numDocs, 10) || 0;
99
101
  const multi = this.redisClient.multi();
100
102
  vectors.map(async (vector, idx) => {
101
- const key = keys && keys.length ? keys[idx] : `${this.keyPrefix}${idx}`;
103
+ const key = keys && keys.length
104
+ ? keys[idx]
105
+ : `${this.keyPrefix}${idx + lastKeyCount}`;
102
106
  const metadata = documents[idx] && documents[idx].metadata
103
107
  ? documents[idx].metadata
104
108
  : {};
@@ -192,6 +196,10 @@ export class RedisVectorStore extends VectorStore {
192
196
  await this.redisClient.ft.info(this.indexName);
193
197
  }
194
198
  catch (err) {
199
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
200
+ if (err?.message.includes("unknown command")) {
201
+ throw new Error("Failed to run FT.INFO command. Please ensure that you are running a RediSearch-capable Redis instance: https://js.langchain.com/docs/modules/data_connection/vectorstores/integrations/redis#setup");
202
+ }
195
203
  // index doesn't exist
196
204
  return false;
197
205
  }
@@ -260,7 +260,7 @@ class VectaraStore extends base_js_1.VectorStore {
260
260
  documentMetadata.forEach((item) => {
261
261
  combinedMetadata[item.name] = item.value;
262
262
  });
263
- responses[i].metadata = Object.entries(combinedMetadata).map(([name, value]) => ({ name, value }));
263
+ responses[i].metadata = combinedMetadata;
264
264
  }
265
265
  const documentsAndScores = responses.map((response) => [
266
266
  new document_js_1.Document({
@@ -257,7 +257,7 @@ export class VectaraStore extends VectorStore {
257
257
  documentMetadata.forEach((item) => {
258
258
  combinedMetadata[item.name] = item.value;
259
259
  });
260
- responses[i].metadata = Object.entries(combinedMetadata).map(([name, value]) => ({ name, value }));
260
+ responses[i].metadata = combinedMetadata;
261
261
  }
262
262
  const documentsAndScores = responses.map((response) => [
263
263
  new Document({
@@ -0,0 +1 @@
1
+ module.exports = require('../dist/llms/llama_cpp.cjs');
@@ -0,0 +1 @@
1
+ export * from '../dist/llms/llama_cpp.js'
@@ -0,0 +1 @@
1
+ export * from '../dist/llms/llama_cpp.js'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "langchain",
3
- "version": "0.0.135",
3
+ "version": "0.0.137",
4
4
  "description": "Typescript bindings for langchain",
5
5
  "type": "module",
6
6
  "engines": {
@@ -145,6 +145,9 @@
145
145
  "llms/bedrock.cjs",
146
146
  "llms/bedrock.js",
147
147
  "llms/bedrock.d.ts",
148
+ "llms/llama_cpp.cjs",
149
+ "llms/llama_cpp.js",
150
+ "llms/llama_cpp.d.ts",
148
151
  "llms/writer.cjs",
149
152
  "llms/writer.js",
150
153
  "llms/writer.d.ts",
@@ -448,6 +451,9 @@
448
451
  "retrievers/document_compressors.cjs",
449
452
  "retrievers/document_compressors.js",
450
453
  "retrievers/document_compressors.d.ts",
454
+ "retrievers/multi_vector.cjs",
455
+ "retrievers/multi_vector.js",
456
+ "retrievers/multi_vector.d.ts",
451
457
  "retrievers/parent_document.cjs",
452
458
  "retrievers/parent_document.js",
453
459
  "retrievers/parent_document.d.ts",
@@ -687,6 +693,7 @@
687
693
  "ml-matrix": "^6.10.4",
688
694
  "mongodb": "^5.2.0",
689
695
  "mysql2": "^3.3.3",
696
+ "node-llama-cpp": "^2.1.2",
690
697
  "notion-to-md": "^3.1.0",
691
698
  "pdf-parse": "1.1.1",
692
699
  "peggy": "^3.0.2",
@@ -772,6 +779,7 @@
772
779
  "mammoth": "*",
773
780
  "mongodb": "^5.2.0",
774
781
  "mysql2": "^3.3.3",
782
+ "node-llama-cpp": "*",
775
783
  "notion-to-md": "^3.1.0",
776
784
  "pdf-parse": "1.1.1",
777
785
  "peggy": "^3.0.2",
@@ -964,6 +972,9 @@
964
972
  "mysql2": {
965
973
  "optional": true
966
974
  },
975
+ "node-llama-cpp": {
976
+ "optional": true
977
+ },
967
978
  "notion-to-md": {
968
979
  "optional": true
969
980
  },
@@ -1297,6 +1308,11 @@
1297
1308
  "import": "./llms/bedrock.js",
1298
1309
  "require": "./llms/bedrock.cjs"
1299
1310
  },
1311
+ "./llms/llama_cpp": {
1312
+ "types": "./llms/llama_cpp.d.ts",
1313
+ "import": "./llms/llama_cpp.js",
1314
+ "require": "./llms/llama_cpp.cjs"
1315
+ },
1300
1316
  "./llms/writer": {
1301
1317
  "types": "./llms/writer.d.ts",
1302
1318
  "import": "./llms/writer.js",
@@ -1810,6 +1826,11 @@
1810
1826
  "import": "./retrievers/document_compressors.js",
1811
1827
  "require": "./retrievers/document_compressors.cjs"
1812
1828
  },
1829
+ "./retrievers/multi_vector": {
1830
+ "types": "./retrievers/multi_vector.d.ts",
1831
+ "import": "./retrievers/multi_vector.js",
1832
+ "require": "./retrievers/multi_vector.cjs"
1833
+ },
1813
1834
  "./retrievers/parent_document": {
1814
1835
  "types": "./retrievers/parent_document.d.ts",
1815
1836
  "import": "./retrievers/parent_document.js",
@@ -0,0 +1 @@
1
+ module.exports = require('../dist/retrievers/multi_vector.cjs');
@@ -0,0 +1 @@
1
+ export * from '../dist/retrievers/multi_vector.js'
@@ -0,0 +1 @@
1
+ export * from '../dist/retrievers/multi_vector.js'