---
title: "Improving Retrieval on Ramp with Transaction Embeddings"
description: "Ramp developed transaction embeddings to help automate accounting coding, where employees choose general ledger (GL) categories for transactions. The model represents enriched transaction features—such as merchant, category, department, location, amount, memo, spend program, and trip—as stringified documents labeled with chart-of-accounts codes. Starting from a pre-trained encoder, it is fine-tuned with sentence-transformers and BatchSemiHardTripletLoss, using large batches and contextual sampling to learn embeddings whose similarity is measured with cosine similarity. Triplet loss pulls same-label transactions together and pushes different-label examples apart, while informed mining addresses subtle distinctions such as Travel: Sales versus Travel: Engineering. The embeddings support GL coding suggestions, high-confidence defaults, business-spend similarity analysis, and transaction context for LLM-enabled features, with the stated aim of keeping predictions personalized and data private."
---

# Improving Retrieval on Ramp with Transaction Embeddings

[Ramp](https://yomu.fyi/company/ramp) · Calix Huang, Anton Biryukov · Aug 13, 2024

**Type:** Problem & solution

## Summary

Ramp developed transaction embeddings to help automate accounting coding, where employees choose general ledger (GL) categories for transactions. The model represents enriched transaction features—such as merchant, category, department, location, amount, memo, spend program, and trip—as stringified documents labeled with chart-of-accounts codes. Starting from a pre-trained encoder, it is fine-tuned with sentence-transformers and BatchSemiHardTripletLoss, using large batches and contextual sampling to learn embeddings whose similarity is measured with cosine similarity. Triplet loss pulls same-label transactions together and pushes different-label examples apart, while informed mining addresses subtle distinctions such as Travel: Sales versus Travel: Engineering. The embeddings support GL coding suggestions, high-confidence defaults, business-spend similarity analysis, and transaction context for LLM-enabled features, with the stated aim of keeping predictions personalized and data private.

## Context

Employees often find it difficult and error-prone to select accounting codes from hundreds of GL categories, creating additional work for finance teams during book closing. Ramp also sought a relational representation of transactions for semantic search, grouping, recommendations, and spending-pattern analysis.

## Approach / What changed

Ramp enriched transactions with relevant contextual features, represented them as labeled stringified documents, and fine-tuned a pre-trained encoder with sentence-transformers and triplet loss. Large batches and BatchSemiHardTripletLoss supplied informative samples, while cosine similarity supported retrieval in a smaller embedding space.

## Takeaways

- BatchSemiHardTripletLoss produced the best results among the tested sentence-transformers loss-function modifications, using contextual transactions to sample difficult triplets during training.
- Transaction embeddings use merchant, MCC, department, location, amount, memo, spend program, and trip information while retaining GL categories as labels for matching new transactions to coded examples.
- The embeddings power GL coding suggestions and defaults, business similarity analysis, and relevant transaction context for features such as suggested memos.

**Tags:** [Machine Learning](https://yomu.fyi/topic/machine-learning), [Python](https://yomu.fyi/topic/python), [Search](https://yomu.fyi/topic/search)

- Source: [Ramp](https://builders.ramp.com/post/transaction-embeddings)
- Source URL: https://builders.ramp.com/post/transaction-embeddings
- Ingested by Yomu: 2026-09-01T01:34:17.859Z

[Read original post](https://builders.ramp.com/post/transaction-embeddings)
