RAG-Based Industry Classification System for Customer Segmentation

ramp · Finance · 2025 · source Agentic: no · promotional bias: low · source-backed · extracted with prompt 0.5.6 (schema v2)

Generated from extraction.json — do not edit by hand. Every claim cites verbatim source evidence; stated means the quote directly asserts the claim, implied means it supports it indirectly.

Problem

Domain: Customer industry classification and segmentation

Ramp needed a consistent, auditable way to classify customers by industry for compliance, portfolio monitoring, sales targeting, and product analytics after homegrown taxonomies created inaccurate, overly generic, and inconsistent categories.

Constraints:

Architecture

Ramp replaced its homegrown classification patchwork with an in-house RAG classifier over NAICS codes. The system computes embeddings for business queries and the NAICS knowledge base, uses similarity scores to retrieve candidate recommendations from precomputed embeddings stored in ClickHouse, and asks an LLM to choose a final NAICS code from the filtered candidates. Internal services handle embeddings and prompt evaluation, Kafka logs intermediate results for diagnostics, and the valid-code knowledge base constrains output to an auditable taxonomy.

Diagram confidence: reconstructed (reconstructed from prose).

flowchart LR
  customer-business-record["Customer business record"] --> embedding-service["Embedding service"]
  customer-business-record["Customer business record"] --> downstream-business-teams["Downstream business teams"]
  naics-knowledge-base["NAICS knowledge base"] --> clickhouse-embedding-store["ClickHouse embedding store"]
  clickhouse-embedding-store["ClickHouse embedding store"] --> similarity-scorer["Similarity scorer"]
  embedding-service["Embedding service"] --> similarity-scorer["Similarity scorer"]
  similarity-scorer["Similarity scorer"] --> candidate-recommendations["Candidate recommendations"]
  candidate-recommendations["Candidate recommendations"] --> llm-selector["LLM selector"]
  naics-knowledge-base["NAICS knowledge base"] --> llm-selector["LLM selector"]
  llm-selector["LLM selector"] --> valid-naics-output["Valid NAICS output"]
  naics-knowledge-base["NAICS knowledge base"] --> valid-naics-output["Valid NAICS output"]
  valid-naics-output["Valid NAICS output"] --> downstream-business-teams["Downstream business teams"]
  similarity-scorer["Similarity scorer"] --> kafka-diagnostic-log["Kafka diagnostic log"]
  llm-selector["LLM selector"] --> kafka-diagnostic-log["Kafka diagnostic log"]
  kafka-diagnostic-log["Kafka diagnostic log"] --> prompt-evaluation-service["Prompt evaluation service"]
  embedding-service["Embedding service"] --> prompt-evaluation-service["Prompt evaluation service"]
  prompt-evaluation-service["Prompt evaluation service"] --> llm-selector["LLM selector"]
Drag to pan · scroll or use +/− to zoom · reconstructed from the source's described component topology

Components

Component Role Interacts with
Customer business record Business profile or customer information that needs an industry classification. Embedding service, Downstream business teams
Embedding service Computes embeddings for incoming businesses and supports prompt-evaluation workflows. Customer business record, Similarity scorer, Prompt evaluation service
NAICS knowledge base Standardized industry taxonomy used as the valid classification universe. ClickHouse embedding store, LLM selector, Valid NAICS output
ClickHouse embedding store Stores precomputed NAICS embeddings for fast similarity-based retrieval. NAICS knowledge base, Similarity scorer
Similarity scorer Compares business embeddings to NAICS embeddings and generates candidate recommendations. Embedding service, ClickHouse embedding store, Candidate recommendations
Candidate recommendations Filtered candidate NAICS codes supplied to the LLM. Similarity scorer, LLM selector
LLM selector Chooses the final NAICS classification from filtered candidates. Candidate recommendations, NAICS knowledge base, Valid NAICS output, Prompt evaluation service
Valid NAICS output Standardized, interpretable industry classification consumed across Ramp. LLM selector, NAICS knowledge base, Downstream business teams
Kafka diagnostic log Intermediate-result logging for debugging pathological cases and iterating prompts. Similarity scorer, LLM selector, Prompt evaluation service
Prompt evaluation service Internal evaluation path for prompt changes and classification behavior. Embedding service, LLM selector, Kafka diagnostic log
Downstream business teams Compliance, risk, sales, marketing, product analytics, and portfolio teams using the standardized classifications. Customer business record, Valid NAICS output

