UnieAI Studio

Querying Large Databases

Handing a database to an assistant — from connecting it, through letting the system read it, to the few sentences you write that make it answer accurately. Every step says why it exists, and whether what you wrote actually reaches the assistant.

Connecting a database does not make the assistant understand it. This page walks the whole flow, and every step states why it exists and what goes wrong without it before telling you where to click.

Complete these steps with your own database. Table, column and relationship counts and processing time depend on the source and current workload.

First, two things that make the rest make sense

One: the assistant carries a map, not your data

The assistant uses a data map to identify tables, columns and relationships. To answer a data question it runs an authorized SQL query; the query result or a reference to the complete result becomes available for that answer.

WhenContents
MapEvery messageTable names, descriptions, column names, relationships
EvidenceOnly when a number is neededThe query result and readable result references

Everything below is about making that map correct. A wrong map makes the assistant confidently wrong.

Two: definitions belong to the database, not to the assistant

What a column means, how a metric is computed, how tables join — these are facts about that database. They do not change because a different assistant reads it.

So definitions live on the database's own page, written once:

  • Three assistants on the same database means one read, and one set of descriptions to maintain
  • Correct a column's meaning in one place and every assistant using it is current immediately
  • There is no way to end up with "one database, two assistants, two different meanings"

When you need the full flow, and when you don't

A handful of tables with human-readable names — steps 1 and 2 are enough; the system's own descriptions are usually usable as they are.

The later steps matter when:

  • Column names are abbreviations (ord, cst, amt, f_0837)
  • One concept has different names in different tables, or one name means different things
  • You have a history of "the same number, computed differently by different people"

If you only want the assistant to read documents, not query a database — this page does not apply; see the knowledge base sections.

Step 1: Connect a database

Why: something has to reach your database. This step only opens the connection — it reads nothing.

What you get: a working connection. The system still does not know what is inside.

How: go to My SQL Databases, add a connection, and fill in host, port, database, username and password.

Use a read-only account for analysis. Data-connection and tool permissions determine allowed operations; a read-only source account restricts unnecessary writes.

 Name the connection.  Select its engine.  Enter the host.  Enter the database; the example host is not reachable.
Name the connection. Select its engine. Enter the host. Enter the database; the example host is not reachable. Click to enlarge
 Database user.  Password.  Continue to the connection test; use read-only access for querying.
Database user. Password. Continue to the connection test; use read-only access for querying. Click to enlarge

Step 2: Let the system read the database

Why: abbreviations such as ord and f_0837 do not explain business meaning. Describe tables and columns so the assistant has explicit definitions to consult; verify the actual query and source when checking an answer.

What you get: a map the assistant can read.

How: click the database's name in the list to open its page, then press Read this database. It runs in the background and you can leave the page. After the task completes, inspect its status and generated definitions.

It does four things:

  1. Reads the structure — tables, columns, types, primary keys, foreign keys. No rows are read.
  2. Writes descriptions — one sentence per table and per column. This calls a model and is billed to the owner's wallet.
  3. Groups what is the same thing — ord and ord_2023 collapse into one business entity, marked current vs. history.
  4. Adopts declared foreign keys — relationships your database declares are taken as fact, not put to you as questions. Check that the source foreign-key definitions reflect the intended business relationships.

Step 3: See what the assistant actually reads

Why: this is the most important step on the page and the easiest to skip. What you write does not automatically reach the assistant — see which parts do before deciding where to spend effort.

What you get: a definite answer to "is the sentence I just wrote being used".

How: on the database's page, open What the assistant reads.

The page shows which definition types are included in the current database prompt:

DefinitionIn the prompt?When it goes in
Table namesYesAlways
Column namesSometimesFull mode only — and then all of them, nothing truncated
Column meaningsNoNot expanded column by column in the map; tools can read the details when needed
Business logic (metrics)SometimesFull mode only, and only ones that are confirmed and carry an expression
Table relationshipsSometimesFull mode only; a confirmed one becomes A.col = B.col

Inspect the content currently available to the assistant and check its tables, columns, definitions and relationships.

"Not in the prompt" is not "unused". Column meanings are what makes a question find the right table: they feed both lexical matching and semantic retrieval, and they are what the assistant reads when it looks a table up. A Chinese question reaching an English-named column is exactly this at work.

Two modes: the system provides a full map or a name index according to the available prompt budget. With a name index, the assistant can request the required details through tools. Check the preview to see what is currently included.

A map summary does not define the extent of the source. For tables that are not expanded, continue reading the catalogue and definitions before answering from the results.

Step 4: Add the meanings only you know

Why: some things the data cannot answer. Whether net_amt is before tax or after discounts, what entity_id actually refers to — the schema does not say. An assistant that guesses gives you a number that cites real rows, looks reasonable, and is wrong.

What you get: explicit column definitions for the assistant to consult and for users to verify.

How: on the Column definitions tab.

