DAT (Data Ask Tool)

repository·main·Indexed 42 days ago

https://github.com/hexinfo/dat

An enterprise-grade AI framework for natural language querying of databases. DAT uses a semantic modeling layer and agentic workflows to convert human language into deterministic SQL queries. It features a pluggable SPI architecture supporting MySQL, PostgreSQL, and Oracle, and provides a Java SDK (version 0.7.2), CLI, and server options for OpenAPI and Model Context Protocol (MCP) integration.

Tokens
28.9K
Snippets
81
Records
106
Agent score
34%

What's inside DAT

  1. Overview of DAT (Data Ask Tool)

    main

    DAT (Data Ask Tool) is an enterprise-grade AI framework designed to bridge the gap between natural language and structured data. It allows business users to interact with databases using natural language instead of writing complex SQL queries.

    Unlike a standalone platform, DAT is a framework that provides an Askdata Agent workflow. It focuses on ensuring high-quality and deterministic results by providing precise knowledge (semantic modeling), more computational steps, and extended reasoning time.

    Key capabilities include:

    • Pluggable SPI Architecture: Flexible extension for databases, LLMs, and embedding models.
    • Multi-Database Support: Native support for MySQL, PostgreSQL, and Oracle, with extensibility via SPI.
    • Semantic SQL Generation: LLM-based natural language understanding with automatic SQL dialect conversion.
    • Semantic Modeling: Definition of Entities (primary/foreign keys), Dimensions (time, category, enumeration), and Measures (aggregations, calculated fields) using YAML.
    • Vectorized Retrieval Augmentation (RAG): Semantic matching for SQL question-answer pairs, synonyms, and business knowledge using backends like DuckDB, Weaviate, or PGVector.
  2. What are seed data in DAT?

    main

    Seed data refers to static datasets within the DAT system used for storing relatively unchanging reference data, configuration data, or test data. These datasets are stored as CSV files and defined via YAML configuration files that describe their structure and metadata. Once loaded, seed data can be queried and referenced just like regular database tables.

    Common use cases include:

    • Reference Data: Country codes, currency codes, product categories.
    • Configuration Data: Business rule configurations, rate tables, threshold settings.
    • Test Data: Static datasets for development and testing environments.
    • Dimension Data: Small dimension tables like status enums or category mappings.
  3. Relate seed data to semantic models

    main

    Seed data can serve as a data source (table) for semantic models or be joined with other data sources. You can reference seed data within a semantic model using standard SQL JOIN syntax in the model definition.

    # In a semantic model, reference seed data via SQL
    semantic_models:
      - name: orders_with_country
        model: |
          SELECT o.*, c.country_name, c.continent
          FROM orders o
          LEFT JOIN country_codes c 
            ON o.country_code = c.country_code
  4. Understand the DAT System Architecture

    main

    DAT is organized into two primary layers: the DAT Language (Creation Layer) and the DAT Engine (Execution Layer).

    1. DAT Language (Creation Layer)

    This layer is where users define the intelligence of the system using:

    • Semantic Model Definitions (YAML): Defining the structure and relationships of the data.
    • Data Model Configuration: Configuring how data is accessed.
    • Intelligent Agent Configuration: Setting up the behavior of the AI agents.

    2. DAT Engine (Execution Layer)

    This layer handles the heavy lifting of processing a natural language request:

    • Natural Language Understanding (NLU): Parsing the user's intent.
    • Semantic SQL Generation: Converting intent into database-specific SQL.
    • Data Query Execution: Running the generated SQL against the database.
    • LLM Management: Handling calls to Large Language Models.
    • Vector Retrieval Augmentation: Enhancing queries with retrieved context.
    • SPI Component Management: Using the Factory pattern to manage pluggable components.
    • Result Formatting: Preparing the data for the end-user.
    ┌─────────────────────────────────────────────────────────────┐
    │                        DAT Framework                        │
    ├─────────────────────────────────────────────────────────────┤
    │  🎯 DAT Language (创作层)                                    │
    │  ├── 📝 语义模型定义 (YAML)                                  │
    │  ├── 🗃️ 数据模型配置                                         │
    │  └── 🤖 智能代理配置                                         │
    ├─────────────────────────────────────────────────────────────┤
    │  ⚙️ DAT Engine (执行层)                                      │
    │  ├── 🔤 自然语言理解   │  📊 语义SQL生成    │  🗄️ 数据查询执行  │
    │  ├── 🧠 LLM调用管理    │  🔍 向量检索增强   │  📈 结果格式化    │
    │  └── 🔌 SPI组件管理    │  🏭 工厂模式创建   │  ⚡ 缓存优化     │
    └─────────────────────────────────────────────────────────────┘
  5. Configure seed data structure and properties

    main

    Seed data is defined using a YAML configuration file. Each entry in the seeds list requires a name and description. You can optionally provide a config object for parsing settings and a columns list to define the schema.

    Basic Schema Components:

    • name (Required, String): The unique name of the seed data, which must match the CSV filename.
    • description (Required, String): A detailed description of the data's purpose.
    • config (Optional, Object): Parsing configurations, such as the delimiter.
    • columns (Optional, List): Definitions for each column, including name, description, and data type.
    version: 1
    seeds:
      - name: seed_data_name
        description: "Detailed description"
        config:
          delimiter: ","
        columns:
          - name: column_name
            description: "Column description"
            data_type: "VARCHAR(255)"
  6. Understand the DAT Module Architecture

    main

    DAT is built using a modular architecture where specific functionalities are isolated into distinct modules. This allows for easy extension and selection of specific components like database adapters, LLMs, or vector stores.

    Key module categories include:

    • dat-core: Core interfaces and factory management.
    • dat-adapters: Database connectivity (e.g., DuckDB, MySQL, PostgreSQL).
    • dat-llms: Large Language Model integrations (e.g., OpenAI, Anthropic, Ollama).
    • dat-embedders: Embedding model integrations.
    • dat-rerankers: Reranking model integrations.
    • dat-storers: Vector storage backends (e.g., PGVector, Qdrant, Milvus).
    • dat-agents: Intelligent agent implementations.
    • dat-servers: Server components like MCP or OpenAPI.
    • dat-sdk: The primary development toolkit for Java integration.
    • dat-cli: Command-line interface tool.
  7. Organize semantic model files

    main

    DAT supports two primary ways to organize your semantic and data models:

    1. Co-located (共置方式): Keep the semantic model configuration and the corresponding data model in the same file/location. This is suitable for smaller projects to reduce file switching.
    2. Separated (分离方式): Keep semantic model configurations in .yaml files and data models in .sql files. This is recommended for large-scale projects to improve maintainability.

    Recommended Directory Structure:

    models/
    ├── customers.sql       # Customer data model
    ├── customers.yaml       # Customer semantic model
    └── marts/
        ├── orders.sql          # Order data model
        └── orders.yaml          # Order semantic model
  8. Understand the core components of a Semantic Model

    main

    A Semantic Model is the core of the DAT system. It defines the business meaning and structure of data, enabling the AI to translate natural language queries into precise SQL statements.

    A semantic model consists of three core components defined in a YAML configuration file:

    1. Entities (entities): Describe the relationships between different semantic models (similar to primary/foreign key relationships).
    2. Dimensions (dimensions): The columns you want to slice, group, and filter by (e.g., timestamps, categories, etc.).
    3. Measures (measures): The quantitative values you want to aggregate (e.g., sums, counts, averages).

    Semantic models are defined purely through YAML files located in the models directory.

  9. Understand the DAT Modular Architecture

    main

    DAT (Data Ask Tool) is designed with a modular architecture where each component has a specific responsibility. This allows developers to pick and choose specific capabilities (like specific LLMs, database adapters, or vector stores) by adding the corresponding Maven dependencies.

    Core modules include:

    • dat-core: Core interfaces and factory management.
    • dat-adapters: Database adapters (e.g., DuckDB, MySQL, Oracle, PostgreSQL).
    • dat-llms: LLM integration (e.g., OpenAI, Anthropic, Gemini, Ollama).
    • dat-embedders: Embedding model integration (e.g., BGE, Jina, OpenAI).
    • dat-rerankers: Reranking model integration (e.g., ONNX, MS-Marco).
    • dat-storers: Vector storage backends (e.g., PGVector, Weaviate, Qdrant, Milvus).
    • dat-agents: Intelligent agent implementations.
    • dat-servers: Server components like MCP or OpenAPI.
    • dat-sdk: The primary development kit for Java integration.
    • dat-cli: Command-line interface tool.
  10. Core Features of DAT

    main

    DAT provides several key capabilities for building natural-language-to-SQL applications:

    Architecture & Extensibility

    • Pluggable SPI Architecture: Supports flexible extensions for multiple databases, LLMs, and embedding models.
    • Factory Pattern: Uses a standardized mechanism for component creation and management.
    • Modular Design: Separates responsibilities for easier maintenance.

    Database & SQL Support

    • Multi-database Support: Native support for MySQL (including connection pooling and dialect conversion), PostgreSQL, and Oracle, with extensibility for others via SPI.
    • Intelligent Semantic SQL Generation: Combines LLM-based semantic parsing with automatic SQL dialect conversion and semantic model binding.

    Semantic Modeling & Retrieval

    • Rich Semantic Modeling: Define Entities (PK/FK relationships), Dimensions (time, categorical, enumeration), and Measures (aggregations, calculated fields) using YAML configuration.
    • Vector-enhanced Retrieval: Uses embedding models to perform semantic retrieval on SQL Q&A pairs, synonyms, and business knowledge. Supports backends like DuckDB, Weaviate, and PGVector.
  11. Configure Measures in a Semantic Model

    main

    Measures are aggregations performed on columns (e.g., sums, counts). They can be final metrics or building blocks for complex calculations.

    Supported Aggregation Types (agg)

    sum, min, max, avg, count, count_distinct, median, sum_boolean, none (default).

    Configuration Parameters

    ParameterDescriptionRequiredType
    nameUnique name across all modelsYesString
    exprColumn or SQL expression to aggregateNoString
    aggAggregation typeNoString
    agg_time_dimensionThe time field used for aggregationNoString
    non_additive_dimensionDefines dimensions where aggregation is invalid (e.g., balances)NoObject

    Handling Non-Additive Dimensions

    For metrics like account balances that cannot be summed across certain dimensions, use non_additive_dimension to specify a windowing strategy.

    measures:
      - name: account_balance
        expr: balance
        agg: sum
        non_additive_dimension:
          name: "balance_date"
          window_choice: "max"
          window_groupings: ["account_id"]
    measures:
      - name: total_amount
        expr: amount
        agg: sum
        agg_time_dimension: "order_date"
    
      - name: unique_customers
        expr: customer_id
        agg: count_distinct