RAG-Based Industry Classification System for Financial Services

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: Financial-services industry classification and business data quality

Ramp needed to replace fragmented, non-auditable industry classifications with a standardized system that could support compliance, risk assessment, sales targeting, portfolio monitoring, and product analytics.

Constraints:

Architecture

Ramp built an in-house RAG industry classifier that migrates customer classifications to NAICS. The system embeds business queries and NAICS knowledge-base entries, retrieves likely code candidates with similarity scoring from ClickHouse-stored embeddings, and uses an LLM to rerank/select the final code from the filtered candidate set. Kafka logs intermediate results for diagnostics and iteration, while internal services run embedding and LLM prompt evaluations.

Diagram confidence: reconstructed (reconstructed from prose).

flowchart LR
  business-record["Business record"] --> embedding-service["Embedding service"]
  business-record["Business record"] --> downstream-ramp-teams["Downstream Ramp 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-naics-recommendations["Candidate NAICS recommendations"]
  similarity-scorer["Similarity scorer"] --> kafka-diagnostic-log["Kafka diagnostic log"]
  candidate-naics-recommendations["Candidate NAICS recommendations"] --> llm-reranker["LLM reranker"]
  naics-knowledge-base["NAICS knowledge base"] --> llm-reranker["LLM reranker"]
  llm-reranker["LLM reranker"] --> final-naics-classification["Final NAICS classification"]
  naics-knowledge-base["NAICS knowledge base"] --> final-naics-classification["Final NAICS classification"]
  llm-reranker["LLM reranker"] --> kafka-diagnostic-log["Kafka diagnostic log"]
  kafka-diagnostic-log["Kafka diagnostic log"] --> evaluation-service["Evaluation service"]
  embedding-service["Embedding service"] --> evaluation-service["Evaluation service"]
  evaluation-service["Evaluation service"] --> llm-reranker["LLM reranker"]
  final-naics-classification["Final NAICS classification"] --> downstream-ramp-teams["Downstream Ramp teams"]
Drag to pan · scroll or use +/− to zoom · reconstructed from the source's described component topology

Components

Component Role Interacts with
Business record Customer/business profile requiring a standardized industry classification. Embedding service, Downstream Ramp teams
Embedding service Computes embeddings for business queries and supports classification experiments. Business record, Similarity scorer, Evaluation service
NAICS knowledge base Valid industry-code taxonomy and descriptions. ClickHouse embedding store, LLM reranker, Final NAICS classification
ClickHouse embedding store Fast storage for precomputed NAICS embeddings. NAICS knowledge base, Similarity scorer
Similarity scorer Generates candidate NAICS recommendations from embedding similarity. Embedding service, ClickHouse embedding store, Candidate NAICS recommendations, Kafka diagnostic log
Candidate NAICS recommendations Filtered candidate codes supplied to the LLM for final selection. Similarity scorer, LLM reranker
LLM reranker Selects the final valid NAICS code from retrieved recommendations. Candidate NAICS recommendations, NAICS knowledge base, Final NAICS classification, Kafka diagnostic log, Evaluation service
Final NAICS classification Auditable standardized industry code used across Ramp. LLM reranker, NAICS knowledge base, Downstream Ramp teams
Kafka diagnostic log Intermediate-result log for debugging and iteration. Similarity scorer, LLM reranker, Evaluation service
Evaluation service Internal embedding and LLM prompt evaluation path. Embedding service, LLM reranker, Kafka diagnostic log
Downstream Ramp teams Compliance, risk, sales, portfolio monitoring, and product analytics consumers. Business record, Final NAICS classification

Data flow

A business record enters the classifier. Internal embedding services encode the business query and compare it with precomputed NAICS embeddings stored in ClickHouse. Similarity scoring produces candidate recommendations. The LLM receives those candidates and chooses a final valid NAICS code rather than inventing a free-form category. Kafka captures intermediate retrieval and selection results for diagnosis, and downstream compliance, risk, sales, portfolio, and analytics workflows consume the standardized classification.

3 supporting quotes
“The RAG architecture consists of three main stages: calculating text embeddings of queries (businesses) and a knowledge base (NAICS codes), computing similarity scores to generate recommendations, and using an LLM to make a final prediction from the filtered recommendations.”summary, stated
“pre-computed knowledge base embeddings are stored in ClickHouse for fast similarity-based retrieval”summary, stated
“intermediate results are logged via Kafka for diagnostics and iteration.”summary, stated

Why this architecture

Ramp used RAG because retrieval could narrow a large standardized taxonomy to plausible candidates, while an LLM could make the final semantic choice. Building the system in-house gave Ramp control over costs, behavior, diagnostics, and iteration, and constraining output to NAICS codes made the classifier auditable enough for compliance and risk workflows.

3 supporting quotes
“Ramp chose to build a custom RAG system rather than rely on third-party solutions, citing their unique needs with complex data and the desire for full control over the model's behavior, iteration speed, and costs.”summary, stated
“the ability to constrain LLM outputs to valid NAICS codes from the knowledge base”summary, stated
“effectively transforming an open-ended generation problem into a multiple-choice question.”summary, stated

Models used: Embedding model · LLM reranker · RAG classifier

Scale

Alternatives considered (roads not taken)

Fragmented homegrown taxonomy

Rejected because: It created incorrect, generic, inconsistent, and non-auditable categories.

“The old system suffered from four key problems: obviously incorrect categories, overly generic classifications, inconsistent categorization of similar businesses, and lack of auditability or interpretability.”summary, stated

Third-party classification solutions

Rejected because: Ramp wanted control over behavior, iteration speed, and costs for complex business data.

“rather than rely on third-party solutions, citing their unique needs with complex data”summary, stated

Open-ended LLM category generation

Rejected because: A valid-code candidate set made the output auditable and constrained.

“transforming an open-ended generation problem into a multiple-choice question.”summary, stated

Only final-output logging

Rejected because: Ramp needed intermediate results to diagnose and iterate on pathological cases.

“intermediate results are logged via Kafka for diagnostics and iteration.”summary, stated

Patterns

rag-retrieval (retrieval)

Ramp retrieves likely NAICS candidates from an embedded knowledge base before LLM selection.

“combines embeddings-based retrieval with LLM-based re-ranking”summary, stated

retrieval-ranking (retrieval)

Similarity scoring and LLM reranking turn a broad taxonomy into ranked, filtered candidates.

“computing similarity scores to generate recommendations, and using an LLM to make a final prediction from the filtered recommendations.”summary, stated

structured-output-contract (interface)

The output contract is a valid NAICS code, not a free-form LLM label.

“A key architectural benefit highlighted is the ability to constrain LLM outputs to valid NAICS codes from the knowledge base, effectively transforming an open-ended generation problem into a multiple-choice question.”summary, stated

observability-tracing (operations)

Kafka captures intermediate classifier state for diagnostics and prompt iteration.

“intermediate results are logged via Kafka for diagnostics and iteration.”summary, stated

eval-driven-development (quality)

Ramp reports retrieval and final prediction accuracy improvements and runs internal embedding/LLM prompt evaluations.

“up to 60% in retrieval metrics and 5-15% in final prediction accuracy”summary, stated

Tradeoffs

Build a custom in-house model

Chose In-house RAG classifier over Third-party classification services.

Rationale: Ramp wanted control over complex data behavior, iteration speed, and costs.

“the desire for full control over the model's behavior, iteration speed, and costs.”summary, stated

Use retrieval plus reranking

Chose Embeddings-based retrieval followed by LLM-based re-ranking over Direct LLM classification.

Rationale: Retrieval constrains the LLM to valid taxonomy candidates while preserving semantic selection.

“custom RAG system that combines embeddings-based retrieval with LLM-based re-ranking”summary, stated

Standardize on NAICS

Chose External standardized taxonomy over Homegrown business categories.

Rationale: NAICS made industry data more consistent and communicable across teams and partners.

“enabled consistent cross-team usage of industry data for compliance, risk assessment, sales targeting, and product analytics.”summary, stated

Gotchas (what bit them)

A stitched taxonomy created inconsistent business decisions.

Root cause: Different teams relied on third-party data, sales-entered data, and self-reported categories with no shared standard.

Resolution: Migrate industry classification to a NAICS-based system consumed across teams.

“When different teams use different taxonomies or when classifications are inconsistent, it creates friction in decision-making”summary, stated

Broad categories were not actionable for risk or sales.

Root cause: A category like Professional Services grouped unrelated businesses.

Resolution: Use NAICS retrieval and LLM selection to produce more specific industry codes.

“For instance, WizeHire, a hiring platform, was classified as "Professional Services"—a category so broad it included law firms, dating apps, and consulting firms, making it unhelpful for risk profiling or sales targeting.”summary, stated

Open-ended classification would undermine auditability.

Root cause: LLMs can generate labels outside the official taxonomy.

Resolution: Constrain generation to candidates drawn from the NAICS knowledge base.

“This is an important LLMOps pattern for production systems where output validity is critical.”summary, stated

Pathological cases need intermediate diagnostics.

Root cause: Final labels alone do not show whether retrieval, candidate ranking, or LLM selection failed.

Resolution: Log intermediate results via Kafka for diagnostics and iteration.

“intermediate results are logged via Kafka for diagnostics and iteration.”summary, stated

Evaluation

Ramp evaluated the system with retrieval metrics, final prediction accuracy, internal embedding and prompt evaluations, and diagnostic analysis of intermediate retrieval/reranking results.

Metrics: retrieval metric improvement · final prediction accuracy · prompt evaluation results · pathological-case diagnostics · cross-team classification consistency

“significant improvements in classification accuracy (up to 60% in retrieval metrics and 5-15% in final prediction accuracy)”summary, stated
“internal services handle embeddings and LLM prompt evaluations”summary, stated

Outcomes

Concrete anchors include up to 60% retrieval-metric improvement, 5-15% final-prediction improvement, three RAG stages, ClickHouse retrieval storage, Kafka diagnostics, and downstream use across compliance, risk, sales, and analytics.

“achieved significant improvements in classification accuracy (up to 60% in retrieval metrics and 5-15% in final prediction accuracy)”summary, stated
“gained full control over the model's behavior and costs”summary, stated