Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

ClickHouse 12 min read Announcement mediumAdept

AI Functions in ClickHouse: Upgrade your SQL to the AI age

ClickHouse's beta AI Functions call LLM and embedding providers directly from SQL. They include aiClassify, aiExtract, aiGenerate, aiTranslate, aiFilter, aiRedact, aiEmbed and aiSimilarity, added across releases 26.4 to 26.8, and they make one HTTP request per row (batched for embeddings) and return native ClickHouse values. Setup on OSS uses named collections for credentials and works with any OpenAI-compatible endpoint, including local models via Ollama. Examples on the Hacker News dataset show classification, LLM predicates in WHERE, summarization, translation and an in-database RAG pipeline built on materialized-view embeddings and vector indexes. Per-query quotas on API calls and input/output tokens cap spend: call limits are exact, token limits can overshoot by one in-flight request per thread, a soft-stop mode returns partial results, and actual usage is visible in system.query_log ProfileEvents.

Related posts

  • Using ClickHouse UDFs to integrate with OpenAI models

    ClickHouse mediumAdept

    ClickHouse executable user-defined functions can call the OpenAI chat completions API from SQL, adding sentiment labels or extracted entities to rows at insert or query time. The walkthrough starts with a Bash script and then moves to a Python script with retries and exponential backoff, configured as an executable_pool with chunk headers for parallel, batched invocation. Applying the UDF only to final result rows keeps API calls few, since OpenAI latency far exceeds ClickHouse query time. Aggregating sentiment across many rows means thousands of API calls, so rate limits and latency become the main constraints.

  • Building a RAG pipeline for Google Analytics with ClickHouse and Amazon Bedrock

    ClickHouse mediumAdept

    A natural language interface over raw Google Analytics data stored in ClickHouse is built as a multi-step RAG pipeline that generates SQL from user questions using Amazon Bedrock models. Drawing on text-to-SQL research such as DAIL-SQL from the Spider benchmark, the design retrieves similar example questions and their SQL via vector embeddings, because concepts like "returning users" cannot be inferred from the schema alone. Embeddings come from a Python executable-pool UDF calling Titan embeddings, with retries and backoff for Bedrock quotas, and are invoked at query or insert time. ClickHouse serves as both the vector store and the analytics database, and specific settings are given to parallelize embedding generation on small tables.

  • Building an agentic app with ClickHouse MCP and CopilotKit

    ClickHouse mediumAdept

    A natural-language analytics dashboard for UK property prices can be built by combining an LLM (Claude Sonnet 3.7), the ClickHouse MCP Server and CopilotKit in a Next.js app. The LLM turns a prompt into SQL, CopilotKit's MCP client runs it against ClickHouse over SSE, and the model then calls a `generateChart` action defined with `useCopilotAction` to render the result via ECharts. The walkthrough covers swapping in the Anthropic adapter, running the MCP server with fastmcp, and sharing chart state with `useCopilotReadable`. It recommends a read-only ClickHouse user with restricted databases, quotas and a limited settings profile so the model cannot reach data or run queries beyond what is intended.

  • How Fetch built its flexible agentic analytics tool on ClickHouse Cloud

    ClickHouse easyNovice

    Fetch built FAST, a conversational BI agent that lets non-technical sales teams query receipt purchase data in plain language, on ClickHouse Cloud ingesting 150 billion rows (6.5 TB compressed) a day. Ad hoc queries such as same-receipt basket intersections scan hundreds of millions of rows in under a second, and median agent response time is 1.9 seconds across about 500 daily queries. The team picked ClickHouse for its ad hoc query speed, compute isolation between concurrent queries and simple scaling. A nightly pipeline copies data from Snowflake to S3, loads it via ClickPipes into a new versioned wide table, then repoints a view at it. That keeps LLM-generated queries stable and makes rollback trivial, at the cost of skipping incremental loads.

  • Agentic coding with ClickHouse. One person, one data stack, one full-stack application

    ClickHouse easyNovice

    A ClickHouse Solutions Architect with no frontend or backend background built ClickShop, a full-stack retail analytics demo, in a couple of days using Cursor. The stack uses Next.js on Vercel with per-persona workspaces, PostgreSQL for transactions synced to ClickHouse via ClickPipes CDC, and a Bronze/Silver/Gold medallion layout built on materialized views. On top sit 18 LibreChat agents, plus two observability layers: Langfuse for LLM tracing and cost, and ClickStack over OpenTelemetry for infrastructure. Open source components, Cursor skills and MCP database connectors reduce AI guesswork, though iteration, review and token costs remain significant.

The quest for software engineering knowledge.

Look:
Layout: