langchain.js
    Preparing search index...

    A class that extends BaseTranslator to translate structured queries into functional filters.

    const functionalTranslator = new FunctionalTranslator();
    const relevantDocuments = await functionalTranslator.getRelevantDocuments(
    "Which movies are rated higher than 8.5?",
    );

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    allowedComparators: Comparator[] = ...
    allowedOperators: Operator[] = ...
    VisitComparisonOutput: FunctionFilter
    VisitOperationOutput: FunctionFilter
    VisitStructuredQueryOutput: { filter: FunctionFilter } | { [k: string]: never }

    Methods

    • Formats a given function (either an operator or a comparator) into a string.

      Returns string

      Formatted string representation of the function.

    • Returns the allowed comparators for a given data type.

      Parameters

      • inputType: string

      Returns Comparator[]

      An array of allowed comparators for the input data type.

    • Returns a function that performs a comparison based on the provided comparator.

      Type Parameters

      Parameters

      • comparator: Comparator

        The comparator to base the comparison function on.

      Returns (a: string | number, b: ValueType[C]) => boolean

      A function that takes two arguments and returns a boolean based on the comparison.

    • Returns a function that performs an operation based on the provided operator.

      Parameters

      • operator: Operator

        The operator to base the operation function on.

      Returns (a: boolean, b: boolean) => boolean

      A function that takes two boolean arguments and returns a boolean based on the operation.

    • Merges two filters into one, based on the specified merge type.

      Parameters

      • defaultFilter: FunctionFilter

        The default filter function.

      • generatedFilter: FunctionFilter

        The generated filter function.

      • mergeType: string = "and"

        The type of merge to perform. Can be 'and', 'or', or 'replace'. Default is 'and'.

      Returns undefined | FunctionFilter

      A function that takes a Document as an argument and returns a boolean based on the merged filters, or undefined if both filters are empty.

    • Visits the comparison part of a structured query and translates it into a functional filter.

      Parameters

      • comparison: Comparison<string | number | boolean>

        The comparison part of a structured query.

      Returns FunctionFilter

      A function that takes a Document as an argument and returns a boolean based on the comparison.

    • Visits the operation part of a structured query and translates it into a functional filter.

      Parameters

      • operation: Operation

        The operation part of a structured query.

      Returns FunctionFilter

      A function that takes a Document as an argument and returns a boolean based on the operation.

    • Visits a structured query and translates it into a functional filter.

      Parameters

      Returns { filter: FunctionFilter } | { [k: string]: never }

      An object containing a filter property, which is a function that takes a Document as an argument and returns a boolean based on the structured query.