{"version":3,"file":"vectorstores.cjs","names":["obj: Record<string, unknown>","flattenedObject: Record<string, unknown>","el: unknown","Document","VectorStore","embeddings: EmbeddingsInterface","args: WeaviateLibArgs","config: WeaviateLibArgs & { dimensions?: number }","configure","vectors: number[][]","documents: Document[]","options?: { ids?: string[] }","batch: DataObject<undefined>[]","params: {\n    ids?: string[];\n    filter?: FilterValue;\n  }","query: string","options?: HybridOptions<undefined>","query_vector: number[] | undefined","generate: GenerateOptions<undefined, GenerativeConfigRuntime | undefined>","options?: BaseHybridOptions<undefined>","query: number[]","k: number","filter?: FilterValue","documents: [Document, number, number, number[]][]","options: MaxMarginalRelevanceSearchOptions<this[\"FilterType\"]>","_callbacks?: undefined","queryEmbedding: number[]","allResults: [Document, number, number, number[]][]","texts: string[]","metadatas: object | object[]","docs: Document[]"],"sources":["../src/vectorstores.ts"],"sourcesContent":["import * as uuid from \"uuid\";\nimport {\n  HybridOptions,\n  CollectionConfigCreate,\n  configure,\n  type DataObject,\n  type FilterValue,\n  GenerateOptions,\n  GenerativeConfigRuntime,\n  Metadata,\n  Vectors,\n  WeaviateClient,\n  type WeaviateField,\n  BaseHybridOptions,\n  MetadataKeys,\n} from \"weaviate-client\";\nimport {\n  type MaxMarginalRelevanceSearchOptions,\n  VectorStore,\n} from \"@langchain/core/vectorstores\";\nimport type { EmbeddingsInterface } from \"@langchain/core/embeddings\";\nimport { Document } from \"@langchain/core/documents\";\nimport { maximalMarginalRelevance } from \"@langchain/core/utils/math\";\n\n// Note this function is not generic, it is designed specifically for Weaviate\n// https://weaviate.io/developers/weaviate/config-refs/datatypes#introduction\nexport const flattenObjectForWeaviate = (obj: Record<string, unknown>) => {\n  const flattenedObject: Record<string, unknown> = {};\n  for (const key in obj) {\n    if (!Object.hasOwn(obj, key)) {\n      continue;\n    }\n\n    // Replace any character that is not a letter, a number, or an underscore with '_'\n    const newKey = key.replace(/[^a-zA-Z0-9_]/g, \"_\");\n\n    const value = obj[key];\n    if (typeof value === \"object\" && !Array.isArray(value)) {\n      const recursiveResult = flattenObjectForWeaviate(\n        value as Record<string, unknown>\n      );\n      for (const deepKey in recursiveResult) {\n        if (Object.hasOwn(recursiveResult, deepKey)) {\n          // Replace any character in the deepKey that is not a letter, a number, or an underscore with '_'\n          const newDeepKey = deepKey.replace(/[^a-zA-Z0-9_]/g, \"_\");\n          flattenedObject[`${newKey}_${newDeepKey}`] = recursiveResult[deepKey];\n        }\n      }\n    } else if (Array.isArray(value)) {\n      if (value.length === 0) {\n        flattenedObject[newKey] = value;\n      } else if (\n        typeof value[0] !== \"object\" &&\n        value.every((el: unknown) => typeof el === typeof value[0])\n      ) {\n        // Weaviate only supports arrays of primitive types,\n        // where all elements are of the same type\n        flattenedObject[newKey] = value;\n      }\n    } else {\n      flattenedObject[newKey] = value;\n    }\n  }\n  return flattenedObject;\n};\n\n/**\n * Interface that defines the arguments required to create a new instance\n * of the `WeaviateStore` class. It includes the Weaviate client, the name\n * of the class in Weaviate, and optional keys for text and metadata.\n */\nexport interface WeaviateLibArgs {\n  client: WeaviateClient;\n  /**\n   * The name of the class in Weaviate. Must start with a capital letter.\n   */\n  indexName?: string;\n  textKey?: string;\n  metadataKeys?: string[];\n  tenant?: string;\n  schema?: CollectionConfigCreate;\n}\n\nexport class WeaviateDocument extends Document {\n  generated?: string;\n\n  additional: Partial<Metadata>;\n\n  vectors: Vectors;\n}\n\n/**\n * Class that extends the `VectorStore` base class. It provides methods to\n * interact with a Weaviate index, including adding vectors and documents,\n * deleting data, and performing similarity searches.\n */\nexport class WeaviateStore extends VectorStore {\n  declare FilterType: FilterValue;\n\n  private client: WeaviateClient;\n\n  private indexName: string;\n\n  private textKey: string;\n\n  private queryAttrs: string[];\n\n  private tenant?: string;\n\n  private schema?: CollectionConfigCreate;\n\n  _vectorstoreType(): string {\n    return \"weaviate\";\n  }\n\n  constructor(public embeddings: EmbeddingsInterface, args: WeaviateLibArgs) {\n    super(embeddings, args);\n\n    this.client = args.client;\n    this.indexName = args.indexName || args.schema?.name || \"\";\n    this.textKey = args.textKey || \"text\";\n    this.queryAttrs = [this.textKey];\n    this.tenant = args.tenant;\n    this.schema = args.schema;\n\n    if (args.metadataKeys) {\n      this.queryAttrs = [\n        ...new Set([\n          ...this.queryAttrs,\n          ...args.metadataKeys.filter((k) => {\n            // https://spec.graphql.org/June2018/#sec-Names\n            // queryAttrs need to be valid GraphQL Names\n            const keyIsValid = /^[_A-Za-z][_0-9A-Za-z]*$/.test(k);\n            if (!keyIsValid) {\n              console.warn(\n                `Skipping metadata key ${k} as it is not a valid GraphQL Name`\n              );\n            }\n            return keyIsValid;\n          }),\n        ]),\n      ];\n    }\n  }\n\n  static async initialize(\n    embeddings: EmbeddingsInterface,\n    config: WeaviateLibArgs & { dimensions?: number }\n  ): Promise<WeaviateStore> {\n    const weaviateStore = new this(embeddings, config);\n    const collection = await weaviateStore.client.collections.exists(\n      weaviateStore.indexName\n    );\n    if (!collection) {\n      if (weaviateStore.schema) {\n        await weaviateStore.client.collections.create(weaviateStore.schema);\n      } else {\n        if (config.tenant) {\n          await weaviateStore.client.collections.create({\n            name: weaviateStore.indexName,\n            multiTenancy: configure.multiTenancy({\n              enabled: true,\n              autoTenantCreation: true,\n            }),\n          });\n        } else {\n          await weaviateStore.client.collections.create({\n            name: weaviateStore.indexName,\n          });\n        }\n      }\n    }\n    return weaviateStore;\n  }\n\n  /**\n   * Method to add vectors and corresponding documents to the Weaviate\n   * index.\n   * @param vectors Array of vectors to be added.\n   * @param documents Array of documents corresponding to the vectors.\n   * @param options Optional parameter that can include specific IDs for the documents.\n   * @returns An array of document IDs.\n   */\n  async addVectors(\n    vectors: number[][],\n    documents: Document[],\n    options?: { ids?: string[] }\n  ) {\n    const documentIds = options?.ids ?? documents.map((_) => uuid.v4());\n    const batch: DataObject<undefined>[] = documents.map((document, index) => {\n      if (Object.hasOwn(document.metadata, \"id\"))\n        throw new Error(\n          \"Document inserted to Weaviate vectorstore should not have `id` in their metadata.\"\n        );\n      const flattenedMetadata = flattenObjectForWeaviate(\n        document.metadata\n      ) as Record<string, WeaviateField>;\n      return {\n        id: documentIds[index],\n        vectors: vectors[index],\n        references: {},\n        properties: {\n          [this.textKey]: document.pageContent,\n          ...flattenedMetadata,\n        },\n      };\n    });\n\n    try {\n      const collection = this.client.collections.get(this.indexName);\n      let response;\n      if (this.tenant) {\n        response = await collection\n          .withTenant(this.tenant)\n          .data.insertMany(batch);\n      } else {\n        response = await collection.data.insertMany(batch);\n      }\n      console.log(\n        `Successfully imported batch of ${\n          Object.values(response.uuids).length\n        } items`\n      );\n      if (response.hasErrors) {\n        console.log(\"this the error\", response.errors);\n        throw new Error(\"Error in batch import!\");\n      }\n      return Object.values(response.uuids);\n    } catch (error) {\n      console.error(\"Error importing batch:\", error);\n      throw error;\n    }\n  }\n\n  /**\n   * Method to add documents to the Weaviate index. It first generates\n   * vectors for the documents using the embeddings, then adds the vectors\n   * and documents to the index.\n   * @param documents Array of documents to be added.\n   * @param options Optional parameter that can include specific IDs for the documents.\n   * @returns An array of document IDs.\n   */\n  async addDocuments(documents: Document[], options?: { ids?: string[] }) {\n    return this.addVectors(\n      await this.embeddings.embedDocuments(documents.map((d) => d.pageContent)),\n      documents,\n      options\n    );\n  }\n\n  /**\n   * Method to delete data from the Weaviate index. It can delete data based\n   * on specific IDs or a filter.\n   * @param params Object that includes either an array of IDs or a filter for the data to be deleted.\n   * @returns Promise that resolves when the deletion is complete.\n   */\n  async delete(params: {\n    ids?: string[];\n    filter?: FilterValue;\n  }): Promise<void> {\n    const { ids, filter } = params;\n    const collection = this.client.collections.get(this.indexName);\n    if (ids && ids.length > 0) {\n      if (this.tenant) {\n        await collection\n          .withTenant(this.tenant)\n          .data.deleteMany(collection.filter.byId().containsAny(ids));\n      } else {\n        await collection.data.deleteMany(\n          collection.filter.byId().containsAny(ids)\n        );\n      }\n    } else if (filter) {\n      if (this.tenant) {\n        await collection.withTenant(this.tenant).data.deleteMany(filter);\n      } else {\n        await collection.data.deleteMany(filter);\n      }\n    } else {\n      throw new Error(\n        `This method requires either \"ids\" or \"filter\" to be set in the input object`\n      );\n    }\n  }\n\n  /**\n   * Hybrid search combines the results of a vector search and a\n   * keyword (BM25F) search by fusing the two result sets.\n   * @param query The query to search for.\n   * @param options available options for the search. Check docs for complete list\n   * @returns Promise that resolves the result of the search within the fetched collection.\n   */\n  async hybridSearch(\n    query: string,\n    options?: HybridOptions<undefined>\n  ): Promise<Document[]> {\n    const collection = this.client.collections.get(this.indexName);\n    let query_vector: number[] | undefined;\n    if (!options?.vector) {\n      query_vector = await this.embeddings.embedQuery(query);\n    }\n\n    const options_with_vector = {\n      ...options,\n      vector: options?.vector || query_vector,\n      returnMetadata: [\n        \"score\",\n        ...((options?.returnMetadata as MetadataKeys) || []),\n      ] as MetadataKeys,\n    };\n    let result;\n    if (this.tenant) {\n      result = await collection.withTenant(this.tenant).query.hybrid(query, {\n        ...options_with_vector,\n      });\n    } else {\n      result = await collection.query.hybrid(query, {\n        ...options_with_vector,\n      });\n    }\n    const documents: Document[] = [];\n\n    for (const data of result.objects) {\n      const { properties = {}, metadata = {} } = data ?? {};\n      const { [this.textKey]: text, ...rest } = properties;\n\n      documents.push(\n        new Document({\n          pageContent: String(text ?? \"\"),\n          metadata: {\n            ...rest,\n            ...metadata,\n          },\n          id: data.uuid,\n        })\n      );\n    }\n    return documents;\n  }\n\n  /**\n   * Weaviate's Retrieval Augmented Generation (RAG) combines information retrieval\n   * with generative AI models. It first performs the search, then passes both\n   * the search results and your prompt to a generative AI model before returning the generated response.\n   * @param query The query to search for.\n   * @param generate available options for the generation. Check docs for complete list\n   * @param options available options for performing the hybrid search\n   * @returns Promise that resolves the result of the search including the generated data.\n   */\n  async generate(\n    query: string,\n    generate: GenerateOptions<undefined, GenerativeConfigRuntime | undefined>,\n    options?: BaseHybridOptions<undefined>\n  ): Promise<WeaviateDocument[]> {\n    const collection = this.client.collections.get(this.indexName);\n    let result;\n    if (this.tenant) {\n      result = await collection\n        .withTenant(this.tenant)\n        .generate.hybrid(\n          query,\n          { ...(generate || {}) },\n          { ...(options || {}) }\n        );\n    } else {\n      result = await collection.generate.hybrid(\n        query,\n        { ...(generate || {}) },\n        { ...(options || {}) }\n      );\n    }\n    const documents = [];\n    for (const data of result.objects) {\n      const { properties = {} } = data ?? {};\n      const { [this.textKey]: text, ...rest } = properties;\n\n      const doc = new WeaviateDocument({\n        pageContent: String(text ?? \"\"),\n        metadata: {\n          ...rest,\n        },\n        id: data.uuid,\n      });\n\n      doc.generated = data.generative?.text;\n      doc.vectors = data.vectors;\n      doc.additional = data.metadata || {};\n\n      documents.push(doc);\n    }\n    return documents;\n  }\n\n  /**\n   * Method to perform a similarity search on the stored vectors in the\n   * Weaviate index. It returns the top k most similar documents and their\n   * similarity scores.\n   * @param query The query vector.\n   * @param k The number of most similar documents to return.\n   * @param filter Optional filter to apply to the search.\n   * @returns An array of tuples, where each tuple contains a document and its similarity score.\n   */\n  async similaritySearchVectorWithScore(\n    query: number[],\n    k: number,\n    filter?: FilterValue\n  ): Promise<[Document, number][]> {\n    const resultsWithEmbedding =\n      await this.similaritySearchVectorWithScoreAndEmbedding(query, k, filter);\n    return resultsWithEmbedding.map(([document, score, _embedding]) => [\n      document,\n      score,\n    ]);\n  }\n\n  /**\n   * Method to perform a similarity search on the stored vectors in the\n   * Weaviate index. It returns the top k most similar documents, their\n   * similarity scores and embedding vectors.\n   * @param query The query vector.\n   * @param k The number of most similar documents to return.\n   * @param filter Optional filter to apply to the search.\n   * @returns An array of tuples, where each tuple contains a document, its similarity score and its embedding vector.\n   */\n  async similaritySearchVectorWithScoreAndEmbedding(\n    query: number[],\n    k: number,\n    filter?: FilterValue\n  ): Promise<[Document, number, number, number[]][]> {\n    try {\n      const collection = this.client.collections.get(this.indexName);\n      // define query attributes to return\n      // if no queryAttrs, show all properties\n      const queryAttrs =\n        this.queryAttrs.length > 1 ? this.queryAttrs : undefined;\n      let result;\n      if (this.tenant) {\n        result = await collection\n          .withTenant(this.tenant)\n          .query.nearVector(query, {\n            filters: filter,\n            limit: k,\n            returnMetadata: [\"distance\", \"score\"],\n            returnProperties: queryAttrs,\n          });\n      } else {\n        result = await collection.query.nearVector(query, {\n          filters: filter,\n          limit: k,\n          includeVector: true,\n          returnMetadata: [\"distance\", \"score\"],\n          returnProperties: queryAttrs,\n        });\n      }\n\n      const documents: [Document, number, number, number[]][] = [];\n\n      for (const data of result.objects) {\n        const { properties = {}, metadata = {} } = data ?? {};\n        const { [this.textKey]: text, ...rest } = properties;\n\n        documents.push([\n          new Document({\n            pageContent: String(text ?? \"\"),\n            metadata: {\n              ...rest,\n            },\n            id: data.uuid,\n          }),\n          metadata?.distance ?? 0,\n          metadata?.score ?? 0,\n          Object.values(data.vectors)[0],\n        ]);\n      }\n      return documents;\n    } catch (e) {\n      throw Error(`Error in similaritySearch ${e}`);\n    }\n  }\n\n  /**\n   * Return documents selected using the maximal marginal relevance.\n   * Maximal marginal relevance optimizes for similarity to the query AND diversity\n   * among selected documents.\n   *\n   * @param {string} query - Text to look up documents similar to.\n   * @param {number} options.k - Number of documents to return.\n   * @param {number} options.fetchK - Number of documents to fetch before passing to the MMR algorithm.\n   * @param {number} options.lambda - Number between 0 and 1 that determines the degree of diversity among the results,\n   *                 where 0 corresponds to maximum diversity and 1 to minimum diversity.\n   * @param {this[\"FilterType\"]} options.filter - Optional filter\n   * @param _callbacks\n   *\n   * @returns {Promise<Document[]>} - List of documents selected by maximal marginal relevance.\n   */\n  override async maxMarginalRelevanceSearch(\n    query: string,\n    options: MaxMarginalRelevanceSearchOptions<this[\"FilterType\"]>,\n    _callbacks?: undefined\n  ): Promise<Document[]> {\n    const { k, fetchK = 20, lambda = 0.5, filter } = options;\n    const queryEmbedding: number[] = await this.embeddings.embedQuery(query);\n    const allResults: [Document, number, number, number[]][] =\n      await this.similaritySearchVectorWithScoreAndEmbedding(\n        queryEmbedding,\n        fetchK,\n        filter\n      );\n    const embeddingList = allResults.map(\n      ([_doc, _distance, _score, embedding]) => embedding\n    );\n    const mmrIndexes = maximalMarginalRelevance(\n      queryEmbedding,\n      embeddingList,\n      lambda,\n      k\n    );\n    return mmrIndexes\n      .filter((idx) => idx !== -1)\n      .map((idx) => allResults[idx][0]);\n  }\n\n  /**\n   * Static method to create a new `WeaviateStore` instance from a list of\n   * texts. It first creates documents from the texts and metadata, then\n   * adds the documents to the Weaviate index.\n   * @param texts Array of texts.\n   * @param metadatas Metadata for the texts. Can be a single object or an array of objects.\n   * @param embeddings Embeddings to be used for the texts.\n   * @param args Arguments required to create a new `WeaviateStore` instance.\n   * @returns A new `WeaviateStore` instance.\n   */\n  static fromTexts(\n    texts: string[],\n    metadatas: object | object[],\n    embeddings: EmbeddingsInterface,\n    args: WeaviateLibArgs\n  ): Promise<WeaviateStore> {\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 WeaviateStore.fromDocuments(docs, embeddings, args);\n  }\n\n  /**\n   * Static method to create a new `WeaviateStore` instance from a list of\n   * documents. It adds the documents to the Weaviate index.\n   * @param docs Array of documents.\n   * @param embeddings Embeddings to be used for the documents.\n   * @param args Arguments required to create a new `WeaviateStore` instance.\n   * @returns A new `WeaviateStore` instance.\n   */\n  static async fromDocuments(\n    docs: Document[],\n    embeddings: EmbeddingsInterface,\n    args: WeaviateLibArgs\n  ): Promise<WeaviateStore> {\n    const instance = await this.initialize(embeddings, args);\n    await instance.addDocuments(docs);\n    return instance;\n  }\n\n  /**\n   * Static method to create a new `WeaviateStore` instance from an existing\n   * Weaviate index.\n   * @param embeddings Embeddings to be used for the Weaviate index.\n   * @param args Arguments required to create a new `WeaviateStore` instance.\n   * @returns A new `WeaviateStore` instance.\n   */\n  static async fromExistingIndex(\n    embeddings: EmbeddingsInterface,\n    args: WeaviateLibArgs\n  ): Promise<WeaviateStore> {\n    return new this(embeddings, args);\n  }\n}\n"],"m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