Skip to content
Browse documentation
API Reference

AVA API

Method signatures, complete input tables, defaults, and returned values.

Use this reference to look up inputs after following the quickstart. Types and defaults below follow the current src/ava.ts implementation. All instance methods listed here are asynchronous.

Constructor

new AVA(config: AVAConfig)

ParameterTypeRequiredDefault / behavior
configAVAConfigYesConfiguration object.
config.llmLLMConfigYesModel fields below.
config.engineEngineConfigNo{ type: 'duckdb' }; engine fields below.

The constructor does not load data. Engine creation happens on source().

Model options

Fields below belong to config.llm.

FieldTypeRequiredMeaning / default
provider'openai' | 'gateway'NoDefaults to OpenAI-compatible Chat Completions. Gateway reads AI_GATEWAY_API_KEY.
modelstring | LanguageModelYesModel name or a preconfigured AI SDK model instance.
apiKeystringNoAPI key for the LLM provider
baseURLstringNoOptional API base URL
maxRetriesnumberNoMaximum retries for retryable model API failures. Default 3.
onQueryUsage(usage: LanguageModelUsage) => voidNoOptional callback for SQL-generation token usage

String model names use OpenAI-compatible Chat Completions by default. A supplied model object is used directly. Usage callbacks are not a complete accounting stream for every LLM request.

Engine options

config.engine.type is required when engine is supplied. Supported values are duckdb, python, javascript, supabase, and clickhouse, plus names registered through registerEngine(). Omitting engine selects DuckDB. JavaScript, Supabase, and ClickHouse accept no additional engine fields; connection credentials belong to source().

DuckDB

Set engine.type to duckdb. These are all additional fields accepted on engine.

FieldTypeRequiredMeaning / default
memoryLimitstringNoMemory limit, e.g. '512MB'. Default '512MB'.
threadsnumberNoNumber of worker threads. Default 1.
maxTempDirectorySizestringNoMax size of the spill (temp) directory, e.g. '1GB'. Unset = unlimited.
queryTimeoutMsnumberNoPer-query timeout in milliseconds. Default 30000.
allowCommunityExtensionsbooleanNoAllow DuckDB community extensions during source loading when explicitly needed.

Python

Set engine.type to python. These are all additional fields accepted on engine.

FieldTypeRequiredMeaning / default
execute(code: string) => Promise<ExecutionResult>NoOverride local python3 execution with a custom environment. Local execution is not sandboxed. Run the complete Python script and return its JSON output as ExecutionResult. Source loading and result limits are included in the script; configure remote execution deadlines separately.
queryTimeoutMsnumberNoClient wait limit and local process execution deadline. Default 30000 ms.

Registered engines

Set engine.type to the name passed to registerEngine(). Additional fields are forwarded to the engine constructor as options. This is an SDK-only capability; the CLI supports built-in engine names.

FieldTypeRequiredMeaning / default
typestringYesRegistered engine name, such as 'sales'.
Other fieldsEngine-specificDepends on engineValidated by the registered engine.

registerEngine

registerEngine(type: string, engineClass: EngineClass): void

Exported by both SDK entry points. Register an engine implemented in your own application before loading a source.

ParameterTypeRequiredMeaning
typestringYesEngine name. Re-registering replaces the constructor used for future loads.
engineClassnew (llmConfig: LLMConfig, options?: Record<string, unknown>) => AnalysisEngineYesEngine class. AVA passes its model configuration and remaining engine options to each new instance.

Registration affects the loaded SDK module only. See Custom engines for a complete external implementation and lifecycle details.

source

source(config: DataSourceConfig): Promise<void>

ParameterTypeRequiredDefault / behavior
configDataSourceConfigYesReplaces the current source and disposes its engine.
config.typeSourceTypeYesOne of the 13 source types.
config.optionsSource-specific objectYesComplete source parameter tables, including CSV and database configuration.

Returns no value. Call schema() to inspect the loaded source. Reloading clears the cached schema and profile.

schema

schema(): Promise<Schema> takes no parameters. Requires a loaded source. Returns tables and optional relations; see schema and metadata.

profile

profile(options?: ProfileOptions): Promise<Profile>

ParameterTypeRequiredDefault / behavior
optionsProfileOptionsNo{}.
options.metricsMetricConfig[]Norow_count, null_count, distinct_count, top_values, min, max, mean. A supplied array replaces the defaults.
options.metrics[]Metric name or { id, ...options }When providedSupported names are listed below.
options.metrics[].idstringFor object formMetric name.
options.metrics[].limitnumberNo; top_values only3; non-negative safe integer.
options.metrics[].maxDistinctRationumberNo; top_values only0.5; finite number from 0 to 1.

Supported built-in metric names: row_count, null_count, distinct_count, top_values, min, max, mean, duplicate_count, min_length, max_length, sum, stddev, median. Other metrics accept no additional options. Unknown metrics and unknown option names are rejected. Availability depends on the engine's definitions and the field type.

Requires a loaded source and an engine with profile(). Returns and caches a Profile; metrics: [] skips metric computation. See profiling for the output format.

analyze

analyze(query: string, config?: AnalysisConfig): Promise<AnalysisResponse>

