Skip to main content
Use the Database Connector to ingest the result of a SQL SELECT query from a MySQL or PostgreSQL database into the mAItion knowledge base. Each returned row becomes one indexed document.

What It Does

  • runs a pre-configured SELECT query against a MySQL or PostgreSQL database
  • indexes the content column of every row as the body of a document
  • optionally stores extra columns as document metadata
  • runs ingestion on configurable schedules
One connector type covers both databases. Add one source for each database you want to ingest.

Query Requirements

The query must return these four columns. Use SQL AS aliases to map your own column names to them: If the query does not return one of these columns, the ingestion fails and the error names the missing columns. A row is indexed again when its updated_at value changes. Make sure updated_at changes every time content changes, otherwise edits to a row can be missed. Example with aliases:
Use a read-only database account in the connection string. The connector only checks that the query starts with SELECT or WITH, so it cannot guarantee that a query does not change data.

Required Environment Variables

Set these in .env.rag:
  • DB_POSTGRES1_CONNECTION_STRING: SQLAlchemy connection string for the PostgreSQL source (example: postgresql+psycopg2://user:password@db-host:5432/dbname)
  • DB_POSTGRES1_SCHEDULES: ingestion interval in seconds (default is 3600)
  • DB_MYSQL1_CONNECTION_STRING: SQLAlchemy connection string for the MySQL source (example: mysql+pymysql://user:password@db-host:3306/dbname)
  • DB_MYSQL1_SCHEDULES: ingestion interval in seconds (default is 3600)
The database drivers ship with the RAG image. Use a host name that the mAItion containers can reach, because localhost points to the container itself. URL-encode special characters in the password (for example @ becomes %40).

config.yaml Example

.env.rag Example

Configuration Reference

Multiple Database Sources

Add more sources entries (postgres2, mysql2, etc) with separate env vars per source.