Data flow

A customer or business record enters Ramp's classification flow. Internal services create embeddings for the query and compare them with precomputed NAICS knowledge-base embeddings stored in ClickHouse. Similarity search produces candidate NAICS recommendations. The LLM receives the filtered candidates and selects a final classification rather than generating an unconstrained label. Intermediate results flow to Kafka so the team can diagnose pathological cases and iterate prompts, while downstream compliance, risk, sales, marketing, and analytics teams consume the standardized industry data.

3 supporting quotes
“The RAG architecture consists of three main stages: calculating text embeddings of queries and knowledge base, computing similarity scores to generate recommendations, and using an LLM to make final predictions from filtered recommendations.”summary, stated
“knowledge base embeddings are pre-computed and stored in ClickHouse for fast retrieval using similarity scores.”summary, stated
“Intermediate results are logged using Kafka to enable diagnosis of pathological cases and prompt iteration.”summary, stated

Why this architecture

Ramp chose in-house RAG because it needed the interpretability of a standardized taxonomy, the flexibility to control cost and behavior, and the validity guarantee of choosing from NAICS candidates instead of generating arbitrary labels. Retrieval narrows the taxonomy to plausible codes; the LLM handles semantic selection among those candidates; logging and prompt evaluation give the team a way to diagnose failures.

3 supporting quotes
“They solved this by building an in-house RAG (Retrieval-Augmented Generation) system that migrated all industry classification to standardized NAICS codes”summary, stated
“provided interpretable results with full control over the classification process.”summary, stated
“The entire system is designed to constrain LLM outputs to the domain of valid NAICS codes”summary, stated

Models used: Embedding model · LLM selector · RAG classifier

Scale

Alternatives considered (roads not taken)

Continue homegrown taxonomies

Rejected because: They produced inaccurate, generic, inconsistent, and non-auditable classifications.

“homegrown taxonomies that were inaccurate, too generic, and not auditable.”summary, stated

Use stitched third-party, sales-entered, and self-reported labels

Rejected because: The combined sources produced multiple sources of truth across teams.

“stitched together third-party data, sales-entered information, and customer self-reporting.”summary, stated

Let the LLM generate industry labels freely

Rejected because: Ramp needed outputs constrained to valid NAICS codes for interpretability and consistency.

“constrain LLM outputs to the domain of valid NAICS codes, essentially transforming an open-ended generation problem into a multiple-choice selection task.”summary, stated

Rely on third-party classification solutions

Rejected because: The in-house system gave Ramp full control over behavior, iteration, costs, and interpretability.

“building an in-house RAG (Retrieval-Augmented Generation) system”summary, stated

Patterns

rag-retrieval (retrieval)

Ramp retrieves candidate NAICS codes from embedded taxonomy knowledge before asking an LLM to select the final classification.

“embedding-based retrieval and LLM-based selection.”summary, stated

retrieval-ranking (retrieval)

Similarity scoring ranks candidate NAICS recommendations before LLM selection.

“The RAG architecture consists of three main stages: calculating text embeddings of queries and knowledge base, computing similarity scores to generate recommendations, and using an LLM to make final predictions from filtered recommendations.”summary, stated

structured-output-contract (interface)

The model output is constrained to valid NAICS codes, turning classification into a multiple-choice selection task.

“The entire system is designed to constrain LLM outputs to the domain of valid NAICS codes, essentially transforming an open-ended generation problem into a multiple-choice selection task.”summary, stated

observability-tracing (operations)

