Lesson 6 of 7 Cost and Capacity Optimization

Monitoring Token, Embedding and Vector Storage Costs

This lesson explains how to monitor AI-specific cost drivers that traditional ML does not have: tokens per request, embedding computation and vector database storage.

Learning outcomes

After completing this lesson, you will be able to:

  • Track token usage patterns by application and tenant.
  • Control embedding computation costs.
  • Reduce vector storage cost.

Token usage patterns

Track InputTokenCount and OutputTokenCount per model and, through application inference profiles or logged metadata, per application, feature and tenant. Watch tokens per request over time: steady growth usually means prompts, retrieved context or conversation history are growing. Compare cost per successful outcome (for example, per resolved ticket), not only per request.

True or false

Token patterns

Exam skills 4.2.10

Check how token usage patterns reveal cost problems.

Log in to try this activity Interactive activities are free with an account.

Embedding computation

Embedding models charge per input token, so embedding costs depend on how much text is embedded. Costs spike when whole corpora are re-embedded, which happens after changing the embedding model or chunking strategy, or when pipelines re-ingest documents that have not changed.

Incremental knowledge base syncs process only changed documents. Custom pipelines can hash documents and skip unchanged ones. Caching the embeddings of repeated queries avoids re-embedding them, and batch inference reduces the cost of large backfills.

The following diagram compares the figures of a custom RAG pipeline before and after three changes to embedding and hosting.

Three changes to the custom RAG pipeline. Hashing documents and re-embedding only new or changed ones cuts the nightly embedding volume by about 98%; re-embedding once at 512 dimensions instead of 1,536, after evaluation confirms recall, shrinks every vector to a third; and one replica instead of two matches the low query rate.
The after value for chunks is approximate.
Scenario questions

Embedding costs

Exam skills 4.2.10

Reduce embedding and vector storage costs.

Log in to try this activity Interactive activities are free with an account.

Vector storage

Vector store cost grows with the number of vectors, their dimensions, index overhead and replicas. OpenSearch Serverless is billed in OpenSearch Compute Units for indexing and search plus storage; managed domains by instance and storage. Reduce cost with fewer dimensions (for example, 512 instead of 1,024 with Titan Text Embeddings V2), byte or binary quantisation, larger chunks where quality allows, deleting stale vectors, and Amazon S3 Vectors for large, infrequently queried collections. The following table summarises the cost patterns.

Cost driverMonitorOptimize
Tokens per requestToken count metrics per applicationPrompt trimming, caching, routing
Embedding computationEmbedding token usage, ingestion job sizesIncremental sync, skip unchanged, batch
Vector storage and computeIndex size, OCUs or instance usageFewer dimensions, quantisation, S3 Vectors, clean-up
Replicas and shardsQuery rate vs. capacityRight-size replicas to query load
Worked example

A nightly re-ingestion

A custom RAG pipeline re-embeds all 3 million chunks every night, and its OpenSearch domain stores 1,536-dimension vectors with two replicas, although query volume is low.

  • Hash each document and re-embed only new or changed ones: nightly embedding volume falls by about 98%.
  • Re-embed once with Titan Text Embeddings V2 at 512 dimensions after evaluation shows recall is maintained.
  • Reduce to one replica to match the low query rate.

Embedding cost and vector storage both fall sharply. Monitoring embedding token usage would have revealed the wasteful nightly re-ingestion months earlier.

Check yourself

How can re-embedding unchanged documents be avoided?

Show answer

With incremental sync, or by hashing content to detect changes.

Exam Tips

Remember for the exam

  • Track tokens per request per application to spot prompt growth.
  • Avoid re-embedding unchanged documents: incremental sync or hashing.
  • Fewer dimensions and quantisation reduce vector storage cost.
  • Large, rarely queried vector sets: S3 Vectors.
  • Match replicas to query load.