Ask data in your table a question

https://{your-workspace-slug}.{region}.xata.sh/db/db_branch_name/tables/table_name/ask

Ask your table a question and have Xata answer.

Expected parameters

NameDescriptionInRequiredSchema
db_branch_name

The DBBranchName matches the pattern {db_name}:{branch_name}.

pathstring
table_name

The Table name

pathstring

Ask Your Table a Question

POST
https://{your-workspace-slug}.{region}.xata.sh/db/db_branch_name/tables/table_name/ask

Ask your table a question. If the Accept header is set to text/event-stream, Xata will stream the results back as SSE's.

Request Body Type Definition

type AskTable = {
    /**
     * The question you'd like to ask.
     *
     * @minLength 3
     */
    question: string;
    /**
     * The type of search to use. If set to `keyword` (the default), the search can be configured by passing
     * a `search` object with the following fields. For more details about each, see the Search endpoint documentation.
     * All fields are optional.
     *   * fuzziness  - typo tolerance
     *   * target - columns to search into, and weights.
     *   * prefix - prefix search type.
     *   * filter - pre-filter before searching.
     *   * boosters - control relevancy.
     * If set to `vector`, a `vectorSearch` object must be passed, with the following parameters. For more details, see the Vector
     * Search endpoint documentation. The `column` and `contentColumn` parameters are required.
     *   * column - the vector column containing the embeddings.
     *   * contentColumn - the column that contains the text from which the embeddings where computed.
     *   * filter - pre-filter before searching.
     *
     * @default keyword
     */
    searchType?: "keyword" | "vector";
    search?: {
        fuzziness?: FuzzinessExpression;
        target?: TargetExpression;
        prefix?: PrefixExpression;
        filter?: FilterExpression;
        boosters?: BoosterExpression[];
    };
    vectorSearch?: {
        /**
         * The column to use for vector search. It must be of type `vector`.
         */
        column: string;
        /**
         * The column containing the text for vector search. Must be of type `text`.
         */
        contentColumn: string;
        filter?: FilterExpression;
    };
    rules?: string[];
};
 
/**
 * Maximum [Levenshtein distance](https://en.wikipedia.org/wiki/Levenshtein_distance) for the search terms. The Levenshtein
 * distance is the number of one character changes needed to make two strings equal. The default is 1, meaning that single
 * character typos per word are tolerated by search. You can set it to 0 to remove the typo tolerance or set it to 2
 * to allow two typos in a word.
 * 
 * @default 1
 * @maximum 2
 * @minimum 0
 */
type FuzzinessExpression = number;
 
/**
 * The target expression is used to filter the search results by the target columns.
 */
type TargetExpression = (string | {
    /**
     * The name of the column.
     */
    column: string;
    /**
     * The weight of the column.
     *
     * @default 1
     * @maximum 10
     * @minimum 1
     */
    weight?: number;
})[];
 
/**
 * If the prefix type is set to "disabled" (the default), the search only matches full words. If the prefix type is set to "phrase", the search will return results that match prefixes of the search phrase.
 */
type PrefixExpression = "phrase" | "disabled";
 
/**
 * @minProperties 1
 */
type FilterExpression = {
    $exists?: string;
    $existsNot?: string;
    $any?: FilterList;
    $all?: FilterList;
    $none?: FilterList;
    $not?: FilterList;
} & {
    [key: string]: FilterColumn;
};
 
/**
 * Booster Expression
 */
type BoosterExpression = {
    valueBooster?: ValueBooster;
} | {
    numericBooster?: NumericBooster;
} | {
    dateBooster?: DateBooster;
};
 
type FilterList = FilterExpression | FilterExpression[];
 
type FilterColumn = FilterColumnIncludes | FilterPredicate | FilterList;
 
/**
 * Boost records with a particular value for a column.
 */
type ValueBooster = {
    /**
     * The column in which to look for the value.
     */
    column: string;
    /**
     * The exact value to boost.
     */
    value: string | number | boolean;
    /**
     * The factor with which to multiply the added boost.
     */
    factor: number;
    /**
     * Only apply this booster to the records for which the provided filter matches.
     */
    ifMatchesFilter?: FilterExpression;
};
 