Kafka logs intermediate retrieval and selection results for diagnostics and prompt iteration.

“Intermediate results are logged using Kafka to enable diagnosis of pathological cases and prompt iteration. The entire system is designed to constrain LLM outputs to the domain of valid NAICS codes, essentially transforming an open-ended generation problem into a multiple-choice selection task.”summary, stated

data-quality-loop (quality)

The system turns inconsistent taxonomy data into a standardized, auditable classification layer used across teams.

“The system improved data quality, enabled consistent cross-team communication, and provided interpretable results”summary, stated

Tradeoffs

Build an in-house classifier

Chose Custom RAG over NAICS codes over External or stitched classification sources.

Rationale: Ramp gained control over model behavior, interpretability, and classification process consistency.

“The system improved data quality, enabled consistent cross-team communication, and provided interpretable results with full control over the classification process.”summary, stated

Use retrieval before LLM selection

Chose Embedding-based candidate retrieval plus LLM final prediction over Direct LLM classification across the whole taxonomy.

Rationale: Retrieval narrows the output space and makes the LLM choose from plausible valid codes.

“The RAG architecture consists of three main stages: calculating text embeddings of queries and knowledge base, computing similarity scores to generate recommendations, and using an LLM to make final predictions from filtered recommendations.”summary, stated

Log intermediate results

Chose Kafka diagnostics over Only final classifications.

Rationale: Intermediate logging supports diagnosis of pathological cases and prompt iteration.

“Intermediate results are logged using Kafka to enable diagnosis of pathological cases and prompt iteration. The entire system is designed to constrain LLM outputs to the domain of valid NAICS codes, essentially transforming an open-ended generation problem into a multiple-choice selection task.”summary, stated

Gotchas (what bit them)

Homegrown taxonomies became multiple sources of truth.

Root cause: Ramp stitched together third-party data, sales-entered information, and self-reported customer labels.

Resolution: Move all industry classification to a standardized NAICS-based system.

“a patchwork of homegrown taxonomies that created inconsistencies, inaccuracies, and multiple sources of truth across different teams.”summary, stated

Overly generic categories were not useful for business decisions.

Root cause: Labels like Professional Services covered very different business types.

Resolution: Use NAICS candidates and LLM selection to produce more specific, interpretable classes.

“WizeHire, a hiring platform, was classified broadly as "Professional Services" - a category so generic it could encompass law firms, dating apps, and consulting firms”summary, stated

Unconstrained LLM classification would be hard to audit.

Root cause: Open-ended generation can produce invalid or inconsistent labels outside the taxonomy.

Resolution: Constrain the final decision to valid NAICS codes from retrieved candidates.

“The entire system is designed to constrain LLM outputs to the domain of valid NAICS codes, essentially transforming an open-ended generation problem into a multiple-choice selection task.”summary, stated

Evaluation

Ramp evaluated classification behavior through internal embedding and LLM prompt evaluations, diagnostic logging of intermediate results, and business validation of standardized NAICS outputs.

Metrics: classification quality · retrieval recommendation quality · prompt evaluation results · pathological-case diagnosis · cross-team consistency

“Internal services handle embeddings for new businesses and LLM prompt evaluations, while knowledge base embeddings are pre-computed and stored in ClickHouse for fast retrieval using similarity scores.”summary, stated
“Intermediate results are logged using Kafka to enable diagnosis of pathological cases and prompt iteration. The entire system is designed to constrain LLM outputs to the domain of valid NAICS codes, essentially transforming an open-ended generation problem into a multiple-choice selection task.”summary, stated

Outcomes

The case anchors scale through standardized NAICS migration, three RAG stages, ClickHouse precomputed embeddings, Kafka intermediate logging, and downstream usage across compliance, portfolio monitoring, sales targeting, and product analytics.

“The system improved data quality, enabled consistent cross-team communication, and provided interpretable results with full control over the classification process.”summary, stated
“migrate all industry classification to standardized NAICS (North American Industry Classification System) codes.”summary, stated