ParameterTypeRequiredDefault / behavior
querystringYesNatural-language question.
configAnalysisConfigNo{}.
config.includeSummarybooleanNotrue; false returns empty text.
config.maxRowsnumberNo200; see execution limits.
config.maxResultBytesnumberNo1048576; see execution limits.
config.strategyAnalysisStrategyConfigNoDirect analysis.
config.strategy.type'direct' / 'loop' / 'subset'When strategy is providedSelects the strategy.
config.strategy.maxRetriesnumberNo; direct only2 with explicit type: 'direct'; currently 10 when the strategy is omitted. Correction attempts after the first execution.
config.strategy.maxStepsnumberNo; loop only12; maximum reasoning steps.

subset has no additional options. These retry controls differ from llm.maxRetries. See strategy behavior and requirements.

Requires a loaded source. Returns an ExecutionResult plus:

Result fieldTypePresenceMeaning
querystringAlwaysOriginal question.
textstringAlwaysSummary, or empty when disabled.
markdownstringOptionalMarkdown content.
sqlstringOptionalExecuted query or DSL; the property name is retained for non-SQL engines.

translate

translate(query: string): Promise<string>

ParameterTypeRequiredMeaning
querystringYesNatural-language question.

Requires a loaded source. Returns generated DSL without executing it; use query() to execute that string.

query

query(dsl: string, options?: ExecutionOptions): Promise<ExecutionResult>

ParameterTypeRequiredDefault / behavior
dslstringYesExecutable statement in the selected engine's language.
optionsExecutionOptionsNoDefault execution limits below.
options.maxRowsnumberNo200.
options.maxResultBytesnumberNo1048576 bytes.

Requires a loaded source. Does not generate or summarize a query with the model.

ExecutionOptions

FieldTypeDefaultAccepted values / behavior
maxRowsnumber200Rounded down and bounded to 1–1000000; values outside the safe integer range after rounding use the default.
maxResultBytesnumber1048576 (1 MiB)Finite values are rounded down and clamped to at least 1; non-finite values use the default.

These limits bound returned data; they are separate from engine execution timeouts.

ExecutionResult

FieldTypePresenceMeaning
schemaQueryColumn[]AlwaysReturned column metadata.
schema[].namestringAlwaysColumn name.
schema[].typestringOptionalNative type name, if available.
dataT[]AlwaysReturned rows.
truncatedtrueWhen truncatedResult was bounded.
truncatedBy'maxRows' / 'maxResultBytes'When truncatedLimit that stopped the result.
rowCountnumberWhen knownRow count when execution reaches the end of the result.

suggest

suggest(count?: number): Promise<SuggestResult[]>

ParameterTypeRequiredDefault / behavior
countnumberNo3; requested number of questions.

Requires a loaded source. Returns suggestions sorted by descending score, each with query: string, score: number (0–1), and reason: string.

visualize and recommend

visualize(analysisResult): Promise<VisualizeResponse | null>

recommend(analysisResult): Promise<ChartSpec | null>

Both methods accept the same input:

ParameterTypeRequiredMeaning
analysisResultPick<AnalysisResponse, 'query' | 'data'>YesAn analysis result or an object containing the two fields below.
analysisResult.querystringYesQuestion or visualization intent.
analysisResult.dataRecord<string, unknown>[]YesRows to visualize.

Neither requires a loaded source. Both use the model and return null for empty data or when no chart is recommended. Generation errors propagate. recommend() returns a ChartSpec; visualize() additionally returns html: string containing a standalone chart page.

viz

viz(spec: ChartSpec): Promise<string>

ParameterTypeRequiredMeaning
specChartSpecYesChart specification.
spec.chartTypeChartTypeYesOne of the chart types below. Part of the shared spec; the current renderer uses syntax directly.
spec.syntaxstringYesGPT-Vis chart syntax to embed in HTML.

ChartType values: line, column, bar, pie, area, scatter, dual-axes, histogram, boxplot, radar, funnel, waterfall, liquid, word-cloud, violin, venn, treemap, sankey, table, summary.

Returns a standalone HTML string. Does not require a loaded source or call a model. See chart specifications.

dispose

dispose(): Promise<void> takes no parameters. Releases the current engine and clears the schema and profile. Await it in a finally block.

Event methods

AVA inherits synchronous on, once, off, emit, and getEvents methods from the AntV event emitter. See event method parameters.

executionResult helper

executionResult<T>(rows: T[], schema: QueryColumn[], options?: ExecutionOptions, upstreamTruncatedBy?: 'maxRows' | 'maxResultBytes'): ExecutionResult<T>

A synchronous helper exported by both SDK entry points for custom engine implementations. Import it from @antv/ava or @antv/ava/browser.

ParameterTypeRequiredMeaning / default
rowsT[]YesRows produced by the engine.
schemaQueryColumn[]YesOutput columns; each has name: string and optional type: string.
optionsExecutionOptionsNo{}; uses the execution limits above.
upstreamTruncatedBy'maxRows' or 'maxResultBytes'NoPreserve truncation already reported by an upstream executor unless a local limit truncates further.

Returns bounded data, schema, and either rowCount for a complete result or truncation metadata for a partial result. Throws if an individual result field exceeds 1 MiB. The helper bounds already-produced rows; it does not limit query execution or input memory use.