{"version":3,"file":"tigris.cjs","names":["VectorStore","embeddings: EmbeddingsInterface","args: TigrisLibArgs","documents: Document[]","options?: { ids?: string[] } | string[]","vectors: number[][]","query: number[]","k: number","filter?: object","Document","texts: string[]","metadatas: object[] | object","dbConfig: TigrisLibArgs","docs: Document[]"],"sources":["../../src/vectorstores/tigris.ts"],"sourcesContent":["import * as uuid from \"uuid\";\n\nimport type { EmbeddingsInterface } from \"@langchain/core/embeddings\";\nimport { VectorStore } from \"@langchain/core/vectorstores\";\nimport { Document } from \"@langchain/core/documents\";\n\n/**\n * Type definition for the arguments required to initialize a\n * TigrisVectorStore instance.\n */\nexport type TigrisLibArgs = {\n  // eslint-disable-next-line @typescript-eslint/no-explicit-any\n  index: any;\n};\n\n/**\n * Class for managing and operating vector search applications with\n * Tigris, an open-source Serverless NoSQL Database and Search Platform.\n */\nexport class TigrisVectorStore extends VectorStore {\n  // eslint-disable-next-line @typescript-eslint/no-explicit-any\n  index?: any;\n\n  _vectorstoreType(): string {\n    return \"tigris\";\n  }\n\n  constructor(embeddings: EmbeddingsInterface, args: TigrisLibArgs) {\n    super(embeddings, args);\n\n    this.embeddings = embeddings;\n    this.index = args.index;\n  }\n\n  /**\n   * Method to add an array of documents to the Tigris database.\n   * @param documents An array of Document instances to be added to the Tigris database.\n   * @param options Optional parameter that can either be an array of string IDs or an object with a property 'ids' that is an array of string IDs.\n   * @returns A Promise that resolves when the documents have been added to the Tigris database.\n   */\n  async addDocuments(\n    documents: Document[],\n    options?: { ids?: string[] } | string[]\n  ): Promise<void> {\n    const texts = documents.map(({ pageContent }) => pageContent);\n    await this.addVectors(\n      await this.embeddings.embedDocuments(texts),\n      documents,\n      options\n    );\n  }\n\n  /**\n   * Method to add vectors to the Tigris database.\n   * @param vectors An array of vectors to be added to the Tigris database.\n   * @param documents An array of Document instances corresponding to the vectors.\n   * @param options Optional parameter that can either be an array of string IDs or an object with a property 'ids' that is an array of string IDs.\n   * @returns A Promise that resolves when the vectors have been added to the Tigris database.\n   */\n  async addVectors(\n    vectors: number[][],\n    documents: Document[],\n    options?: { ids?: string[] } | string[]\n  ) {\n    if (vectors.length === 0) {\n      return;\n    }\n\n    if (vectors.length !== documents.length) {\n      throw new Error(`Vectors and metadatas must have the same length`);\n    }\n\n    const ids = Array.isArray(options) ? options : options?.ids;\n    const documentIds = ids == null ? documents.map(() => uuid.v4()) : ids;\n    await this.index?.addDocumentsWithVectors({\n      ids: documentIds,\n      embeddings: vectors,\n      documents: documents.map(({ metadata, pageContent }) => ({\n        content: pageContent,\n        metadata,\n      })),\n    });\n  }\n\n  /**\n   * Method to perform a similarity search in the Tigris database and return\n   * the k most similar vectors along with their similarity scores.\n   * @param query The query vector.\n   * @param k The number of most similar vectors to return.\n   * @param filter Optional filter object to apply during the search.\n   * @returns A Promise that resolves to an array of tuples, each containing a Document and its similarity score.\n   */\n  async similaritySearchVectorWithScore(\n    query: number[],\n    k: number,\n    filter?: object\n  ) {\n    const result = await this.index?.similaritySearchVectorWithScore({\n      query,\n      k,\n      filter,\n    });\n\n    if (!result) {\n      return [];\n    }\n\n    // eslint-disable-next-line @typescript-eslint/no-explicit-any\n    return result.map(([document, score]: [any, any]) => [\n      new Document({\n        pageContent: document.content,\n        metadata: document.metadata,\n      }),\n      score,\n    ]) as [Document, number][];\n  }\n\n  /**\n   * Static method to create a new instance of TigrisVectorStore from an\n   * array of texts.\n   * @param texts An array of texts to be converted into Document instances and added to the Tigris database.\n   * @param metadatas Either an array of metadata objects or a single metadata object to be associated with the texts.\n   * @param embeddings An instance of Embeddings to be used for embedding the texts.\n   * @param dbConfig An instance of TigrisLibArgs to be used for configuring the Tigris database.\n   * @returns A Promise that resolves to a new instance of TigrisVectorStore.\n   */\n  static async fromTexts(\n    texts: string[],\n    metadatas: object[] | object,\n    embeddings: EmbeddingsInterface,\n    dbConfig: TigrisLibArgs\n  ): Promise<TigrisVectorStore> {\n    const docs: Document[] = [];\n    for (let i = 0; i < texts.length; i += 1) {\n      const metadata = Array.isArray(metadatas) ? metadatas[i] : metadatas;\n      const newDoc = new Document({\n        pageContent: texts[i],\n        metadata,\n      });\n      docs.push(newDoc);\n    }\n    return TigrisVectorStore.fromDocuments(docs, embeddings, dbConfig);\n  }\n\n  /**\n   * Static method to create a new instance of TigrisVectorStore from an\n   * array of Document instances.\n   * @param docs An array of Document instances to be added to the Tigris database.\n   * @param embeddings An instance of Embeddings to be used for embedding the documents.\n   * @param dbConfig An instance of TigrisLibArgs to be used for configuring the Tigris database.\n   * @returns A Promise that resolves to a new instance of TigrisVectorStore.\n   */\n  static async fromDocuments(\n    docs: Document[],\n    embeddings: EmbeddingsInterface,\n    dbConfig: TigrisLibArgs\n  ): Promise<TigrisVectorStore> {\n    const instance = new this(embeddings, dbConfig);\n    await instance.addDocuments(docs);\n    return instance;\n  }\n\n  /**\n   * Static method to create a new instance of TigrisVectorStore from an\n   * existing index.\n   * @param embeddings An instance of Embeddings to be used for embedding the documents.\n   * @param dbConfig An instance of TigrisLibArgs to be used for configuring the Tigris database.\n   * @returns A Promise that resolves to a new instance of TigrisVectorStore.\n   */\n  static async fromExistingIndex(\n    embeddings: EmbeddingsInterface,\n    dbConfig: TigrisLibArgs\n  ): Promise<TigrisVectorStore> {\n    const instance = new this(embeddings, dbConfig);\n    return instance;\n  }\n}\n"],"mappings":";;;;;;;;;;;;AAmBA,IAAa,oBAAb,MAAa,0BAA0BA,0CAAY;CAEjD;CAEA,mBAA2B;AACzB,SAAO;CACR;CAED,YAAYC,YAAiCC,MAAqB;EAChE,MAAM,YAAY,KAAK;EAEvB,KAAK,aAAa;EAClB,KAAK,QAAQ,KAAK;CACnB;;;;;;;CAQD,MAAM,aACJC,WACAC,SACe;EACf,MAAM,QAAQ,UAAU,IAAI,CAAC,EAAE,aAAa,KAAK,YAAY;EAC7D,MAAM,KAAK,WACT,MAAM,KAAK,WAAW,eAAe,MAAM,EAC3C,WACA,QACD;CACF;;;;;;;;CASD,MAAM,WACJC,SACAF,WACAC,SACA;AACA,MAAI,QAAQ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