urimai.core

.. py:module:: urimai.core

.. py:module:: urimai.core.chat_session

Chat session management with conversation history.

.. py:class:: Message(*, role, content, timestamp=None) :module: urimai.core.chat_session

Bases: :py:class:~pydantic.main.BaseModel

A message in the conversation.

.. py:attribute:: Message.role :module: urimai.core.chat_session :type: str

.. py:attribute:: Message.content :module: urimai.core.chat_session :type: str

.. py:attribute:: Message.timestamp :module: urimai.core.chat_session :type: str

.. py:attribute:: Message.model_config :module: urimai.core.chat_session :type: ~typing.ClassVar[~pydantic.config.ConfigDict] :value: {}

  Configuration for the model, should be a dictionary conforming to [`ConfigDict`][pydantic.config.ConfigDict].

.. py:class:: QueryResult(*, question, sql_query, answer, row_count, timestamp=None) :module: urimai.core.chat_session

Bases: :py:class:~pydantic.main.BaseModel

A query execution result for history.

.. py:attribute:: QueryResult.question :module: urimai.core.chat_session :type: str

.. py:attribute:: QueryResult.sql_query :module: urimai.core.chat_session :type: str

.. py:attribute:: QueryResult.answer :module: urimai.core.chat_session :type: str

.. py:attribute:: QueryResult.row_count :module: urimai.core.chat_session :type: int

.. py:attribute:: QueryResult.timestamp :module: urimai.core.chat_session :type: str

.. py:attribute:: QueryResult.model_config :module: urimai.core.chat_session :type: ~typing.ClassVar[~pydantic.config.ConfigDict] :value: {}

  Configuration for the model, should be a dictionary conforming to [`ConfigDict`][pydantic.config.ConfigDict].

.. py:class:: ChatSession(db_name) :module: urimai.core.chat_session

Bases: :py:class:object

Manages an interactive chat session with conversation history.

.. py:attribute:: ChatSession.conversation_history :module: urimai.core.chat_session :type: list[~urimai.core.chat_session.Message]

.. py:attribute:: ChatSession.query_history :module: urimai.core.chat_session :type: list[~urimai.core.chat_session.QueryResult]

.. py:method:: ChatSession.add_user_message(question) :module: urimai.core.chat_session

  Add user message to conversation history.

  :type question: :sphinx_autodoc_typehints_type:`\:py\:class\:\`str\``
  :param question: User's question

  :rtype: :sphinx_autodoc_typehints_type:`\:py\:obj\:\`None\``

.. py:method:: ChatSession.add_assistant_response(answer, sql_query=None, row_count=0) :module: urimai.core.chat_session

  Add assistant response to conversation history.

  :type answer: :sphinx_autodoc_typehints_type:`\:py\:class\:\`str\``
  :param answer: Assistant's answer
  :type sql_query: :sphinx_autodoc_typehints_type:`\:py\:class\:\`str\` \| \:py\:obj\:\`None\``
  :param sql_query: SQL query that was executed (if any)
  :type row_count: :sphinx_autodoc_typehints_type:`\:py\:class\:\`int\``
  :param row_count: Number of rows returned

  :rtype: :sphinx_autodoc_typehints_type:`\:py\:obj\:\`None\``

.. py:method:: ChatSession.get_conversation_context() :module: urimai.core.chat_session

  Get formatted conversation context for agents.

  :rtype: :sphinx_autodoc_typehints_type:`\:py\:class\:\`str\``
  :returns: Formatted conversation history string

.. py:method:: ChatSession.get_recent_queries(limit=5) :module: urimai.core.chat_session

  Get recent query results.

  :type limit: :sphinx_autodoc_typehints_type:`\:py\:class\:\`int\``
  :param limit: Maximum number of queries to return

  :rtype: :sphinx_autodoc_typehints_type:`\:py\:class\:\`list\`\\ \\\[\:py\:class\:\`\~urimai.core.chat\_session.QueryResult\`\]`
  :returns: List of recent QueryResult objects

.. py:method:: ChatSession.clear_history() :module: urimai.core.chat_session

  Clear all conversation and query history.


  :rtype: :sphinx_autodoc_typehints_type:`\:py\:obj\:\`None\``

.. py:method:: ChatSession.get_message_count() :module: urimai.core.chat_session

  Get total number of messages in conversation.

  :rtype: :sphinx_autodoc_typehints_type:`\:py\:class\:\`int\``
  :returns: Number of messages

.. py:method:: ChatSession.get_query_count() :module: urimai.core.chat_session

  Get total number of queries executed.

  :rtype: :sphinx_autodoc_typehints_type:`\:py\:class\:\`int\``
  :returns: Number of queries

.. py:module:: urimai.core.context_manager

