System Architecture¶
The In-Dataset Discovery Service is a self-contained application designed to act as a specialized query layer within the DataGEMS ecosystem.
Core Components¶
-
FastAPI Application: The heart of the service is a Python web application built with FastAPI. It exposes the REST API, handles incoming HTTP requests, and orchestrates all internal operations.
-
Geospatial Component: A module that processes natural language geospatial queries, identifies places using Wikidata, generates OverpassQL queries, and retrieves geospatial data from OpenStreetMap via the Overpass API.
GET /text2geoand the first step ofGET /exploreboth use this module. -
Text-to-SQL Component: Converts a natural-language question into SQL and executes it. The default generator is DAIL-SQL (
TEXT2SQL_FRAMEWORK=dail), with one candidate at temperature 0.TEXT2SQL_FRAMEWORK=opensearchselects the OpenSearch-SQL graph.TEXT2SQL_LEGACY=true(orTEXT2SQL_PIPELINE=false) keeps the single-shot pattern generator. On the DAIL-SQL path,sql_pattern,input_params, andoutput_paramsare null, and clients usesql_query. ERA5-Land receivesMETEO_DDL,UNIT_CONTRACTS, hints, the constraint validator, and a query rewrite. AROUND(CAST(latitude/longitude)) IN (...)list of 20 or more pairs is rewritten as aVALUESjoin with the same coordinates. PostgreSQL executes that form much faster, and its query optimizer does not apply the rewrite automatically. Shorter lists are left unchanged. Other databases use the live schema only. Few-shot text comes from in-cluster Qdrant only whenRETRIEVAL_ENABLEDis on, the database isera5land, and retrieval returns text. -
Meteo text-to-SQL agent:
GET /exploreruns this LangGraph workflow (meteo_agent). It calls text2geo, then text-to-SQL, against the ERA5-Land database set byDB_HOST,DB_PORT,DB_USER,DB_PASSWORD,DB_NAME_ERA5LAND, andDB_SCHEMA_ERA5LAND.POST /explore4apruns the same chain and writes the result onto an analytical pattern graph, includingmetadata.params.text2geoandmetadata.params.text2sql. -
Analytical-pattern-specific endpoints:
POST /text2sql4apandPOST /explore4apare the analytical-pattern-specific forms of/text2sqland/explore. They accept an analytical pattern graph (node labelAnalytical_Pattern), read the question from the natural language operator (NLQ_Operator), and connect withDB_USERandDB_PASSWORDplus the database connection node'scontentUrl. They return the enriched graph and text-to-SQL metadata./text2sql4apomitssql_resultsfrom metadata. -
Security Layer: This layer intercepts protected requests to perform authentication and authorization. It integrates with an external OIDC provider to validate JWTs and with the DataGEMS Gateway to fetch user-specific permissions.
Request Flow¶
Geospatial Query Flow¶
- A user sends a
GET /text2georequest with a natural language question about a location. - The Security Layer validates the token and checks for the required user roles.
- The service uses Wikidata to identify the most relevant place entity.
- An OverpassQL query is generated based on the Wikidata information.
- The Overpass API is queried to retrieve geospatial data.
- Results are returned, including
{lon, lat}points, a[lat, lon]center, GeoJSON, and a bounding box. A missing place is404. Wikidata or Overpass connectivity failure is503.
Text-to-SQL Query Flow¶
- A user sends a
POST /text2sqlrequest with a natural language question and database connection information. Coordinate pairs, when present, are disambiguated so the larger magnitude within ±90 is latitude. - The Security Layer validates the token and checks for the required user roles.
- The text-to-SQL component generates SQL with DAIL-SQL.
TEXT2SQL_FRAMEWORK=opensearchselects the OpenSearch-SQL graph, andTEXT2SQL_LEGACY=truekeeps the single-shot pattern path. - For
era5land, the prompt includesMETEO_DDLandUNIT_CONTRACTS. Few-shot text from in-cluster Qdrant is added only when retrieval is enabled and returns text. - The SQL query is executed against the database in the request.
- Results are returned with
sql_queryandsql_results. If generation or execution fails, the HTTP status can still be200and the body"status"is"error".
Explore Flow¶
- A user sends
GET /explore?question=.... - text2geo returns coordinates for the place named in the question.
- Text-to-SQL runs against
DB_HOST,DB_PORT,DB_USER,DB_PASSWORD,DB_NAME_ERA5LAND, andDB_SCHEMA_ERA5LAND. - The response includes
sql_query,sql_results,inference_time_s, anddb_fetch_time_s.
Analytical-pattern-specific flow¶
- A user sends
POST /text2sql4aporPOST /explore4apwith{ "ap": { "nodes", "edges" } }. - The service reads the question from the natural language operator and the relational-database node from the graph.
- Database host, port, and name come from the database connection node's
contentUrl. The password is the serviceDB_PASSWORD. /text2sql4apgenerates SQL directly./explore4apruns the meteo text-to-SQL agent first.- The enriched graph is returned with metadata. An invalid graph returns
422. DMM or database connection failures return424.