langchain 0.0.162 → 0.0.163

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.
@@ -39,10 +39,17 @@ class SemanticSimilarityExampleSelector extends base_js_1.BaseExampleSelector {
39
39
  writable: true,
40
40
  value: void 0
41
41
  });
42
+ Object.defineProperty(this, "filter", {
43
+ enumerable: true,
44
+ configurable: true,
45
+ writable: true,
46
+ value: void 0
47
+ });
42
48
  this.vectorStore = data.vectorStore;
43
49
  this.k = data.k ?? 4;
44
50
  this.exampleKeys = data.exampleKeys;
45
51
  this.inputKeys = data.inputKeys;
52
+ this.filter = data.filter;
46
53
  }
47
54
  /**
48
55
  * Method that adds a new example to the vectorStore. The example is
@@ -56,7 +63,7 @@ class SemanticSimilarityExampleSelector extends base_js_1.BaseExampleSelector {
56
63
  await this.vectorStore.addDocuments([
57
64
  new document_js_1.Document({
58
65
  pageContent: stringExample,
59
- metadata: { example },
66
+ metadata: example,
60
67
  }),
61
68
  ]);
62
69
  }
@@ -70,7 +77,7 @@ class SemanticSimilarityExampleSelector extends base_js_1.BaseExampleSelector {
70
77
  async selectExamples(inputVariables) {
71
78
  const inputKeys = this.inputKeys ?? Object.keys(inputVariables);
72
79
  const query = sortedValues(inputKeys.reduce((acc, key) => ({ ...acc, [key]: inputVariables[key] }), {})).join(" ");
73
- const exampleDocs = await this.vectorStore.similaritySearch(query, this.k);
80
+ const exampleDocs = await this.vectorStore.similaritySearch(query, this.k, this.filter);
74
81
  const examples = exampleDocs.map((doc) => doc.metadata);
75
82
  if (this.exampleKeys) {
76
83
  // If example keys are provided, filter examples to those keys.
@@ -6,9 +6,10 @@ import { BaseExampleSelector } from "../base.js";
6
6
  * Interface for the input data of the SemanticSimilarityExampleSelector
7
7
  * class.
8
8
  */
9
- export interface SemanticSimilarityExampleSelectorInput {
10
- vectorStore: VectorStore;
9
+ export interface SemanticSimilarityExampleSelectorInput<V extends VectorStore = VectorStore> {
10
+ vectorStore: V;
11
11
  k?: number;
12
+ filter?: V["FilterType"];
12
13
  exampleKeys?: string[];
13
14
  inputKeys?: string[];
14
15
  }
@@ -16,12 +17,13 @@ export interface SemanticSimilarityExampleSelectorInput {
16
17
  * Class that selects examples based on semantic similarity. It extends
17
18
  * the BaseExampleSelector class.
18
19
  */
19
- export declare class SemanticSimilarityExampleSelector extends BaseExampleSelector {
20
- vectorStore: VectorStore;
20
+ export declare class SemanticSimilarityExampleSelector<V extends VectorStore = VectorStore> extends BaseExampleSelector {
21
+ vectorStore: V;
21
22
  k: number;
22
23
  exampleKeys?: string[];
23
24
  inputKeys?: string[];
24
- constructor(data: SemanticSimilarityExampleSelectorInput);
25
+ filter?: V["FilterType"];
26
+ constructor(data: SemanticSimilarityExampleSelectorInput<V>);
25
27
  /**
26
28
  * Method that adds a new example to the vectorStore. The example is
27
29
  * converted to a string and added to the vectorStore as a document.
@@ -36,10 +36,17 @@ export class SemanticSimilarityExampleSelector extends BaseExampleSelector {
36
36
  writable: true,
37
37
  value: void 0
38
38
  });
39
+ Object.defineProperty(this, "filter", {
40
+ enumerable: true,
41
+ configurable: true,
42
+ writable: true,
43
+ value: void 0
44
+ });
39
45
  this.vectorStore = data.vectorStore;
40
46
  this.k = data.k ?? 4;
41
47
  this.exampleKeys = data.exampleKeys;
42
48
  this.inputKeys = data.inputKeys;
49
+ this.filter = data.filter;
43
50
  }
44
51
  /**
45
52
  * Method that adds a new example to the vectorStore. The example is
@@ -53,7 +60,7 @@ export class SemanticSimilarityExampleSelector extends BaseExampleSelector {
53
60
  await this.vectorStore.addDocuments([
54
61
  new Document({
55
62
  pageContent: stringExample,
56
- metadata: { example },
63
+ metadata: example,
57
64
  }),
58
65
  ]);
59
66
  }
@@ -67,7 +74,7 @@ export class SemanticSimilarityExampleSelector extends BaseExampleSelector {
67
74
  async selectExamples(inputVariables) {
68
75
  const inputKeys = this.inputKeys ?? Object.keys(inputVariables);
69
76
  const query = sortedValues(inputKeys.reduce((acc, key) => ({ ...acc, [key]: inputVariables[key] }), {})).join(" ");
70
- const exampleDocs = await this.vectorStore.similaritySearch(query, this.k);
77
+ const exampleDocs = await this.vectorStore.similaritySearch(query, this.k, this.filter);
71
78
  const examples = exampleDocs.map((doc) => doc.metadata);
72
79
  if (this.exampleKeys) {
73
80
  // If example keys are provided, filter examples to those keys.
@@ -48,7 +48,8 @@ class BedrockLLMInputOutputAdapter {
48
48
  else if (provider === "ai21") {
49
49
  return responseBody?.completions?.[0]?.data?.text ?? "";
50
50
  }
51
- return responseBody.outputText;
51
+ // I haven't been able to get a response with more than one result in it.
52
+ return responseBody.results?.[0]?.outputText;
52
53
  }
53
54
  }
54
55
  exports.BedrockLLMInputOutputAdapter = BedrockLLMInputOutputAdapter;
@@ -45,6 +45,7 @@ export class BedrockLLMInputOutputAdapter {
45
45
  else if (provider === "ai21") {
46
46
  return responseBody?.completions?.[0]?.data?.text ?? "";
47
47
  }
48
- return responseBody.outputText;
48
+ // I haven't been able to get a response with more than one result in it.
49
+ return responseBody.results?.[0]?.outputText;
49
50
  }
50
51
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "langchain",
3
- "version": "0.0.162",
3
+ "version": "0.0.163",
4
4
  "description": "Typescript bindings for langchain",
5
5
  "type": "module",
6
6
  "engines": {