Context Manager - Unified source of truth for database context.

This module provides a centralized way to access database context including:

  • Schemas with enriched metadata

  • Database domain understanding

  • Column profiles

  • Sample data

All agents (query generation, analysis, quality checks) should get context from this manager to ensure consistency.

.. py:class:: ContextManager(db_name) :module: urimai.core.context_manager

Bases: :py:class:object

Manages and caches database context for consistent access across agents.

.. py:method:: ContextManager.initialize() :module: urimai.core.context_manager :async:

  Initialize the context manager by loading database info.


  :rtype: :sphinx_autodoc_typehints_type:`\:py\:obj\:\`None\``

.. py:method:: ContextManager.get_schemas() :module: urimai.core.context_manager :async:

  Get all schemas with enriched metadata.

  :rtype: :sphinx_autodoc_typehints_type:`\:py\:class\:\`list\`\\ \\\[\:py\:class\:\`\~urimai.storage.models.SchemaInfo\`\]`
  :returns: List of SchemaInfo objects

.. py:method:: ContextManager.get_database_context(force_refresh=False) :module: urimai.core.context_manager :async:

  Get or generate holistic database context.

  This provides domain understanding, business priorities, etc.
  Loads from persisted context first, falls back to LLM generation.
  Result is cached for performance.

  :type force_refresh: :sphinx_autodoc_typehints_type:`\:py\:class\:\`bool\``
  :param force_refresh: If True, regenerate context even if cached/persisted

  :rtype: :sphinx_autodoc_typehints_type:`\:py\:class\:\`\~urimai.agents.schema\_context\_agent.DatabaseContext\``
  :returns: DatabaseContext with domain understanding

.. py:method:: ContextManager.get_table_profile(table_name) :module: urimai.core.context_manager :async:

  Get statistical profile for a table.

  Profiles are cached for performance.

  :type table_name: :sphinx_autodoc_typehints_type:`\:py\:class\:\`str\``
  :param table_name: Name of the table

  :rtype: :sphinx_autodoc_typehints_type:`\:py\:data\:\`\~typing.Optional\`\\ \\\[\:py\:class\:\`\~urimai.storage.models.TableProfile\`\]`
  :returns: TableProfile if exists, None otherwise

.. py:method:: ContextManager.get_enriched_schema_for_table(table_name) :module: urimai.core.context_manager :async:

  Get enriched metadata for a specific table.

  :type table_name: :sphinx_autodoc_typehints_type:`\:py\:class\:\`str\``
  :param table_name: Name of the table

  :rtype: :sphinx_autodoc_typehints_type:`\:py\:data\:\`\~typing.Optional\`\\ \\\[\:py\:class\:\`dict\`\]`
  :returns: Enriched metadata dict or None if not available

.. py:method:: ContextManager.format_context_for_query_agent(query=None) :module: urimai.core.context_manager :async:

  Format database context for query generation agent.

  When a query is provided and the database has more than TABLE_SELECTION_THRESHOLD
  tables, an intelligent selection agent filters to only relevant tables.
  For small databases (<= threshold), all tables are used.

  :type query: :sphinx_autodoc_typehints_type:`\:py\:class\:\`str\` \| \:py\:obj\:\`None\``
  :param query: Optional user question for intelligent table selection

  :rtype: :sphinx_autodoc_typehints_type:`\:py\:class\:\`dict\``
  :returns: Dictionary with formatted context including selection metadata

.. py:method:: ContextManager.refresh() :module: urimai.core.context_manager :async:

  Refresh all cached context.

  Useful after schema changes or re-sync.


  :rtype: :sphinx_autodoc_typehints_type:`\:py\:obj\:\`None\``

.. py:module:: urimai.core.csv_ingestion

CSV to SQLite ingestion module with LLM-powered schema inference.

.. py:exception:: CSVIngestionError :module: urimai.core.csv_ingestion

Bases: :py:class:Exception

Custom exception for CSV ingestion errors.

.. py:function:: is_csv_file(path) :module: urimai.core.csv_ingestion

Check if file is a CSV file based on extension.

:type path: :sphinx_autodoc_typehints_type:\:py\:class\:\~pathlib._local.Path`` :param path: Path to file

:rtype: :sphinx_autodoc_typehints_type:\:py\:class\:\bool`` :returns: True if file has .csv or .tsv extension

.. py:function:: sanitize_identifier(name) :module: urimai.core.csv_ingestion

Sanitize table/column name for SQLite.

:type name: :sphinx_autodoc_typehints_type:\:py\:class\:\str`` :param name: Original name

:rtype: :sphinx_autodoc_typehints_type:\:py\:class\:\str`` :returns: Sanitized name (lowercase, alphanumeric + underscore only)

