langchain.js
    Preparing search index...

    Example usage:

    // Initialize embeddings and chat model
    const embeddings = new OpenAIEmbeddings();
    const chatModel = new ChatOpenAI({ model: "gpt-4o-mini" });

    // Create retriever with hybrid search
    const retriever = new AzionRetriever(embeddings, chatModel, {
    searchType: 'hybrid',
    similarityK: 3,
    ftsK: 2,
    dbName: 'my_docs',
    metadataItems: ['category', 'author'],
    vectorTable: 'documents',
    ftsTable: 'documents_fts',
    filters: [
    { operator: '=', column: 'status', value: 'published' }
    ]
    });

    // Retrieve relevant documents
    const docs = await retriever.invoke(
    "What are coral reefs in Australia?"
    );

    // Create retriever with similarity search only
    const simRetriever = new AzionRetriever(embeddings, chatModel, {
    searchType: 'similarity',
    similarityK: 5,
    dbName: 'my_docs',
    vectorTable: 'documents'
    });

    // Customize entity extraction prompt
    const customRetriever = new AzionRetriever(embeddings, chatModel, {
    searchType: 'hybrid',
    similarityK: 3,
    ftsK: 2,
    dbName: 'my_docs',
    promptEntityExtractor: "Extract key entities from: {{query}}"
    });

    Hierarchy (View Summary)

    Index

    Constructors

    • Parameters

      Returns AzionRetriever

    Properties

    dbName: string

    Name of the database to search

    embeddings: EmbeddingsInterface

    Interface for generating embeddings from text

    entityExtractor?: any

    Optional ChatModel used to extract entities from queries

    expandedMetadata: boolean

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

    filters: AzionFilter[]

    Array of filters to apply to search results

    ftsK: number

    Number of results to return from full text search. Minimum is 1.

    ftsTable: string

    Name of table containing documents for full text search

    lc_namespace: string[] = ...

    Namespace for the retriever in LangChain

    metadataItems?: string[]

    Optional metadata columns to include in results

    promptEntityExtractor: string

    Prompt template for entity extraction

    searchType?: "hybrid" | "similarity"

    Type of search to perform - either hybrid (combining vector + FTS) or similarity only

    similarityK: number

    Number of results to return from similarity search. Minimum is 1.

    vectorTable: string

    Name of table containing vector embeddings for similarity search

    Methods

    • Performs the selected search and returns the documents retrieved.

      Parameters

      • query: string

        The user query

      Returns Promise<Document[]>

      A promise that resolves with the completion of the search results.

    • Converts a query to a FTS query.

      Parameters

      • query: string

        The user query

      Returns string

      The converted FTS query

    • Extracts entities from a user query using the entityExtractor model.

      Parameters

      • query: string

        The user query

      Returns Promise<string>

      A promise that resolves with the extracted entities when the extraction is complete.

    • Generates a string of filters for the SQL query.

      Parameters

      • filters: AzionFilter[]

        The filters to apply to the search.

      Returns string

      A string of filters for the SQL query.

    • Generates the metadata string for the SQL query.

      Returns string

      The metadata string.

    • Generates SQL queries for full-text search and similarity search.

      Parameters

      • embeddedQuery: number[]

        The embedded query vector.

      • queryEntities: string

        The entities extracted from the query for full-text search.

      • metadata: string

        Additional metadata columns to be included in the results.

      Returns { ftsQuery: string; similarityQuery: string }

      An object containing the FTS query and similarity query strings.

    • Generates the SQL statements for the similarity search and full-text search.

      Parameters

      • query: string

        The user query.

      Returns Promise<string[]>

      An array of SQL statements.

    • Performs a hybrid search on the vector store, using cosine similarity and FTS search, and returns the top 'similarityK' + 'ftsK' similar documents.

      Parameters

      • query: string

        The user query

      Returns Promise<[Document][]>

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

    • Maps search results to Document objects.

      Parameters

      • searches: SearchEmbeddingsResponse[]

        An array of SearchEmbeddingsResponse objects.

      Returns [Document][]

      An array of tuples, each containing a single Document object.

    • Generates an error document based on the provided error information

      Parameters

      • error: undefined | { message: string; operation: string }

        The error object containing details about the issue

      Returns Error

      A promise that resolves to an array containing a single Document representing the error

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

      Parameters

      • query: string

        The query string.

      Returns Promise<[Document][]>

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

    • Returns string