@langchain/community
Version:
Third-party integrations for LangChain.js
1 lines • 2.71 kB
Source Map (JSON)
{"version":3,"file":"metal.cjs","names":["BaseRetriever","fields: MetalRetrieverFields","query: string","Document"],"sources":["../../src/retrievers/metal.ts"],"sourcesContent":["import type { Client as Metal } from \"@getmetal/metal-sdk\";\n\nimport { BaseRetriever, BaseRetrieverInput } from \"@langchain/core/retrievers\";\nimport { Document } from \"@langchain/core/documents\";\n\n/**\n * Interface for the fields required during the initialization of a\n * `MetalRetriever` instance. It extends the `BaseRetrieverInput`\n * interface and adds a `client` field of type `Metal`.\n */\nexport interface MetalRetrieverFields extends BaseRetrieverInput {\n client: Metal;\n}\n\n/**\n * Interface to represent a response item from the Metal service. It\n * contains a `text` field and an index signature to allow for additional\n * unknown properties.\n */\ninterface ResponseItem {\n text: string;\n [key: string]: unknown;\n}\n\n/**\n * Class used to interact with the Metal service, a managed retrieval &\n * memory platform. It allows you to index your data into Metal and run\n * semantic search and retrieval on it. It extends the `BaseRetriever`\n * class and requires a `Metal` instance and a dictionary of parameters to\n * pass to the Metal API during its initialization.\n * @example\n * ```typescript\n * const retriever = new MetalRetriever({\n * client: new Metal(\n * process.env.METAL_API_KEY,\n * process.env.METAL_CLIENT_ID,\n * process.env.METAL_INDEX_ID,\n * ),\n * });\n * const docs = await retriever.getRelevantDocuments(\"hello\");\n * ```\n */\nexport class MetalRetriever extends BaseRetriever {\n static lc_name() {\n return \"MetalRetriever\";\n }\n\n lc_namespace = [\"langchain\", \"retrievers\", \"metal\"];\n\n private client: Metal;\n\n constructor(fields: MetalRetrieverFields) {\n super(fields);\n\n this.client = fields.client;\n }\n\n async _getRelevantDocuments(query: string): Promise<Document[]> {\n const res = await this.client.search({ text: query });\n\n const items = (\"data\" in res ? res.data : res) as ResponseItem[];\n return items.map(\n ({ text, metadata }) =>\n new Document({\n pageContent: text,\n metadata: metadata as Record<string, unknown>,\n })\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AA0CA,IAAa,iBAAb,cAAoCA,0CAAc;CAChD,OAAO,UAAU;AACf,SAAO;CACR;CAED,eAAe;EAAC;EAAa;EAAc;CAAQ;CAEnD,AAAQ;CAER,YAAYC,QAA8B;EACxC,MAAM,OAAO;EAEb,KAAK,SAAS,OAAO;CACtB;CAED,MAAM,sBAAsBC,OAAoC;EAC9D,MAAM,MAAM,MAAM,KAAK,OAAO,OAAO,EAAE,MAAM,MAAO,EAAC;EAErD,MAAM,QAAS,UAAU,MAAM,IAAI,OAAO;AAC1C,SAAO,MAAM,IACX,CAAC,EAAE,MAAM,UAAU,KACjB,IAAIC,oCAAS;GACX,aAAa;GACH;EACX,GACJ;CACF;AACF"}