.. py:function:: read_csv_sample(csv_path, delimiter=’,’, encoding=’utf-8’, has_header=True, sample_size=50) :module: urimai.core.csv_ingestion :async:

Read sample data from CSV for schema inference with profiling.

:type csv_path: :sphinx_autodoc_typehints_type:\:py\:class\:\~pathlib._local.Path`    :param csv_path: Path to CSV file    :type delimiter: :sphinx_autodoc_typehints_type::py:class:`str`    :param delimiter: Column delimiter    :type encoding: :sphinx_autodoc_typehints_type::py:class:`str`    :param encoding: File encoding    :type has_header: :sphinx_autodoc_typehints_type::py:class:`bool`    :param has_header: Whether CSV has header row    :type sample_size: :sphinx_autodoc_typehints_type::py:class:`int`` :param sample_size: Number of rows to sample

:rtype: :sphinx_autodoc_typehints_type:\:py\:class\:\tuple`\ \[:py:class:`~typing.List`\ \[:py:class:`str`], :py:class:`~typing.Dict`\ \[:py:class:`str`, :py:class:`~typing.List`\ \[:py:data:`~typing.Any`]], :py:class:`~typing.Dict`\ \[:py:class:`str`, :py:class:`~typing.Dict`\ \[:py:class:`str`, :py:data:`~typing.Any`]]]` :returns: Tuple of (column_names, column_samples_dict, column_profiles_dict)

:raises CSVIngestionError: If CSV cannot be read

.. py:function:: convert_value_to_type(value, sqlite_type) :module: urimai.core.csv_ingestion

Convert a value to the appropriate type for SQLite insertion.

:type value: :sphinx_autodoc_typehints_type:\:py\:data\:\~typing.Any`    :param value: Raw value from CSV    :type sqlite_type: :sphinx_autodoc_typehints_type::py:class:`str`` :param sqlite_type: Target SQLite type (TEXT, INTEGER, REAL)

:rtype: :sphinx_autodoc_typehints_type:\:py\:data\:\~typing.Any`` :returns: Converted value or None

.. py:function:: create_sqlite_from_csv(csv_path, output_dir, table_name=None, delimiter=’,’, encoding=’utf-8’, has_header=True, chunksize=10000) :module: urimai.core.csv_ingestion :async:

Create SQLite database from CSV file with LLM-inferred schema.

Loads full CSV, profiles ALL data, and uses accurate statistics for schema inference.

:type csv_path: :sphinx_autodoc_typehints_type:\:py\:class\:\~pathlib._local.Path`    :param csv_path: Path to CSV file    :type output_dir: :sphinx_autodoc_typehints_type::py:class:`~pathlib._local.Path`    :param output_dir: Directory to store SQLite database    :type table_name: :sphinx_autodoc_typehints_type::py:data:`~typing.Optional`\ \[:py:class:`str`]    :param table_name: Custom table name (default: LLM-suggested or sanitized filename)    :type delimiter: :sphinx_autodoc_typehints_type::py:class:`str`    :param delimiter: Column delimiter    :type encoding: :sphinx_autodoc_typehints_type::py:class:`str`    :param encoding: File encoding    :type has_header: :sphinx_autodoc_typehints_type::py:class:`bool`    :param has_header: Whether CSV has header row    :type chunksize: :sphinx_autodoc_typehints_type::py:class:`int`` :param chunksize: Unused (kept for backward compatibility)

:rtype: :sphinx_autodoc_typehints_type:\:py\:class\:\tuple`\ \[:py:class:`~pathlib._local.Path`, :py:class:`~typing.Dict`\ \[:py:class:`str`, :py:data:`~typing.Any`]]` :returns: Tuple of (path_to_sqlite_db, ingestion_info)

:raises CSVIngestionError: If ingestion fails

.. py:function:: get_csv_info(csv_path, delimiter=’,’, encoding=’utf-8’) :module: urimai.core.csv_ingestion

Get basic information about a CSV file.

:type csv_path: :sphinx_autodoc_typehints_type:\:py\:class\:\~pathlib._local.Path`    :param csv_path: Path to CSV file    :type delimiter: :sphinx_autodoc_typehints_type::py:class:`str`    :param delimiter: Column delimiter    :type encoding: :sphinx_autodoc_typehints_type::py:class:`str`` :param encoding: File encoding

:rtype: :sphinx_autodoc_typehints_type:\:py\:class\:\~typing.Dict`\ \[:py:class:`str`, :py:data:`~typing.Any`]` :returns: Dictionary with CSV info (num_rows, num_columns, columns, size_mb)

.. py:module:: urimai.core.db_manager

Database manager wrapper for dq_db_manager.

.. py:class:: DatabaseManager(db_path) :module: urimai.core.db_manager

