@langchain/core
Version:
Core LangChain.js abstractions and schemas
1 lines • 5.26 kB
Source Map (JSON)
{"version":3,"file":"semantic_similarity.d.ts","names":["Embeddings","VectorStoreInterface","VectorStoreRetrieverInterface","VectorStore","Example","BaseExampleSelector","SemanticSimilarityExampleSelectorInput","V","SemanticSimilarityExampleSelector","Promise","T","Record","C","Parameters"],"sources":["../../src/example_selectors/semantic_similarity.d.ts"],"sourcesContent":["import type { Embeddings } from \"../embeddings.js\";\nimport type { VectorStoreInterface, VectorStoreRetrieverInterface, VectorStore } from \"../vectorstores.js\";\nimport type { Example } from \"../prompts/base.js\";\nimport { BaseExampleSelector } from \"./base.js\";\n/**\n * Interface for the input data of the SemanticSimilarityExampleSelector\n * class.\n */\nexport type SemanticSimilarityExampleSelectorInput<V extends VectorStoreInterface = VectorStoreInterface> = {\n vectorStore: V;\n k?: number;\n filter?: V[\"FilterType\"];\n exampleKeys?: string[];\n inputKeys?: string[];\n vectorStoreRetriever?: never;\n} | {\n vectorStoreRetriever: VectorStoreRetrieverInterface<V>;\n exampleKeys?: string[];\n inputKeys?: string[];\n vectorStore?: never;\n k?: never;\n filter?: never;\n};\n/**\n * Class that selects examples based on semantic similarity. It extends\n * the BaseExampleSelector class.\n * @example\n * ```typescript\n * const exampleSelector = await SemanticSimilarityExampleSelector.fromExamples(\n * [\n * { input: \"happy\", output: \"sad\" },\n * { input: \"tall\", output: \"short\" },\n * { input: \"energetic\", output: \"lethargic\" },\n * { input: \"sunny\", output: \"gloomy\" },\n * { input: \"windy\", output: \"calm\" },\n * ],\n * new OpenAIEmbeddings(),\n * HNSWLib,\n * { k: 1 },\n * );\n * const dynamicPrompt = new FewShotPromptTemplate({\n * exampleSelector,\n * examplePrompt: PromptTemplate.fromTemplate(\n * \"Input: {input}\\nOutput: {output}\",\n * ),\n * prefix: \"Give the antonym of every input\",\n * suffix: \"Input: {adjective}\\nOutput:\",\n * inputVariables: [\"adjective\"],\n * });\n * console.log(await dynamicPrompt.format({ adjective: \"rainy\" }));\n * ```\n */\nexport declare class SemanticSimilarityExampleSelector<V extends VectorStoreInterface = VectorStoreInterface> extends BaseExampleSelector {\n vectorStoreRetriever: VectorStoreRetrieverInterface<V>;\n exampleKeys?: string[];\n inputKeys?: string[];\n constructor(data: SemanticSimilarityExampleSelectorInput<V>);\n /**\n * Method that adds a new example to the vectorStore. The example is\n * converted to a string and added to the vectorStore as a document.\n * @param example The example to be added to the vectorStore.\n * @returns Promise that resolves when the example has been added to the vectorStore.\n */\n addExample(example: Example): Promise<void>;\n /**\n * Method that selects which examples to use based on semantic similarity.\n * It performs a similarity search in the vectorStore using the input\n * variables and returns the examples with the highest similarity.\n * @param inputVariables The input variables used for the similarity search.\n * @returns Promise that resolves with an array of the selected examples.\n */\n selectExamples<T>(inputVariables: Record<string, T>): Promise<Example[]>;\n /**\n * Static method that creates a new instance of\n * SemanticSimilarityExampleSelector. It takes a list of examples, an\n * instance of Embeddings, a VectorStore class, and an options object as\n * parameters. It converts the examples to strings, creates a VectorStore\n * from the strings and the embeddings, and returns a new\n * SemanticSimilarityExampleSelector with the created VectorStore and the\n * options provided.\n * @param examples The list of examples to be used.\n * @param embeddings The instance of Embeddings to be used.\n * @param vectorStoreCls The VectorStore class to be used.\n * @param options The options object for the SemanticSimilarityExampleSelector.\n * @returns Promise that resolves with a new instance of SemanticSimilarityExampleSelector.\n */\n static fromExamples<C extends typeof VectorStore>(examples: Record<string, string>[], embeddings: Embeddings, vectorStoreCls: C, options?: {\n k?: number;\n inputKeys?: string[];\n } & Parameters<C[\"fromTexts\"]>[3]): Promise<SemanticSimilarityExampleSelector>;\n}\n"],"mappings":";;;;;;;;;AAQA;;AAA6DC,KAAjDK,sCAAiDL,CAAAA,UAAAA,oBAAAA,GAAuBA,oBAAvBA,CAAAA,GAAAA;EAAoB,WAAGA,EACnEM,CADmEN;EAAoB,CAAA,CAAA,EACvFM,MAAAA;EAAC,MAELA,CAAAA,EAAAA,CAAAA,CAAAA,YAAAA,CAAAA;EAAC,WAK0CA,CAAAA,EAAAA,MAAAA,EAAAA;EAAC,SAA/BL,CAAAA,EAAAA,MAAAA,EAAAA;EAA6B,oBAAA,CAAA,EAAA,KAAA;AAoCvD,CAAA,GAAqBM;EAAiC,oBAAA,EApC5BN,6BAoC4B,CApCEK,CAoCF,CAAA;EAAA,WAAWN,CAAAA,EAAAA,MAAAA,EAAAA;EAAoB,SAAGA,CAAAA,EAAAA,MAAAA,EAAAA;EAAoB,WACpDM,CAAAA,EAAAA,KAAAA;EAAC,CAAA,CAAA,EAA/BL,KAAAA;EAA6B,MAGMK,CAAAA,EAAAA,KAAAA;CAAC;;;;;;;;;;;;;;;;AAJ2E;;;;;;;;;;;;;;cAApHC,4CAA4CP,uBAAuBA,8BAA8BI,mBAAAA;wBAC5FH,8BAA8BK;;;oBAGlCD,uCAAuCC;;;;;;;sBAOrCH,UAAUK;;;;;;;;oCAQIE,eAAeD,KAAKD,QAAQL;;;;;;;;;;;;;;;uCAezBD,uBAAuBQ,sCAAsCX,4BAA4BY;;;MAG1HC,WAAWD,qBAAqBH,QAAQD"}