Class for interacting with a Milvus database. Extends the VectorStore class.

Hierarchy

  • VectorStore
    • Milvus

Constructors

Properties

FilterType: string
autoId?: boolean
client: MilvusClient
collectionName: string
embeddings: EmbeddingsInterface
fields: string[]
indexCreateParams: IndexCreateOptions
indexSearchParams: keyValueObj
numDimensions?: number
partitionKey?: string
partitionKeyMaxLength?: number
partitionName?: string
primaryField: string
textField: string
textFieldMaxLength: number
vectorField: string

Methods

  • Adds documents to the Milvus database.

    Parameters

    • documents: Document<Record<string, any>>[]

      Array of Document instances to be added to the database.

    • Optionaloptions: {
          ids?: string[];
      }

      Optional parameter that can include specific IDs for the documents.

      • Optionalids?: string[]

    Returns Promise<void>

    Promise resolving to void.

  • Adds vectors to the Milvus database.

    Parameters

    • vectors: number[][]

      Array of vectors to be added to the database.

    • documents: Document<Record<string, any>>[]

      Array of Document instances associated with the vectors.

    • Optionaloptions: {
          ids?: string[];
      }

      Optional parameter that can include specific IDs for the documents.

      • Optionalids?: string[]

    Returns Promise<void>

    Promise resolving to void.

  • Creates a VectorStoreRetriever instance with flexible configuration options.

    Parameters

    • OptionalkOrFields: number | Partial<VectorStoreRetrieverInput<Milvus>>

      If a number is provided, it sets the k parameter (number of items to retrieve).

      • If an object is provided, it should contain various configuration options.
    • Optionalfilter: string

      Optional filter criteria to limit the items retrieved based on the specified filter type.

    • Optionalcallbacks: Callbacks

      Optional callbacks that may be triggered at specific stages of the retrieval process.

    • Optionaltags: string[]

      Tags to categorize or label the VectorStoreRetriever. Defaults to an empty array if not provided.

    • Optionalmetadata: Record<string, unknown>

      Additional metadata as key-value pairs to add contextual information for the retrieval process.

    • Optionalverbose: boolean

      If true, enables detailed logging for the retrieval process. Defaults to false.

    Returns VectorStoreRetriever<Milvus>

    • A configured VectorStoreRetriever instance based on the provided parameters.

    Basic usage with a k value:

    const retriever = myVectorStore.asRetriever(5);
    

    Usage with a configuration object:

    const retriever = myVectorStore.asRetriever({
    k: 10,
    filter: myFilter,
    tags: ['example', 'test'],
    verbose: true,
    searchType: 'mmr',
    searchKwargs: { alpha: 0.5 },
    });
  • Creates a collection in the Milvus database.

    Parameters

    • vectors: number[][]

      Array of vectors to be added to the new collection.

    • documents: Document<Record<string, any>>[]

      Array of Document instances to be added to the new collection.

    Returns Promise<void>

    Promise resolving to void.

  • Deletes data from the Milvus database.

    Parameters

    • params: {
          filter?: string;
          ids?: string[];
      }

      Object containing a filter to apply to the deletion.

      • Optionalfilter?: string
      • Optionalids?: string[]

    Returns Promise<void>

    Promise resolving to void.

  • Ensures that a collection exists in the Milvus database.

    Parameters

    • Optionalvectors: number[][]

      Optional array of vectors to be used if a new collection needs to be created.

    • Optionaldocuments: Document<Record<string, any>>[]

      Optional array of Document instances to be used if a new collection needs to be created.

    Returns Promise<void>

    Promise resolving to void.

  • Return documents selected using the maximal marginal relevance. Maximal marginal relevance optimizes for similarity to the query AND diversity among selected documents.

    Parameters

    • query: string

      Text to look up documents similar to.

    • options: MaxMarginalRelevanceSearchOptions<string>
    • _callbacks: undefined | Callbacks

    Returns Promise<DocumentInterface<Record<string, any>>[]>

    • List of documents selected by maximal marginal relevance.
  • Searches for documents similar to a text query by embedding the query and performing a similarity search on the resulting vector.

    Parameters

    • query: string

      Text query for finding similar documents.

    • Optionalk: number

      Number of similar results to return. Defaults to 4.

    • Optionalfilter: string

      Optional filter based on FilterType.

    • Optional_callbacks: Callbacks

      Optional callbacks for monitoring search progress

    Returns Promise<DocumentInterface<Record<string, any>>[]>

    A promise resolving to an array of DocumentInterface instances representing similar documents.

  • Searches for vectors in the Milvus database that are similar to a given vector.

    Parameters

    • query: number[]

      Vector to compare with the vectors in the database.

    • k: number

      Number of similar vectors to return.

    • Optionalfilter: string

      Optional filter to apply to the search.

    Returns Promise<[Document<Record<string, any>>, number][]>

    Promise resolving to an array of tuples, each containing a Document instance and a similarity score.

  • Searches for documents similar to a text query by embedding the query, and returns results with similarity scores.

    Parameters

    • query: string

      Text query for finding similar documents.

    • Optionalk: number

      Number of similar results to return. Defaults to 4.

    • Optionalfilter: string

      Optional filter based on FilterType.

    • Optional_callbacks: Callbacks

      Optional callbacks for monitoring search progress

    Returns Promise<[DocumentInterface<Record<string, any>>, number][]>

    A promise resolving to an array of tuples, each containing a document and its similarity score.

  • Returns Serialized

  • Creates a Milvus instance from a set of Document instances.

    Parameters

    • docs: Document<Record<string, any>>[]

      Array of Document instances to be added to the database.

    • embeddings: EmbeddingsInterface

      Embeddings instance used to generate vector embeddings for the documents.

    • OptionaldbConfig: MilvusLibArgs

      Optional configuration for the Milvus database.

    Returns Promise<Milvus>

    Promise resolving to a new Milvus instance.

  • Creates a Milvus instance from an existing collection in the Milvus database.

    Parameters

    • embeddings: EmbeddingsInterface

      Embeddings instance used to generate vector embeddings for the documents in the collection.

    • dbConfig: MilvusLibArgs

      Configuration for the Milvus database.

    Returns Promise<Milvus>

    Promise resolving to a new Milvus instance.

  • Creates a Milvus instance from a set of texts and their associated metadata.

    Parameters

    • texts: string[]

      Array of texts to be added to the database.

    • metadatas: object | object[]

      Array of metadata objects associated with the texts.

    • embeddings: EmbeddingsInterface

      Embeddings instance used to generate vector embeddings for the texts.

    • OptionaldbConfig: MilvusLibArgs

      Optional configuration for the Milvus database.

    Returns Promise<Milvus>

    Promise resolving to a new Milvus instance.