Example usage:

// Initialize the vector store
const vectorStore = new AzionVectorStore(embeddings, {
dbName: "mydb",
tableName: "documents"
});

// Setup database with hybrid search and metadata columns
await vectorStore.setupDatabase({
columns: ["topic", "language"],
mode: "hybrid"
});


// OR: Initialize using the static create method
const vectorStore = await AzionVectorStore.initialize(embeddings, {
dbName: "mydb",
tableName: "documents"
}, {
columns: ["topic", "language"],
mode: "hybrid"
});

By default, the columns are not expanded, meaning that the metadata is stored in a single column:

// Setup database with hybrid search and metadata columns
await vectorStore.setupDatabase({
columns: ["*"],
mode: "hybrid"
});

// Add documents to the vector store
await vectorStore.addDocuments([
new Document({
pageContent: "Australia is known for its unique wildlife",
metadata: { topic: "nature", language: "en" }
})
]);

// Perform similarity search
const results = await vectorStore.similaritySearch(
"coral reefs in Australia",
2, // Return top 2 results
{ filter: [{ operator: "=", column: "topic", string: "biology" }] } // Optional AzionFilter
);

// Perform full text search
const ftResults = await vectorStore.fullTextSearch(
"Sydney Opera House",
1, // Return top result
{ filter: [{ operator: "=", column: "language", string: "en" }] } // Optional AzionFilter
);

Hierarchy

  • VectorStore
    • AzionVectorStore

Constructors

Properties

FilterType: AzionFilter[]

Type declaration for filter type

dbName: string

Name of the database to use

embeddings: EmbeddingsInterface

Embeddings interface for generating vector embeddings from text queries, enabling vector-based similarity searches.

expandedMetadata: boolean

Whether the metadata is contained in a single column or multiple columns

tableName: string

Name of the main table to store vectors and documents

Methods

  • Adds documents to the vector store.

    Parameters

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

      The documents to add.

    Returns Promise<void>

    A promise that resolves when the documents have been added.

  • Adds vectors to the vector store.

    Parameters

    • vectors: number[][]

      The vectors to add.

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

      The documents associated with the vectors.

    Returns Promise<void>

    A promise that resolves with the IDs of the added vectors when the vectors have been added.

  • Creates a VectorStoreRetriever instance with flexible configuration options.

    Parameters

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

      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: AzionFilter[]

      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<AzionVectorStore>

    • 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 },
    });
  • Performs a full-text search on the vector store and returns the top 'k' similar documents.

    Parameters

    • query: string

      The query string to search for

    • options: FullTextSearchOptions

      The options for the full-text search, including: - kfts: The number of full-text search results to return - filter: Optional filters to apply to narrow down the search results - metadataItems: Optional metadata fields to include in the results

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

    A promise that resolves with the full-text search results when the search is complete.

  • Performs a hybrid search on the vector store and returns the top 'k' similar documents.

    Parameters

    • query: string

      The query string to search for

    • hybridSearchOptions: HybridSearchOptions

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

    A promise that resolves with the hybrid search results when the search is complete.

  • Performs a similarity search on the vector store and returns the top 'k' similar documents.

    Parameters

    • query: string

      The query string.

    • options: SimilaritySearchOptions

      The options for the similarity search, including: - kvector: The number of vector search results to return - filter: Optional filters to apply to the search - metadataItems: Optional metadata fields to include in results

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

    A promise that resolves with the similarity search results when the search is complete.

  • Deletes documents from the vector store.

    Parameters

    • ids: string[]

      The IDs of the documents to delete.

    Returns Promise<void>

    A promise that resolves when the documents have been deleted.

  • 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<AzionFilter[]>
    • _callbacks: undefined | Callbacks

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

    • List of documents selected by maximal marginal relevance.
  • Sets up the database and tables.

    Parameters

    • setupOptions: AzionSetupOptions

      The setup options:

      • columns: string[] - The metadata columns to add to the table
      • mode: "vector" | "hybrid" - The mode to use for the table. "vector" for vector search only, "hybrid" for vector and full-text search

    Returns Promise<void>

    A promise that resolves when the database and tables have been set up.

  • 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: AzionFilter[]

      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.

  • Performs a similarity search on the vector store and returns the top 'similarityK' similar documents.

    Parameters

    • vector: number[]

      The vector to search for.

    • k: number

      The number of documents to return.

    • Optionalfilter: AzionFilter[]

      Optional filters to apply to the search.

    • OptionalmetadataItems: string[]

      Optional metadata items to include in the search.

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

    A promise that resolves with the similarity search results when the search is complete.

  • 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: AzionFilter[]

      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 VectorStore instance from an array of documents, using the specified embeddings and database configuration.

    Subclasses must implement this method to define how documents are embedded and stored. Throws an error if not overridden.

    Parameters

    • _docs: DocumentInterface<Record<string, any>>[]

      Array of DocumentInterface instances representing the documents to be stored.

    • _embeddings: EmbeddingsInterface

      Instance of EmbeddingsInterface to embed the documents.

    • _dbConfig: Record<string, any>

      Database configuration settings.

    Returns Promise<VectorStore>

    A promise that resolves to a new VectorStore instance.

    Throws an error if this method is not overridden by a subclass.

  • Creates a VectorStore instance from an array of text strings and optional metadata, using the specified embeddings and database configuration.

    Subclasses must implement this method to define how text and metadata are embedded and stored in the vector store. Throws an error if not overridden.

    Parameters

    • _texts: string[]

      Array of strings representing the text documents to be stored.

    • _metadatas: object | object[]

      Metadata for the texts, either as an array (one for each text) or a single object (applied to all texts).

    • _embeddings: EmbeddingsInterface

      Instance of EmbeddingsInterface to embed the texts.

    • _dbConfig: Record<string, any>

      Database configuration settings.

    Returns Promise<VectorStore>

    A promise that resolves to a new VectorStore instance.

    Throws an error if this method is not overridden by a subclass.