Build a Production LLM Integration for Customer Support on GCP A developer published a guide for building a production-grade customer-support LLM integration on Google Cloud Platform, wiring Vertex AI, Cloud Storage, Dataflow, Matching Engine, Cloud Run, and Firestore into an end-to-end retrieval-augmented pipeline. The guide covers ingesting PDFs, HTML, and markdown via an Apache Beam/Dataflow pipeline with Tika-based text extraction, generating embeddings, populating a managed vector index, and deploying a stateless Cloud Run API with least-privilege IAM roles. It also details cost-control tactics, monitoring dashboards, and a production-ops checklist to keep the bot within latency and budget constraints. A single mis-configured retrieval request can flood your GCP bill and return irrelevant answers, turning a promising support bot into a costly liability. An LLM integration that respects latency, cost, and data-privacy constraints is therefore the only viable path for a production-grade customer-support assistant. In this guide you’ll build a end-to-end support bot that safely consumes your knowledge base, serves accurate answers, and stays within budget. We start with a full-stack architecture map that ties Vertex AI, Cloud Storage, and Cloud Run together. Next, you’ll assemble a scalable pipeline that crawls documents, creates vector embeddings, and populates a managed vector store. We then cover model hosting, retrieval, and a CI/CD workflow that automates model refreshes and API deployments. Finally, you’ll learn concrete cost-control tactics, monitoring dashboards, and a production-ops checklist that lets you scale the bot without surprise outages. | Service | Role in the support bot | Typical IAM role least-privilege | |---|---|---| | Cloud Storage | Stores the original knowledge-base PDFs, HTML, or markdown files. Acts as the source bucket for the ETL pipeline. | roles/storage.objectViewer on the bucket | | Dataflow | Executes a Beam pipeline that extracts text, cleans it, creates embeddings via Vertex AI’s embedding model , and writes vectors to Matching Engine. Also writes the raw chunks to a Firestore collection for debugging. | roles/dataflow.worker , roles/vertexai.viewer | | Vertex AI Matching Engine | Persistent vector index ≈ 10-100 M vectors used for fast nearest-neighbor lookup during retrieval. | roles/aiplatform.matchingEngineAdmin | | Vertex AI LLM endpoint | Hosts the generative model e.g., PaLM-2 or a fine-tuned T5 . Provides two endpoints: predict for generation and embed for query embeddings. | roles/aiplatform.modelViewer , roles/aiplatform.endpointUser | | Cloud Run API layer | Stateless HTTP front-end that receives user queries, orchestrates retrieval, calls the LLM, and returns the answer. Deployed in a fully managed VPC-connected service. | roles/run.invoker for internal callers, roles/run.serviceAgent for the service itself | | Cloud SQL / Firestore | Persists session context e.g., last 3 user turns and audit logs. Firestore is preferred for low-latency key-value access; Cloud SQL can host relational metadata if needed. | roles/cloudsql.client or roles/datastore.user | dataflow-sa@project.iam.gserviceaccount.com , run-sa@project.iam.gserviceaccount.com and enforce With these pieces wired together, you have a production-grade, GCP-native stack that isolates data, scales retrieval, and serves LLM-driven answers with minimal operational friction. gs://support-docs and enable support-ingest . python import apache beam as beam from apache beam.io.gcp.pubsub import ReadFromPubSub from apache beam.io.fileio import MatchFiles, ReadMatches from apache beam.options.pipeline options import PipelineOptions options = PipelineOptions streaming=True, project='my-gcp-project', temp location='gs://tmp-bucket/temp', region='us-central1' with beam.Pipeline options=options as p: p | 'ReadPubSub' ReadFromPubSub topic='projects/my-gcp-project/topics/support-ingest' | 'ParsePath' beam.Map lambda msg: msg.decode 'utf-8' | 'MatchFiles' MatchFiles 'gs://support-docs/ ' | 'ReadFiles' ReadMatches | 'ExtractText' beam.ParDo ExtractTextFn Tika-based parser Gotcha: Beam’s default ReadAllFromText cannot handle binary PDFs; use Apache Tika or pdfminer.six inside a DoFn to pull out clean text for all three formats. spm unigram.model inside the same DoFn . python import sentencepiece as spm sp = spm.SentencePieceProcessor sp.Load 'gs://models/spm unigram.model' def chunk text, size=200, overlap=30 : ids = sp.EncodeAsIds text for i in range 0, len ids , size - overlap : yield sp.DecodeIds ids i:i+size projects/.../locations/us-central1/endpoints/12345 . ParDo . Batch up to 64 chunks per request to stay within latency budgets and reduce RPC overhead. python from google.cloud import aiplatform endpoint = aiplatform.Endpoint '12345' def embed chunk : response = endpoint.predict instances= {'content': chunk} return response.predictions 0 'embedding' | Destination | Purpose | Write method | |---|---|---| | Vertex AI Matching Engine | Fast nearest-neighbor lookup for support queries | IndexServiceClient.upsert datapoints batch up to 1000 | | Cloud SQL PostgreSQL | Auditable metadata – source file, chunk offset, processing timestamps | JDBC sink beam.io.jdbc.WriteToJdbc | Include columns like doc id , chunk index , embedding id , ingest ts . Use a composite primary key doc id , chunk index so re-processing the same file simply overwrites existing rows without duplication. .processed . For each missing marker, it publishes the object path to gcloud functions deploy trigger ingest \ --runtime python311 \ --trigger-http \ --entry-point run ingest \ --set-env-vars BUCKET=support-docs,TOPIC=support-ingest Key gotchas gs://support-docs/