Bases: :py:class:object

Wrapper around dq_db_manager for SQLite operations.

.. py:method:: DatabaseManager.test_connection() :module: urimai.core.db_manager

  Test if database is accessible.

  :rtype: :sphinx_autodoc_typehints_type:`\:py\:class\:\`bool\``
  :returns: True if connection successful, False otherwise

.. py:method:: DatabaseManager.get_complete_metadata() :module: urimai.core.db_manager

  Extract complete database metadata.

  :rtype: :sphinx_autodoc_typehints_type:`\:py\:class\:\`dict\`\\ \\\[\:py\:class\:\`str\`\, \:py\:data\:\`\~typing.Any\`\]`
  :returns: Dictionary containing all metadata (tables, columns, constraints, etc.)

.. py:method:: DatabaseManager.get_table_names() :module: urimai.core.db_manager

  Get list of all table names.

  :rtype: :sphinx_autodoc_typehints_type:`\:py\:class\:\`list\`\\ \\\[\:py\:class\:\`str\`\]`
  :returns: List of table names

.. py:method:: DatabaseManager.get_table_columns(table_name) :module: urimai.core.db_manager

  Get column details for a specific table.

  :type table_name: :sphinx_autodoc_typehints_type:`\:py\:class\:\`str\``
  :param table_name: Name of the table

  :rtype: :sphinx_autodoc_typehints_type:`\:py\:class\:\`list\`\\ \\\[\:py\:class\:\`dict\`\\ \\\[\:py\:class\:\`str\`\, \:py\:data\:\`\~typing.Any\`\]\]`
  :returns: List of column details (name, type, nullable, default)

.. py:method:: DatabaseManager.get_sample_data(table_name, limit=5) :module: urimai.core.db_manager

  Get sample rows from a table.

  :type table_name: :sphinx_autodoc_typehints_type:`\:py\:class\:\`str\``
  :param table_name: Name of the table
  :type limit: :sphinx_autodoc_typehints_type:`\:py\:class\:\`int\``
  :param limit: Number of rows to retrieve (default: 5)

  :rtype: :sphinx_autodoc_typehints_type:`\:py\:class\:\`list\`\\ \\\[\:py\:class\:\`dict\`\\ \\\[\:py\:class\:\`str\`\, \:py\:data\:\`\~typing.Any\`\]\]`
  :returns: List of row dictionaries

.. py:method:: DatabaseManager.execute_query(query, params=None) :module: urimai.core.db_manager

  Execute a SQL query.

  :type query: :sphinx_autodoc_typehints_type:`\:py\:class\:\`str\``
  :param query: SQL query string
  :type params: :sphinx_autodoc_typehints_type:`\:py\:class\:\`list\`\\ \\\[\:py\:data\:\`\~typing.Any\`\] \| \:py\:obj\:\`None\``
  :param params: Optional query parameters (for parameterized queries)

  :rtype: :sphinx_autodoc_typehints_type:`\:py\:class\:\`list\`\\ \\\[\:py\:class\:\`dict\`\\ \\\[\:py\:class\:\`str\`\, \:py\:data\:\`\~typing.Any\`\]\]`
  :returns: List of result rows as dictionaries

.. py:method:: DatabaseManager.get_table_count(table_name) :module: urimai.core.db_manager

  Get row count for a table.

  :type table_name: :sphinx_autodoc_typehints_type:`\:py\:class\:\`str\``
  :param table_name: Name of the table

  :rtype: :sphinx_autodoc_typehints_type:`\:py\:class\:\`int\``
  :returns: Number of rows in the table

.. py:module:: urimai.core.export

Data dictionary export — Excel (.xlsx) and Markdown (.md) formats.

.. py:function:: gather_export_data(db_name, include_profile, include_quality, include_sample_data) :module: urimai.core.export :async:

Load all metadata for a database into a structured dict.

:rtype: :sphinx_autodoc_typehints_type:\:py\:class\:\dict`\ \[:py:class:`str`, :py:data:`~typing.Any`]`

.. py:function:: export_to_excel(data, output_path) :module: urimai.core.export

Write data dictionary to .xlsx using openpyxl.

:rtype: :sphinx_autodoc_typehints_type:\:py\:obj\:\None``

.. py:function:: export_to_markdown(data, output_path) :module: urimai.core.export

Write data dictionary to a single .md file.

:rtype: :sphinx_autodoc_typehints_type:\:py\:obj\:\None``

.. py:module:: urimai.core.interactive

Interactive REPL session for conversational database queries.

.. py:function:: run_interactive_session(db_name) :module: urimai.core.interactive :async:

Run interactive chat session for a database.

:type db_name: :sphinx_autodoc_typehints_type:\:py\:class\:\str`` :param db_name: Name of the registered database

