Introducing a new way to review your PRs.

Read the announcement

frappe / insights

Open Source Business Intelligence Tool

View on GitHub

25 documents · Updated Nov 23, 2026

docs / ai-assisted-search

The AI search API helps an agent turn a business term into a permitted analytical resource or table column. It returns enough context to choose the next exploration step without first loading every document, while usage signals help the agent prefer resources that the organisation uses.

Search API role

The API is a discovery layer for agent-assisted exploration. It does not answer the business question or build the final query. Instead, it exposes the site's own names and definitions so an agent can connect business language to the analytical assets used by data exploration and query building. It complements resource discovery and list filtering by serving agent-led searches for analytical meaning.

The API exposes two search actions:

ActionDiscovery targetMain use
search_contentWorkbooks, queries, charts, and dashboardsFind named resources and definitions that relate to a business term
search_columnsStored table-column metadataFind fields that can become query inputs

Both actions are available to an Insights User through the normal Insights API access boundary. The caller must still use the query-building and execution flows in query editor and execution workflow and the server-side support in query utilities to inspect or run analysis.

Resource discovery

The search API covers the vocabulary that links an organisation's business terms to its analytical work. Content search looks at workbook titles, query titles and operations, chart titles and configuration, and dashboard titles and items; column search looks at stored names and types for readable tables.

The API uses the matching resource as the unit of discovery. A result identifies the resource and its workbook context when one exists. This lets an agent move from a broad term to a specific analytical object before it asks for more detail.

References: insights/…/search.py• L25-40 insights/…/search.py• L43-83

Content search contract

search_content(term, limit=20) finds permitted workbooks, queries, charts, and dashboards whose searchable content contains the term. A blank or whitespace-only term returns no results, so an agent should only call this action after it has a usable business term.

Each result has this shape:

FieldMeaning
doctypeThe analytical resource type
nameThe resource identifier
titleThe resource's display title
workbookThe containing workbook identifier, or the resource itself for a workbook result
workbook_titleThe containing workbook title when it can be resolved
matched_fieldThe field in which the term matched
snippetA short context excerpt with the matched text marked in Markdown-style bold
used_by_chartsNumber of readable charts that use the result
used_by_dashboardsNumber of readable dashboards that use the result, directly or through charts
dashboard_viewsReadable dashboard opens in the last 30 days for the result's downstream reach

The default response contains at most 20 results. The caller can pass limit when it needs a smaller or larger candidate set. The API ranks title matches before matches in other searchable fields, then favors recent dashboard reach, dashboard use, and chart use. Recency breaks ties. These signals help an agent select a trusted definition, but they do not prove that a result answers the question.

References: insights/…/search.py• L43-72 insights/…/search.py• L112-143 insights/…/search.py• L309-315

Column search contract

search_columns(term, data_source=None, limit=100) finds readable table columns whose stored names contain the term. It is intended to turn a business word such as revenue into a field candidate that a later query workflow can use.

Each result has this shape:

FieldMeaning
data_sourceThe source that owns the table
table_nameThe table identifier
labelThe table's user-facing label
columnThe matching column name
typeThe stored column type

The default response contains at most 100 matches. data_source narrows the search to one source when the agent already knows where to look. Exact column names rank before other substring matches. A table appears only when its column metadata has been stored and the caller may read that table.

References: insights/…/search.py• L75-109 insights/…/insights_table_v3.py• L234-264

Access and ranking

The API treats permissions as part of the search contract rather than as a later filter. Search results, workbook context, and usage counts are based only on resources that the caller may read. This prevents an agent from learning the name or popularity of a resource that it cannot open.

Content matching is literal substring matching within the defined searchable fields. The API protects user-entered wildcard characters from changing that meaning. Search is therefore useful for vocabulary discovery, but it is not semantic search and does not infer synonyms.

Usage measures downstream reach. Query use flows through its readable charts and dashboards. Chart use flows through readable dashboards. Dashboard use is measured by its own opens in the last 30 days. A high count indicates organisational use, not correctness for the current question.

References: insights/…/search.py• L4-13 insights/…/search.py• L189-191 insights/…/search.py• L212-263 insights/decorators.py• L118-144 insights/…/dashboards.py• L113-131

Agent exploration flow

An agent should use the API to narrow the site's vocabulary before it selects a query path. The flow separates discovery from execution: content results provide analytical context, column results provide field candidates, and the linked query tools perform the next operation.

The following flow shows the contract between discovery and later analytical work.

flowchart LR
    Q[Business question] --> T[Search term]
    T --> C[search_content]
    T --> F[search_columns]
    C --> R[Resource candidates]
    F --> K[Column candidates]
    R --> D[Inspect permitted analytical resource]
    K --> D
    D --> B[Build or refine query]
    B --> X[Execute and present results]

The agent should use search_content when it needs an existing definition, query, chart, or dashboard. It should use search_columns when it needs a field or table that can support a new query. After discovery, it should follow the query editor and execution workflow or query utilities rather than treating search results as executable queries.

References: insights/…/search.py• L43-109

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep the content result fields aligned with the agent's resource-selection contract, especially matched_field, snippet, workbook context, and usage counts.
  • Keep the searchable resource fields aligned with the names and structures that users see in workbooks, queries, charts, and dashboards.
  • Keep permission filtering consistent across direct results and downstream usage counts. A readable child must not expose an unreadable parent through its counts or names.
  • Keep the column result fields aligned with stored table metadata and with the query-building consumers that use data_source, table_name, column, and type.
  • Recheck the meaning of the ranking window if dashboard view tracking or the 30-day period changes.

Important failure modes

TriggerConsequenceGuard
The agent sends an empty termThe API returns no candidatesValidate the term before search and ask for a more specific business word
A term exists only in a synonym or in an unsearched fieldContent search returns no resourceSearch the organisation's recorded terms, then use column search or another known resource path
Table column metadata was not stored or is staleA valid table or field is absent from column resultsTreat column search as metadata discovery and confirm the selected source before building the query
The caller cannot read a resource or its parent dashboardThe resource or related usage signal is absentContinue only with returned resources and do not infer hidden names
The agent treats usage as semantic relevanceA popular resource can be chosen for the wrong questionUse snippets and titles to verify meaning before query construction
A result is treated as an executable queryDiscovery output is used without the required query flowPass the selected resource or column into the query editor or query utilities

Key files

FileWhy to read it
insights/…/search.pyDefines the search actions, result contracts, matching scope, access behavior, snippets, and ranking signals.
insights/…/insights_table_v3.pyDefines the stored-column view that supports column discovery and its permission boundary.
insights/…/dashboards.pyDefines the dashboard view counts used as the recent usage signal.
insights/decorators.pyDefines the standard Insights User API access boundary applied to the search actions.
docs/query-editor-and-execution.mdRelated page for the workflow that consumes discovered resources and fields.
docs/query-utilities.mdRelated page for the server-side query support that follows discovery.