@langchain/openai
Version:
OpenAI integrations for LangChain.js
1 lines • 7.82 kB
Source Map (JSON)
{"version":3,"file":"fileSearch.d.cts","names":["OpenAI","OpenAIClient","ServerTool","FileSearchComparisonType","FileSearchComparisonFilter","Array","FileSearchCompoundFilter","FileSearchFilter","FileSearchHybridSearchWeights","FileSearchRankingOptions","FileSearchOptions","FileSearchTool","Responses","fileSearch"],"sources":["../../src/tools/fileSearch.d.ts"],"sourcesContent":["import { OpenAI as OpenAIClient } from \"openai\";\nimport type { ServerTool } from \"@langchain/core/tools\";\n/**\n * Comparison operators for file attribute filtering.\n */\nexport type FileSearchComparisonType = \"eq\" | \"ne\" | \"gt\" | \"gte\" | \"lt\" | \"lte\";\n/**\n * A filter used to compare a specified attribute key to a given value.\n */\nexport interface FileSearchComparisonFilter {\n /**\n * The comparison operator to use.\n * - `eq`: equals\n * - `ne`: not equal\n * - `gt`: greater than\n * - `gte`: greater than or equal\n * - `lt`: less than\n * - `lte`: less than or equal\n */\n type: FileSearchComparisonType;\n /**\n * The attribute key to compare against.\n */\n key: string;\n /**\n * The value to compare against the attribute key.\n * Supports string, number, boolean, or array of strings/numbers.\n */\n value: string | number | boolean | Array<string | number>;\n}\n/**\n * Combine multiple filters using `and` or `or`.\n */\nexport interface FileSearchCompoundFilter {\n /**\n * Type of operation: `and` or `or`.\n */\n type: \"and\" | \"or\";\n /**\n * Array of filters to combine.\n */\n filters: Array<FileSearchComparisonFilter | FileSearchCompoundFilter>;\n}\n/**\n * Filter type for file search - can be a comparison or compound filter.\n */\nexport type FileSearchFilter = FileSearchComparisonFilter | FileSearchCompoundFilter;\n/**\n * Weights for hybrid search balancing semantic and keyword matches.\n */\nexport interface FileSearchHybridSearchWeights {\n /**\n * The weight of semantic embedding matches (0-1).\n */\n embeddingWeight: number;\n /**\n * The weight of keyword/text matches (0-1).\n */\n textWeight: number;\n}\n/**\n * Ranking options for file search results.\n */\nexport interface FileSearchRankingOptions {\n /**\n * The ranker to use for the file search.\n * - `auto`: Automatically select the best ranker\n * - `default-2024-11-15`: Default ranker as of November 2024\n */\n ranker?: \"auto\" | \"default-2024-11-15\";\n /**\n * The score threshold for results (0-1).\n * Numbers closer to 1 return only the most relevant results but may return fewer.\n */\n scoreThreshold?: number;\n /**\n * Weights that control how reciprocal rank fusion balances semantic\n * embedding matches versus sparse keyword matches when hybrid search is enabled.\n */\n hybridSearch?: FileSearchHybridSearchWeights;\n}\n/**\n * Options for the File Search tool.\n */\nexport interface FileSearchOptions {\n /**\n * The IDs of the vector stores to search.\n * You must have previously created vector stores and uploaded files to them.\n */\n vectorStoreIds: string[];\n /**\n * The maximum number of results to return.\n * Must be between 1 and 50 inclusive.\n */\n maxNumResults?: number;\n /**\n * A filter to apply based on file attributes/metadata.\n * Use this to narrow down search results to specific categories or file types.\n */\n filters?: FileSearchFilter;\n /**\n * Ranking options to customize how results are scored and ordered.\n */\n rankingOptions?: FileSearchRankingOptions;\n}\n/**\n * OpenAI File Search tool type for the Responses API.\n */\nexport type FileSearchTool = OpenAIClient.Responses.FileSearchTool;\n/**\n * Creates a File Search tool that allows models to search your files\n * for relevant information using semantic and keyword search.\n *\n * File Search enables models to retrieve information from a knowledge base\n * of previously uploaded files stored in vector stores. This is a hosted tool\n * managed by OpenAI - you don't need to implement the search execution yourself.\n *\n * **Prerequisites**: Before using File Search, you must:\n * 1. Upload files to the File API with `purpose: \"assistants\"`\n * 2. Create a vector store\n * 3. Add files to the vector store\n *\n * @see {@link https://platform.openai.com/docs/guides/tools-file-search | OpenAI File Search Documentation}\n *\n * @param options - Configuration options for the File Search tool\n * @returns A File Search tool definition to be passed to the OpenAI Responses API\n *\n * @example\n * ```typescript\n * import { ChatOpenAI, tools } from \"@langchain/openai\";\n *\n * const model = new ChatOpenAI({ model: \"gpt-4.1\" });\n *\n * // Basic usage with a vector store\n * const response = await model.invoke(\n * \"What is deep research by OpenAI?\",\n * {\n * tools: [tools.fileSearch({\n * vectorStoreIds: [\"vs_abc123\"]\n * })]\n * }\n * );\n *\n * // Limit the number of results for lower latency\n * const response = await model.invoke(\n * \"Find information about pricing\",\n * {\n * tools: [tools.fileSearch({\n * vectorStoreIds: [\"vs_abc123\"],\n * maxNumResults: 5\n * })]\n * }\n * );\n *\n * // With metadata filtering\n * const response = await model.invoke(\n * \"Find recent blog posts about AI\",\n * {\n * tools: [tools.fileSearch({\n * vectorStoreIds: [\"vs_abc123\"],\n * filters: {\n * type: \"eq\",\n * key: \"category\",\n * value: \"blog\"\n * }\n * })]\n * }\n * );\n *\n * // With compound filters (AND/OR)\n * const response = await model.invoke(\n * \"Find technical docs from 2024\",\n * {\n * tools: [tools.fileSearch({\n * vectorStoreIds: [\"vs_abc123\"],\n * filters: {\n * type: \"and\",\n * filters: [\n * { type: \"eq\", key: \"category\", value: \"technical\" },\n * { type: \"gte\", key: \"year\", value: 2024 }\n * ]\n * }\n * })]\n * }\n * );\n *\n * // With ranking options for more relevant results\n * const response = await model.invoke(\n * \"Find the most relevant information\",\n * {\n * tools: [tools.fileSearch({\n * vectorStoreIds: [\"vs_abc123\"],\n * rankingOptions: {\n * scoreThreshold: 0.8,\n * ranker: \"auto\"\n * }\n * })]\n * }\n * );\n *\n * // Search multiple vector stores\n * const response = await model.invoke(\n * \"Search across all knowledge bases\",\n * {\n * tools: [tools.fileSearch({\n * vectorStoreIds: [\"vs_abc123\", \"vs_def456\"]\n * })]\n * }\n * );\n * ```\n *\n * @remarks\n * - Vector stores must be created and populated before using this tool\n * - The tool returns file citations in the response annotations\n * - Use `include: [\"file_search_call.results\"]` in the API call to get search results\n * - Supported file types include PDF, DOCX, TXT, MD, and many code file formats\n */\nexport declare function fileSearch(options: FileSearchOptions): ServerTool;\n//# sourceMappingURL=fileSearch.d.ts.map"],"mappings":";;;;;;;AAKA;AAIiBI,KAJLD,wBAAAA,GAI+B,IAAA,GAUjCA,IAAAA,GAAAA,IAAAA,GAAAA,KAAAA,GAAAA,IAS6BE,GAAAA,KAAK;AAK5C;;;AAQaA,UAhCID,0BAAAA,CAgCJC;EAAK;AAKlB;AAIA;AAaA;AAqBA;AAwBA;AA6GA;;;QAtMUF;;;;;;;;;qCAS6BE;;;;;UAKtBC,wBAAAA;;;;;;;;WAQJD,MAAMD,6BAA6BE;;;;;KAKpCC,gBAAAA,GAAmBH,6BAA6BE;;;;UAI3CE,6BAAAA;;;;;;;;;;;;;UAaAC,wBAAAA;;;;;;;;;;;;;;;;iBAgBED;;;;;UAKFE,iBAAAA;;;;;;;;;;;;;;;YAeHH;;;;mBAIOE;;;;;KAKTE,cAAAA,GAAiBV,QAAAA,CAAaW,SAAAA,CAAUD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA6G5BE,UAAAA,UAAoBH,oBAAoBR"}