{"version":3,"file":"vespa.cjs","names":["RemoteRetriever","Document"],"sources":["../../src/retrievers/vespa.ts"],"sourcesContent":["import { Document, type DocumentInterface } from \"@langchain/core/documents\";\nimport {\n  RemoteRetriever,\n  RemoteRetrieverValues,\n  RemoteRetrieverParams,\n} from \"./remote/base.js\";\n\nexport interface VespaRetrieverParams extends RemoteRetrieverParams {\n  /**\n   * The body of the query to send to Vespa\n   */\n  query_body: object;\n  /**\n   * The name of the field the content resides in\n   */\n  content_field: string;\n}\n\n/**\n * Class responsible for retrieving data from Vespa. It extends the\n * `RemoteRetriever` class and includes methods for creating the JSON body\n * for a query and processing the JSON response from Vespa.\n * @example\n * ```typescript\n * const retriever = new VespaRetriever({\n *   url: \"https:\n *   auth: false,\n *   query_body: {\n *     yql: \"select content from paragraph where userQuery()\",\n *     hits: 5,\n *     ranking: \"documentation\",\n *     locale: \"en-us\",\n *   },\n *   content_field: \"content\",\n * });\n * const result = await retriever.getRelevantDocuments(\"what is vespa?\");\n * ```\n */\nexport class VespaRetriever extends RemoteRetriever {\n  static lc_name() {\n    return \"VespaRetriever\";\n  }\n\n  lc_namespace = [\"langchain\", \"retrievers\", \"vespa\"];\n\n  query_body: object;\n\n  content_field: string;\n\n  constructor(fields: VespaRetrieverParams) {\n    super(fields);\n    this.query_body = fields.query_body;\n    this.content_field = fields.content_field;\n\n    this.url = `${this.url}/search/?`;\n  }\n\n  /**\n   * Method that takes a query string as input and returns a JSON object\n   * that includes the query and the original `query_body`.\n   * @param query The query string to be sent to Vespa.\n   * @returns A JSON object that includes the query and the original `query_body`.\n   */\n  createJsonBody(query: string): RemoteRetrieverValues {\n    return {\n      ...this.query_body,\n      query,\n    };\n  }\n\n  /**\n   * Method that processes the JSON response from Vespa into an array of\n   * `Document` instances. Each `Document` instance includes the content\n   * from the specified `content_field` and the document's ID.\n   * @param json The JSON response from Vespa.\n   * @returns An array of `Document` instances.\n   */\n  processJsonResponse(json: RemoteRetrieverValues): DocumentInterface[] {\n    return json.root.children.map(\n      (doc: {\n        id: string;\n        relevance: number;\n        source: string;\n        fields: Record<string, unknown>;\n      }) =>\n        new Document({\n          pageContent: doc.fields[this.content_field] as string,\n          metadata: { id: doc.id },\n        })\n    );\n  }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,IAAa,iBAAb,cAAoCA,aAAAA,gBAAgB;CAClD,OAAO,UAAU;AACf,SAAO;;CAGT,eAAe;EAAC;EAAa;EAAc;EAAQ;CAEnD;CAEA;CAEA,YAAY,QAA8B;AACxC,QAAM,OAAO;AACb,OAAK,aAAa,OAAO;AACzB,OAAK,gBAAgB,OAAO;AAE5B,OAAK,MAAM,GAAG,KAAK,IAAI;;;;;;;;CASzB,eAAe,OAAsC;AACnD,SAAO;GACL,GAAG,KAAK;GACR;GACD;;;;;;;;;CAUH,oBAAoB,MAAkD;AACpE,SAAO,KAAK,KAAK,SAAS,KACvB,QAMC,IAAIC,0BAAAA,SAAS;GACX,aAAa,IAAI,OAAO,KAAK;GAC7B,UAAU,EAAE,IAAI,IAAI,IAAI;GACzB,CAAC,CACL"}