Start with the shared column names — the highest return on the page. The system collects names that recur across tables at the top; confirm the shared meaning applies to the related columns before updating them together. The page lists the actual affected columns.

For example, several tables use entity_id; first confirm whether they refer to the same business concept.

A shared column name does not guarantee shared meaning. Apply an update together only to columns confirmed to have that meaning.

Below it is the per-table column list, searchable and filterable by "still needs me", where the system's descriptions can be reviewed and corrected one at a time.

How far is far enough: you do not have to empty the list. Columns you skip still work — the assistant just has nothing but the name to go on for those.

Step 5 (optional): Pin the numbers that matter

Why: if "revenue this month" is worked out afresh by a model each time it is asked, the same question returns different numbers on different days — and the difference is invisible, because both answers cite real rows.

What you get: metrics and calculations you can inspect.

How: open the Business logic tab and bind a number to one definition — "revenue this month = SUM(net_amt), status = 'paid' only".

Some numbers cannot be written as one expression — they join several tables, use window functions, or you already have an agreed query. Choose fixed query and paste that SQL. Confirmed fixed queries reduce differences from regenerating a query each time. Check the executed metric, parameters, filters and result.

Only confirmed definitions reach the prompt. Drafts do not.

Step 6: Confirm how tables join

Why: declared foreign keys are already adopted; for the rest, the system proposes joins from column names. A wrong proposal joins two unrelated tables, and the error arrives looking well-sourced.

What you get: confirmed relationship definitions for checking queries.

How: open the Table relationships tab and confirm or correct each one. A confirmed relationship is written into the prompt at column level (A.col = B.col), not just "these two tables are related".

Step 7: Let an assistant use the database

In the assistant's Data station, add this database. It immediately reads everything written in the steps above — none of it has to be done again inside the assistant.

With more than one database there is one limit to know: one SQL statement runs on one database.

① The assistant knows which source each table belongs to. The map is sectioned; two databases' tables never blur together.

② It picks the best-matching source and says which ones it did not use.

Other bound sources also matched: support (tickets) — name it in your question to query there instead

③ Joining across two databases is currently unavailable. A cross-database relationship can never be inferred from a foreign key — no database declares one into another database — so it accepts only human-confirmed relationships, and there is currently no place to confirm one. The assistant says it answered from one side rather than quietly answering half the question.

 Open the agent’s data connections.  Add or select a SQL source; a source is required before semantic mapping and BI.
Open the agent’s data connections. Add or select a SQL source; a source is required before semantic mapping and BI. Click to enlarge

What the assistant actually sees

You do not have to take this on trust — What the assistant reads shows the verbatim text. In full mode it looks like this:

# Data Map

This assistant can draw on the data sources below. Use `kb_search` for knowledge bases
and `sql_query` for databases; prefer the source whose description matches the question.

## Databases
### bench_wide (postgresql)
- **audit_log**: The audit_log table stores records of user actions, including the employee ID,
  action code, target type and ID, and the timestamp of the event.
  _[audit_id, actor_employee_id, action_cd, target_kind, target_id, logged_at]_

### Relationships
- audit_log → employee
- campaign → channel

No rows — table names, descriptions, column names, relationships.

Archive tables are labelled, not hidden — the name is evidence, strong enough to state and not strong enough to decide for you:

- **ord_2023** _(looks like an archive/staging copy of `ord` — prefer `ord` unless the question is about history)_

A fixed query is one whole statement, not a fragment to assemble:

- Revenue this month (unit: TWD) — FIXED QUERY, run verbatim, do not modify or wrap:
    SELECT SUM(net_amt) FROM ord o JOIN fx f ON f.d = o.d WHERE o.status = 'paid'

Giving the database to an outside tool

The same definitions are available to clients outside Studio. Take the configuration from the connection's MCP dialog; three tools are available:

ToolWhat it gives you
sql_schemaTable names, columns, types — asked of the database directly
sql_data_mapWhat those names mean: column meanings, relationships, confirmed metrics; also finds which table holds a field
sql_queryRuns SQL

sql_data_map reads exactly the definitions written on this page. For a database that has not been read yet it says so, rather than returning an empty result that reads as "no such data".

Common questions

Does the assistant send my data to a model? The model may receive structural names, definitions and necessary query results. The selected model connection and tools determine the data flow; review the authorized scope before connecting them.

What does reading cost? Step 2 calls a model to write descriptions and is billed using the applicable pricing. Time and cost depend on structure size, model and usage. Multiple agents can share saved definitions; reading the schema or generating descriptions again may incur further usage.

I corrected a column description — when does the assistant know? On the next message, and for every assistant using that database.

Can I see the definitions for a database somebody shared with me? Yes. Anyone who can use a database can read its definitions — that is what their own assistant answers from. Editing is limited to the owner and admins, because one edit changes what every assistant using it says.

Why doesn't the system work out the relationship between two databases? Because no foreign key exists across databases, so any answer would be a guess. A wrong guess joins two companies' customers together, and the error arrives looking well-sourced.