Skip to content
Browse documentation
Working with data

Understand your data

Inspect schema and relationships, then compute profiling metrics.

Read the schema

After calling source(), retrieve structural metadata without an LLM call:

typescript
const schema = await ava.schema();
for (const table of schema.tables) {
  console.log(table.name, table.columnCount);
  console.log(table.fields, table.indexes);
}
console.log(schema.relations);

schema(): Promise<Schema> throws when no source is loaded.

Schema structure

PropertyContents
tablesAll exposed tables or views
tables[].nameEngine-registered table name
tables[].columnCountNumber of columns
tables[].fieldsField name, native type, and optional nullable
tables[].indexesIndex name, columns, uniqueness, and optional primary-key flag
relationsOptional foreign-key relationships with from and to table/column pairs

Metadata availability depends on the source and engine. File sources have no database indexes; not every source exposes foreign-key relations.

Schema versus profile

schema() describes structure. Profiling adds table and column metrics, a shared logical type, and a timestamp. Calling profile() retains those statistics for subsequent model-facing operations.

Always use returned names when writing a direct query instead of guessing a table name from the source filename.

Profile a dataset

typescript
const profile = await ava.profile();
console.log(profile.tables[0].metrics.row_count);
console.log(profile.tables[0].fields[0].logicalType);
console.log(profile.generatedAt);

profile(options?: ProfileOptions): Promise<Profile> requires a loaded source. It computes metrics in the selected engine and retains the latest profile for analysis, translation, and query suggestions.

Select metrics

typescript
const profile = await ava.profile({
  metrics: ['row_count', 'null_count', 'distinct_count', { id: 'top_values', limit: 5, maxDistinctRatio: 0.5 }],
});
SelectionMetrics
Defaultrow_count, null_count, distinct_count, top_values, min, max, mean
Additionalduplicate_count, min_length, max_length, sum, stddev, median

A supplied metrics array replaces the defaults. metrics: [] returns enriched structural metadata without computing statistics. Metrics apply only to compatible targets and field types.

Profile format

A profile contains the schema plus table-level and field-level metrics. Fields also expose logicalType: numeric, string, boolean, date, or unknown. generatedAt is a Unix timestamp in milliseconds.

top_values defaults to a limit of 3 and maximum distinct ratio of 0.5. Options and availability are checked by the engine's metric definitions.

See profile parameters for all metric options and their accepted values.