:rtype: :sphinx_autodoc_typehints_type:\:py\:obj\:\None``

.. py:function:: handle_question(question, chat_session, context_manager, query_agent, analysis_agent, query_executor, planner_agent=None) :module: urimai.core.interactive :async:

Handle a user question in the interactive session.

:type question: :sphinx_autodoc_typehints_type:\:py\:class\:\str`    :param question: User's question    :type chat_session: :sphinx_autodoc_typehints_type::py:class:`~urimai.core.chat_session.ChatSession`    :param chat_session: Current chat session    :type context_manager:     :param context_manager: ContextManager with database context    :type query_agent: :sphinx_autodoc_typehints_type::py:class:`~urimai.agents.query_agent.QueryGenerationAgent`    :param query_agent: Query generation agent    :type analysis_agent: :sphinx_autodoc_typehints_type::py:class:`~urimai.agents.analysis_agent.ResultAnalysisAgent`    :param analysis_agent: Result analysis agent    :type query_executor: :sphinx_autodoc_typehints_type::py:class:`~urimai.core.query_executor.QueryExecutor`    :param query_executor: Query executor    :type planner_agent: :sphinx_autodoc_typehints_type::py:class:`~urimai.agents.query_planner_agent.QueryPlannerAgent` | :py:obj:`None`` :param planner_agent: Query planner agent for complex queries

:rtype: :sphinx_autodoc_typehints_type:\:py\:obj\:\None``

.. py:function:: handle_profile_command(table_name, db_info, store, schemas) :module: urimai.core.interactive :async:

Handle the /profile command to generate table profile.

:type table_name: :sphinx_autodoc_typehints_type:\:py\:class\:\str`    :param table_name: Name of the table to profile    :type db_info: :sphinx_autodoc_typehints_type::py:data:`~typing.Any`    :param db_info: Database information    :type store: :sphinx_autodoc_typehints_type::py:class:`~urimai.storage.metadata_store.MetadataStore`    :param store: Metadata store    :type schemas: :sphinx_autodoc_typehints_type::py:class:`list`\ \[:py:data:`~typing.Any`]` :param schemas: List of SchemaInfo objects

:rtype: :sphinx_autodoc_typehints_type:\:py\:obj\:\None``

.. py:function:: handle_quality_command(table_name, db_info, store, schemas) :module: urimai.core.interactive :async:

Handle the /quality command with agentic intelligence.

:type table_name: :sphinx_autodoc_typehints_type:\:py\:class\:\str`    :param table_name: Name of the table to assess    :type db_info: :sphinx_autodoc_typehints_type::py:data:`~typing.Any`    :param db_info: Database information    :type store: :sphinx_autodoc_typehints_type::py:class:`~urimai.storage.metadata_store.MetadataStore`    :param store: Metadata store    :type schemas: :sphinx_autodoc_typehints_type::py:class:`list`\ \[:py:data:`~typing.Any`]` :param schemas: List of SchemaInfo objects

:rtype: :sphinx_autodoc_typehints_type:\:py\:obj\:\None``

.. py:function:: handle_export_command(db_name, fmt=’xlsx’, output_path=None, include_sample_data=False, include_profile=True, include_quality=True) :module: urimai.core.interactive :async:

Handle the /export command inside an interactive chat session.

:rtype: :sphinx_autodoc_typehints_type:\:py\:obj\:\None``

.. py:module:: urimai.core.plan_executor

Plan executor - orchestrates multi-step query execution.

.. py:class:: PlanExecutor(planner, query_agent, analysis_agent, query_executor, context_manager) :module: urimai.core.plan_executor

Bases: :py:class:object

Executes multi-step query plans with live progress display.

.. py:method:: PlanExecutor.execute_plan(question, schema_info, conversation_context=None) :module: urimai.core.plan_executor :async:

  Execute a multi-step plan and return the final answer.

  :rtype: :sphinx_autodoc_typehints_type:`\:py\:class\:\`tuple\`\\ \\\[\:py\:class\:\`\~urimai.storage.models.SuccessAnswer\` \| \:py\:class\:\`\~urimai.storage.models.RetryWithFeedback\` \| \:py\:obj\:\`None\`\, \:py\:class\:\`\~urimai.storage.models.QueryPlan\` \| \:py\:obj\:\`None\`\, \:py\:data\:\`\~typing.Any\`\, \:py\:class\:\`\~urimai.storage.models.UsageStats\`\]`
  :returns: Tuple of (analysis_result, final_query_plan, exec_result, usage_stats)
            Returns (None, None, None, usage_stats) on unrecoverable failure.

.. py:module:: urimai.core.query_executor

Query execution with error handling and retry logic.

