Read the schema
After calling source(), retrieve structural metadata without an LLM call:
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
| Property | Contents |
|---|---|
tables | All exposed tables or views |
tables[].name | Engine-registered table name |
tables[].columnCount | Number of columns |
tables[].fields | Field name, native type, and optional nullable |
tables[].indexes | Index name, columns, uniqueness, and optional primary-key flag |
relations | Optional 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
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
const profile = await ava.profile({
metrics: ['row_count', 'null_count', 'distinct_count', { id: 'top_values', limit: 5, maxDistinctRatio: 0.5 }],
});| Selection | Metrics |
|---|---|
| Default | row_count, null_count, distinct_count, top_values, min, max, mean |
| Additional | duplicate_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.