---
title: "Building a RAG pipeline for Google Analytics with ClickHouse and Amazon Bedrock"
description: "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."
url: "https://swe.quest/articles/building-a-rag-pipeline-for-google-analytics-with-clickhouse-and-amazon-bedrock-e2945701d51424da"
canonical: "https://clickhouse.com/blog/retrieval-augmented-generation-rag-with-clickhouse-bedrock"
source: "ClickHouse"
published: "2023-11-21"
difficulty: "medium"
kind: "How-to"
reading_minutes: 26
tags: ["rag","llms","vector-search","analytics","cloud"]
---

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

A post on [ClickHouse](https://swe.quest/sources/clickhouse.md), published 2023-11-21, 26 min read, How-to. Original: [https://clickhouse.com/blog/retrieval-augmented-generation-rag-with-clickhouse-bedrock](https://clickhouse.com/blog/retrieval-augmented-generation-rag-with-clickhouse-bedrock)

## Summary

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.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [RAG & retrieval](https://swe.quest/tags/rag.md) (AI & ML)
- [LLMs](https://swe.quest/tags/llms.md) (AI & ML)
- [Vector search](https://swe.quest/tags/vector-search.md) (Data & databases)
- [Analytics & OLAP](https://swe.quest/tags/analytics.md) (Data & databases)
- [Cloud platforms](https://swe.quest/tags/cloud.md) (Infrastructure)

## Prerequisites

- SQL basics ([easy posts on SQL](https://swe.quest/tags/sql.md?difficulty=easy))
- vector embeddings ([easy posts on RAG & retrieval](https://swe.quest/tags/rag.md?difficulty=easy))
- LLM prompting ([easy posts on LLMs](https://swe.quest/tags/llms.md?difficulty=easy))
- ClickHouse basics ([easy posts on Analytics & OLAP](https://swe.quest/tags/analytics.md?difficulty=easy))

## Keywords

ClickHouse, Amazon Bedrock, Google Analytics, DAIL-SQL, Spider, Titan Embeddings

## Related posts

- [AI Functions in ClickHouse: Upgrade your SQL to the AI age](https://swe.quest/articles/ai-functions-in-clickhouse-upgrade-your-sql-to-the-ai-age-11cec6552950f306.md): ClickHouse · 2026-09-11 · Medium · 12 min read · LLMs, SQL, RAG & retrieval, Analytics & OLAP, Cost optimization
  ClickHouse's beta AI Functions call LLM and embedding providers directly from SQL.
- [ChatGPT plugins now support Postgres & Supabase](https://swe.quest/articles/chatgpt-plugins-now-support-postgres-supabase-db9d10a95a8d96b9.md): Supabase · 2023-05-25 · Medium · 7 min read · RAG & retrieval, Vector search, PostgreSQL, LLMs
  Supabase contributed Postgres and Supabase datastore providers to OpenAI's ChatGPT Retrieval Plugin, storing text-embedding-ada-002 embeddings in pgvector.
- [Text2SQL using Hugging Face Dataset Viewer API and Motherduck DuckDB-NSQL-7B](https://swe.quest/articles/text2sql-using-hugging-face-dataset-viewer-api-and-motherduck-duckdb-nsql-7b-7024872a0cc79ab7.md): Hugging Face · 2024-04-04 · Medium · 7 min read · LLMs, SQL, Analytics & OLAP, Python
  DuckDB-NSQL-7B, a Llama-2-7B model fine-tuned on general SQL and then DuckDB text-to-SQL pairs, can turn plain-language questions into DuckDB SQL that runs directly against Hugging Face datasets.
- [Building an agentic app with ClickHouse MCP and CopilotKit](https://swe.quest/articles/building-an-agentic-app-with-clickhouse-mcp-and-copilotkit-8a892e5035cf8b12.md): ClickHouse · 2025-06-12 · Medium · 9 min read · AI agents, Analytics & OLAP, React, LLMs
  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.
- [How Fetch built its flexible agentic analytics tool on ClickHouse Cloud](https://swe.quest/articles/how-fetch-built-its-flexible-agentic-analytics-tool-on-clickhouse-cloud-284f56cdf33d7d26.md): ClickHouse · 2026-07-28 · Easy · 6 min read · Analytics & OLAP, AI agents, Data pipelines, LLMs
  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.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