.. py:class:: QueryExecutionResult(success, data=None, error=None, row_count=0) :module: urimai.core.query_executor

Bases: :py:class:object

Result of query execution.

.. py:class:: QueryExecutor(db_manager) :module: urimai.core.query_executor

Bases: :py:class:object

Executes SQL queries with error handling.

.. py:method:: QueryExecutor.execute(sql_query) :module: urimai.core.query_executor :async:

  Execute a SQL query with timeout protection.

  :type sql_query: :sphinx_autodoc_typehints_type:`\:py\:class\:\`str\``
  :param sql_query: SQL query string to execute

  :rtype: :sphinx_autodoc_typehints_type:`\:py\:class\:\`\~urimai.core.query\_executor.QueryExecutionResult\``
  :returns: QueryExecutionResult with execution status and data/error

.. py:method:: QueryExecutor.validate_query(sql_query) :module: urimai.core.query_executor

  Validate SQL query basic structure.

  Generic validation that works across SQL databases (SQLite, PostgreSQL, MySQL, etc.)

  :type sql_query: :sphinx_autodoc_typehints_type:`\:py\:class\:\`str\``
  :param sql_query: SQL query to validate

  :rtype: :sphinx_autodoc_typehints_type:`\:py\:class\:\`tuple\`\\ \\\[\:py\:class\:\`bool\`\, \:py\:class\:\`str\` \| \:py\:obj\:\`None\`\]`
  :returns: Tuple of (is_valid, error_message)

.. py:module:: urimai.core.schema_extractor

Schema extraction and preparation for LLM enrichment.

.. py:class:: SchemaExtractor(db_manager) :module: urimai.core.schema_extractor

Bases: :py:class:object

Extracts and prepares schema metadata from databases.

.. py:method:: SchemaExtractor.extract_all_schemas(database_id, sample_rows=5) :module: urimai.core.schema_extractor

  Extract schema information for all tables.

  :type database_id: :sphinx_autodoc_typehints_type:`\:py\:class\:\`int\``
  :param database_id: ID of the database in metadata store
  :type sample_rows: :sphinx_autodoc_typehints_type:`\:py\:class\:\`int\``
  :param sample_rows: Number of sample rows to extract per table

  :rtype: :sphinx_autodoc_typehints_type:`\:py\:class\:\`list\`\\ \\\[\:py\:class\:\`\~urimai.storage.models.SchemaInfo\`\]`
  :returns: List of SchemaInfo objects

.. py:method:: SchemaExtractor.build_database_context(all_schemas) :module: urimai.core.schema_extractor

  Build a compact summary of all tables and their columns.

  :type all_schemas: :sphinx_autodoc_typehints_type:`\:py\:class\:\`list\`\\ \\\[\:py\:class\:\`\~urimai.storage.models.SchemaInfo\`\]`
  :param all_schemas: All schemas in the database

  :rtype: :sphinx_autodoc_typehints_type:`\:py\:class\:\`str\``
  :returns: Compact string listing all tables with their columns

.. py:method:: SchemaExtractor.prepare_for_enrichment(schema_info, database_context=None) :module: urimai.core.schema_extractor

  Prepare schema information for LLM enrichment.

  :type schema_info: :sphinx_autodoc_typehints_type:`\:py\:class\:\`\~urimai.storage.models.SchemaInfo\``
  :param schema_info: Schema information to prepare
  :type database_context: :sphinx_autodoc_typehints_type:`\:py\:class\:\`str\` \| \:py\:obj\:\`None\``
  :param database_context: Compact summary of all tables in the database

  :rtype: :sphinx_autodoc_typehints_type:`\:py\:class\:\`dict\`\\ \\\[\:py\:class\:\`str\`\, \:py\:data\:\`\~typing.Any\`\]`
  :returns: Dictionary formatted for LLM consumption

.. py:method:: SchemaExtractor.format_schema_for_query_agent(schemas) :module: urimai.core.schema_extractor

  Format schemas for query generation agent.

  :type schemas: :sphinx_autodoc_typehints_type:`\:py\:class\:\`list\`\\ \\\[\:py\:class\:\`\~urimai.storage.models.SchemaInfo\`\]`
  :param schemas: List of schema information

  :rtype: :sphinx_autodoc_typehints_type:`\:py\:class\:\`dict\`\\ \\\[\:py\:class\:\`str\`\, \:py\:data\:\`\~typing.Any\`\]`
  :returns: Dictionary formatted for query agent consumption

Profiling

.. py:module:: urimai.core.profiling

.. py:module:: urimai.core.profiling.column_profiler

Column-level profiling with statistics computation.

.. py:class:: ColumnProfiler() :module: urimai.core.profiling.column_profiler

Bases: :py:class:object

Computes statistical profiles for database columns.

.. py:method:: ColumnProfiler.profile_column(column_name, data_type, values) :module: urimai.core.profiling.column_profiler :staticmethod:

  Generate a complete statistical profile for a column.

  :type column_name: :sphinx_autodoc_typehints_type:`\:py\:class\:\`str\``
  :param column_name: Name of the column
  :type data_type: :sphinx_autodoc_typehints_type:`\:py\:class\:\`str\``
  :param data_type: SQL data type
  :type values: :sphinx_autodoc_typehints_type:`\:py\:class\:\`list\`\\ \\\[\:py\:data\:\`\~typing.Any\`\]`
  :param values: List of all values in the column

  :rtype: :sphinx_autodoc_typehints_type:`\:py\:class\:\`\~urimai.storage.models.ColumnProfile\``
  :returns: ColumnProfile with computed statistics

.. py:function:: profile_table(db_path, table_name, database_id, schema_info) :module: urimai.core.profiling.column_profiler :async:

Profile an entire table.

:type db_path: :sphinx_autodoc_typehints_type:\:py\:class\:\str`    :param db_path: Path to the database    :type table_name: :sphinx_autodoc_typehints_type::py:class:`str`    :param table_name: Name of the table to profile    :type database_id: :sphinx_autodoc_typehints_type::py:class:`int`    :param database_id: Database ID for storage    :type schema_info: :sphinx_autodoc_typehints_type:SchemaInfo` :param schema_info: SchemaInfo object with table metadata

:rtype: :sphinx_autodoc_typehints_type:TableProfile :returns: TableProfile with all column profiles

.. py:module:: urimai.core.profiling.role_classifier

Semantic role classification for database columns.

.. py:class:: RoleClassifier() :module: urimai.core.profiling.role_classifier

Bases: :py:class:object

Classifies columns into semantic roles based on patterns.

.. py:attribute:: RoleClassifier.PATTERNS :module: urimai.core.profiling.role_classifier :value: [(‘id’, ‘^(id|._id|pk|.pk)$’, 0.9), (‘foreign_key’, ‘^(fk.|._fk|._id)$’, 0.8), (‘email’, ‘^(email|e_mail|mail|email_address)$’, 0.95), (‘phone’, ‘^(phone|telephone|mobile|cell|phone_number)$’, 0.9), (‘name’, ‘^(name|full_name|first_name|last_name|fname|lname)$’, 0.85), (‘address’, ‘^(address|street|city|state|country|zip|postal)$’, 0.8), (‘age’, ‘^(age|years)$’, 0.9), (‘currency’, ‘^(price|cost|amount|salary|revenue|total|sum|balance)$’, 0.85), (‘date’, ‘^(date|.date|.at|created|updated|modified|timestamp)$’, 0.85), (‘year’, ‘^(year|yr)$’, 0.9), (‘month’, ‘^(month|mon)$’, 0.9), (‘day’, ‘^(day)$’, 0.85), (‘status’, ‘^(status|state|condition)$’, 0.9), (‘category’, ‘^(category|type|kind|class|group)$’, 0.85), (‘flag’, ‘^(is.|has.|._flag|active|enabled|verified)$’, 0.8), (‘description’, ‘^(description|desc|details|notes|comments|content)$’, 0.85), (‘url’, ‘^(url|link|website|webpage)$’, 0.9), (‘coordinate’, ‘^(lat|latitude|lon|longitude|coordinates|location)$’, 0.9), (‘quantity’, ‘^(quantity|qty|count|number|total)$’, 0.8), (‘percentage’, ‘^(._percent|._pct|.*_rate|percentage)$’, 0.85)]

.. py:method:: RoleClassifier.classify_column(profile, sample_values=None) :module: urimai.core.profiling.role_classifier :staticmethod:

  Classify a column's semantic role.

  :type profile: :sphinx_autodoc_typehints_type:`\:py\:class\:\`\~urimai.storage.models.ColumnProfile\``
  :param profile: ColumnProfile with statistics
  :type sample_values: :sphinx_autodoc_typehints_type:`\:py\:class\:\`list\`\\ \\\[\:py\:data\:\`\~typing.Any\`\]`
  :param sample_values: Optional sample of actual values for content-based classification

  :rtype: :sphinx_autodoc_typehints_type:`\:py\:class\:\`tuple\`\\ \\\[\:py\:class\:\`str\`\, \:py\:class\:\`float\`\]`
  :returns: Tuple of (role, confidence)

.. py:function:: enrich_profile_with_roles(profile, sample_values=None) :module: urimai.core.profiling.role_classifier

Enrich a column profile with role classification.

