langchain 0.0.135 → 0.0.136

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.
@@ -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 {
@@ -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") {
@@ -84,12 +84,19 @@ class ParentDocumentRetriever extends retriever_js_1.BaseRetriever {
84
84
  writable: true,
85
85
  value: void 0
86
86
  });
87
+ Object.defineProperty(this, "parentK", {
88
+ enumerable: true,
89
+ configurable: true,
90
+ writable: true,
91
+ value: void 0
92
+ });
87
93
  this.vectorstore = fields.vectorstore;
88
94
  this.docstore = fields.docstore;
89
95
  this.childSplitter = fields.childSplitter;
90
96
  this.parentSplitter = fields.parentSplitter;
91
97
  this.idKey = fields.idKey ?? this.idKey;
92
98
  this.childK = fields.childK;
99
+ this.parentK = fields.parentK;
93
100
  }
94
101
  async _getRelevantDocuments(query) {
95
102
  const subDocs = await this.vectorstore.similaritySearch(query, this.childK);
@@ -107,7 +114,7 @@ class ParentDocumentRetriever extends retriever_js_1.BaseRetriever {
107
114
  parentDocs.push(parentDoc);
108
115
  }
109
116
  }
110
- return parentDocs;
117
+ return parentDocs.slice(0, this.parentK);
111
118
  }
112
119
  /**
113
120
  * 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
  /**
@@ -58,12 +58,19 @@ export class ParentDocumentRetriever extends BaseRetriever {
58
58
  writable: true,
59
59
  value: void 0
60
60
  });
61
+ Object.defineProperty(this, "parentK", {
62
+ enumerable: true,
63
+ configurable: true,
64
+ writable: true,
65
+ value: void 0
66
+ });
61
67
  this.vectorstore = fields.vectorstore;
62
68
  this.docstore = fields.docstore;
63
69
  this.childSplitter = fields.childSplitter;
64
70
  this.parentSplitter = fields.parentSplitter;
65
71
  this.idKey = fields.idKey ?? this.idKey;
66
72
  this.childK = fields.childK;
73
+ this.parentK = fields.parentK;
67
74
  }
68
75
  async _getRelevantDocuments(query) {
69
76
  const subDocs = await this.vectorstore.similaritySearch(query, this.childK);
@@ -81,7 +88,7 @@ export class ParentDocumentRetriever extends BaseRetriever {
81
88
  parentDocs.push(parentDoc);
82
89
  }
83
90
  }
84
- return parentDocs;
91
+ return parentDocs.slice(0, this.parentK);
85
92
  }
86
93
  /**
87
94
  * Adds documents to the docstore and vectorstores.
@@ -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({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "langchain",
3
- "version": "0.0.135",
3
+ "version": "0.0.136",
4
4
  "description": "Typescript bindings for langchain",
5
5
  "type": "module",
6
6
  "engines": {