/**
 * Boost records based on the value of a numeric column.
 */
type NumericBooster = {
    /**
     * The column in which to look for the value.
     */
    column: string;
    /**
     * The factor with which to multiply the value of the column before adding it to the item score.
     */
    factor: number;
    /**
     * Modifier to be applied to the column value, before being multiplied with the factor. The possible values are:
     *   - none (default).
     *   - log: common logarithm (base 10)
     *   - log1p: add 1 then take the common logarithm. This ensures that the value is positive if the
     *     value is between 0 and 1.
     *   - ln: natural logarithm (base e)
     *   - ln1p: add 1 then take the natural logarithm. This ensures that the value is positive if the
     *     value is between 0 and 1.
     *   - square: raise the value to the power of two.
     *   - sqrt: take the square root of the value.
     *   - reciprocal: reciprocate the value (if the value is `x`, the reciprocal is `1/x`).
     */
    modifier?: "none" | "log" | "log1p" | "ln" | "ln1p" | "square" | "sqrt" | "reciprocal";
    /**
     * Only apply this booster to the records for which the provided filter matches.
     */
    ifMatchesFilter?: FilterExpression;
};
 
/**
 * Boost records based on the value of a datetime column. It is configured via "origin", "scale", and "decay". The further away from the "origin",
 * the more the score is decayed. The decay function uses an exponential function. For example if origin is "now", and scale is 10 days and decay is 0.5, it
 * should be interpreted as: a record with a date 10 days before/after origin will be boosted 2 times less than a record with the date at origin.
 * The result of the exponential function is a boost between 0 and 1. The "factor" allows you to control how impactful this boost is, by multiplying it with a given value.
 */
type DateBooster = {
    /**
     * The column in which to look for the value.
     */
    column: string;
    /**
     * The datetime (formatted as RFC3339) from where to apply the score decay function. The maximum boost will be applied for records with values at this time.
     * If it is not specified, the current date and time is used.
     */
    origin?: string;
    /**
     * The duration at which distance from origin the score is decayed with factor, using an exponential function. It is formatted as number + units, for example: `5d`, `20m`, `10s`.
     *
     * @pattern ^(\d+)(d|h|m|s|ms)$
     */
    scale: string;
    /**
     * The decay factor to expect at "scale" distance from the "origin".
     */
    decay: number;
    /**
     * The factor with which to multiply the added boost.
     *
     * @minimum 0
     */
    factor?: number;
    /**
     * Only apply this booster to the records for which the provided filter matches.
     */
    ifMatchesFilter?: FilterExpression;
};
 
/**
 * @maxProperties 1
 * @minProperties 1
 */
type FilterColumnIncludes = {
    $includes?: FilterPredicate;
    $includesAny?: FilterPredicate;
    $includesAll?: FilterPredicate;
    $includesNone?: FilterPredicate;
};
 
type FilterPredicate = FilterValue | FilterPredicate[] | FilterPredicateOp | FilterPredicateRangeOp;
 
type FilterValue = number | string | boolean;
 
/**
 * @maxProperties 1
 * @minProperties 1
 */
type FilterPredicateOp = {
    $any?: FilterPredicate[];
    $all?: FilterPredicate[];
    $none?: FilterPredicate | FilterPredicate[];
    $not?: FilterPredicate | FilterPredicate[];
    $is?: FilterValue | FilterValue[];
    $isNot?: FilterValue | FilterValue[];
    $lt?: FilterRangeValue;
    $le?: FilterRangeValue;
    $gt?: FilterRangeValue;
    $ge?: FilterRangeValue;
    $contains?: string;
    $startsWith?: string;
    $endsWith?: string;
    $pattern?: string;
};
 
/**
 * @maxProperties 2
 * @minProperties 2
 */
type FilterPredicateRangeOp = {
    $lt?: FilterRangeValue;
    $le?: FilterRangeValue;
    $gt?: FilterRangeValue;
    $ge?: FilterRangeValue;
};
 
type FilterRangeValue = number | string;

Responses

type AskTable = {
    /**
     * The answer to the input question
     */
    answer: string;
    /**
     * The session ID for the chat session.
     */
    sessionId: string;
};