:type profile: :sphinx_autodoc_typehints_type:\:py\:class\:\~urimai.storage.models.ColumnProfile`    :param profile: ColumnProfile to enrich    :type sample_values: :sphinx_autodoc_typehints_type::py:class:`list`\ \[:py:data:`~typing.Any`]` :param sample_values: Optional sample values for content-based classification

:rtype: :sphinx_autodoc_typehints_type:\:py\:class\:\~urimai.storage.models.ColumnProfile`` :returns: ColumnProfile with inferred_role and role_confidence set

Quality

.. py:module:: urimai.core.quality

.. py:module:: urimai.core.quality.completeness_check

Completeness check - analyze missing values and null patterns.

.. py:class:: CompletenessChecker() :module: urimai.core.quality.completeness_check

Bases: :py:class:object

Checks data completeness by analyzing null values.

.. py:method:: CompletenessChecker.check(table_profile) :module: urimai.core.quality.completeness_check :staticmethod:

  Check completeness of a table.

  :type table_profile: :sphinx_autodoc_typehints_type:`\:py\:class\:\`\~urimai.storage.models.TableProfile\``
  :param table_profile: TableProfile with column statistics

  :rtype: :sphinx_autodoc_typehints_type:`\:py\:class\:\`tuple\`\\ \\\[\:py\:class\:\`float\`\, \:py\:class\:\`list\`\\ \\\[\:py\:class\:\`\~urimai.storage.models.QualityIssue\`\]\]`
  :returns: Tuple of (completeness_score, list of issues)

.. py:module:: urimai.core.quality.consistency_check

Consistency check - validate logical consistency and relationships.

.. py:class:: ConsistencyChecker(db_manager) :module: urimai.core.quality.consistency_check

Bases: :py:class:object

Checks data consistency by validating logical rules.

.. py:method:: ConsistencyChecker.check(table_name, table_profile) :module: urimai.core.quality.consistency_check

  Check consistency of a table.

  :type table_name: :sphinx_autodoc_typehints_type:`\:py\:class\:\`str\``
  :param table_name: Name of the table
  :type table_profile: :sphinx_autodoc_typehints_type:`\:py\:class\:\`\~urimai.storage.models.TableProfile\``
  :param table_profile: TableProfile with column statistics

  :rtype: :sphinx_autodoc_typehints_type:`\:py\:class\:\`tuple\`\\ \\\[\:py\:class\:\`float\`\, \:py\:class\:\`list\`\\ \\\[\:py\:class\:\`\~urimai.storage.models.QualityIssue\`\]\]`
  :returns: Tuple of (consistency_score, list of issues)

.. py:module:: urimai.core.quality.uniqueness_check

Uniqueness check - detect duplicates and uniqueness violations.

.. py:class:: UniquenessChecker(db_manager) :module: urimai.core.quality.uniqueness_check

Bases: :py:class:object

Checks data uniqueness by detecting duplicates.

.. py:method:: UniquenessChecker.check(table_name, table_profile) :module: urimai.core.quality.uniqueness_check

  Check uniqueness of a table.

  :type table_name: :sphinx_autodoc_typehints_type:`\:py\:class\:\`str\``
  :param table_name: Name of the table
  :type table_profile: :sphinx_autodoc_typehints_type:`\:py\:class\:\`\~urimai.storage.models.TableProfile\``
  :param table_profile: TableProfile with column statistics

  :rtype: :sphinx_autodoc_typehints_type:`\:py\:class\:\`tuple\`\\ \\\[\:py\:class\:\`float\`\, \:py\:class\:\`list\`\\ \\\[\:py\:class\:\`\~urimai.storage.models.QualityIssue\`\]\]`
  :returns: Tuple of (uniqueness_score, list of issues)

.. py:module:: urimai.core.quality.validity_check

Validity check - validate data types, ranges, and formats.

.. py:class:: ValidityChecker(db_manager) :module: urimai.core.quality.validity_check

Bases: :py:class:object

Checks data validity by validating types, ranges, and formats.

.. py:method:: ValidityChecker.check(table_name, table_profile) :module: urimai.core.quality.validity_check

  Check validity of a table.

  :type table_name: :sphinx_autodoc_typehints_type:`\:py\:class\:\`str\``
  :param table_name: Name of the table
  :type table_profile: :sphinx_autodoc_typehints_type:`\:py\:class\:\`\~urimai.storage.models.TableProfile\``
  :param table_profile: TableProfile with column statistics

  :rtype: :sphinx_autodoc_typehints_type:`\:py\:class\:\`tuple\`\\ \\\[\:py\:class\:\`float\`\, \:py\:class\:\`list\`\\ \\\[\:py\:class\:\`\~urimai.storage.models.QualityIssue\`\]\]`
  :returns: Tuple of (validity_score, list of issues)