ਮੈਂ ਆਪਣੀ RAG ਪਾਈਪਲਾਈਨ ਨੂੰ ਇੱਕ ਬਲੈਕ ਬਾਕਸ ਵਾਂਗ ਮੰਨਦਾ ਸੀ। ਐਂਬੈਡਿੰਗਜ਼ (Embeddings) ਅੰਦਰ ਜਾਂਦੀਆਂ ਸਨ, ਜਵਾਬ ਬਾਹਰ ਆਉਂਦੇ ਸਨ, ਅਤੇ ਇਸ ਦੇ ਵਿਚਕਾਰ ਕਿਤੇ ਮੇਰਾ ਕਲਾਉਡ ਬਿੱਲ ਵਧਦਾ ਜਾ ਰਿਹਾ ਸੀ। ਮੈਂ ਉਨ੍ਹਾਂ ਜ਼ਿਆਦਾਤਰ ਡਿਵੈਲਪਰਾਂ ਵਾਂਗ, ਜਿਨ੍ਹਾਂ ਨਾਲ ਮੈਂ ਗੱਲ ਕੀਤੀ ਸੀ, ਇਹ ਮੰਨ ਲਿਆ ਸੀ ਕਿ ਡੈਂਸ ਵੈਕਟਰ ਮਾਡਲਜ਼ (dense vector models) ਹੀ ਮੁੱਖ ਦੋਸ਼ੀ ਸਨ। ਉਹ ਮਹਿੰਗੇ ਲੱਗਦੇ ਸਨ। ਹਜ਼ਾਰਾਂ ਪੰਨਿਆਂ ਨੂੰ ਹਾਈ-ਡਾਇਮੈਂਸ਼ਨਲ ਫਲੋਟਸ (high-dimensional floats) ਵਿੱਚ ਬਦਲਣਾ ਭਾਰੀ ਉਦਯੋਗਿਕ ਪ੍ਰਕਿਰਿਆ ਵਾਂਗ ਲੱਗਦਾ ਸੀ, ਇਸ ਲਈ ਮੈਂ ਇਸ ਨਾਲ ਬਹੁਤ ਸਾਵਧਾਨੀ ਨਾਲ ਨਜਿੱਠਿਆ। ਮੈਂ ਖਾਸ ਤੌਰ 'ਤੇ ਉਸ ਡਾਟਾ ਨੂੰ ਦੁਬਾਰਾ ਐਂਬੈਡ ਕਰਨ ਤੋਂ ਬਚਣ ਲਈ ਇੱਕ ਕੈਸ਼ਿੰਗ ਲੇਅਰ (caching layer) ਵੀ ਬਣਾਈ ਸੀ ਜਿਸ ਨੂੰ ਮੈਂ ਪਹਿਲਾਂ ਹੀ ਪ੍ਰੋਸੈਸ ਕਰ ਚੁੱਕਾ ਸੀ। ਮੈਨੂੰ ਉਸ ਆਪਟੀਮਾਈਜ਼ੇਸ਼ਨ 'ਤੇ ਮਾਣ ਸੀ। ਫਿਰ ਮੈਂ ਇਨਵੌਇਸ ਖੋਲ੍ਹਿਆ ਅਤੇ ਹਿਸਾਬ ਲਗਾਇਆ।

ਮੈਂ ਪੂਰੀ ਤਰ੍ਹਾਂ ਗਲਤ ਚੀਜ਼ ਨੂੰ ਆਪਟੀਮਾਈਜ਼ ਕਰ ਰਿਹਾ ਸੀ।

ਐਂਬੈਡਿੰਗ ਦਾ ਜਾਲ

ਇੱਥੇ ਉਹ ਅੰਕੜਾ ਹੈ ਜਿਸ ਨੇ ਮੇਰੀਆਂ ਧਾਰਨਾਵਾਂ ਨੂੰ ਤੋੜ ਦਿੱਤਾ: 1,000-ਪੰਨਿਆਂ ਦੇ ਦਸਤਾਵੇਜ਼ ਨੂੰ ਐਂਬੈਡ ਕਰਨ ਦੀ ਲਗਭਗ ਅਠਾਰਾਂ ਸੈਂਟ ਲੱਗਦੀ ਹੈ। ਇਹ ਕੋਈ ਟਾਈਪੋ ਨਹੀਂ ਹੈ। ਜ਼ਿਆਦਾਤਰ ਸ਼ਹਿਰਾਂ ਵਿੱਚ ਇੱਕ ਕੱਪ ਕੌਫੀ ਦੀ ਕੀਮਤ ਤੋਂ ਵੀ ਘੱਟ ਵਿੱਚ, ਤੁਸੀਂ ਪੂਰੀ ਕਿਤਾਬ ਨੂੰ ਵੈਕਟੋਰਾਈਜ਼ (vectorize) ਕਰ ਸਕਦੇ ਹੋ। ਸਭ ਤੋਂ ਮਹੱਤਵਪੂਰਨ ਗੱਲ ਇਹ ਹੈ ਕਿ ਇਹ ਲਾਗਤ ਸਿਰਫ ਇੱਕ ਵਾਰ, ਡਾਟਾ ਇੰਜੈਸਸ਼ਨ (ingestion) ਵੇਲੇ ਲੱਗਦੀ ਹੈ। ਸ਼ੁਰੂਆਤੀ ਪਾਸ ਤੋਂ ਬਾਅਦ, ਉਹ ਵੈਕਟਰ ਸਟੋਰੇਜ ਵਿੱਚ ਰਹਿੰਦੇ ਹਨ ਅਤੇ ਉਡੀਕ ਕਰਦੇ ਹਨ। ਹਰ ਵਾਰ ਜਦੋਂ ਕੋਈ ਯੂਜ਼ਰ ਤੁਹਾਡੀ ਐਪਲੀਕੇਸ਼ਨ ਖੋਲ੍ਹਦਾ ਹੈ, ਤਾਂ ਉਹ ਵਾਰ-ਵਾਰ ਫੀਸ ਨਹੀਂ ਵਧਾਉਂਦੇ। ਉਹ ਇੱਕ ਕੈਪੀਟਲ ਖਰਚਾ (capital expense) ਹਨ, ਨਾ ਕਿ ਵਾਰ-ਵਾਰ ਹੋਣ ਵਾਲਾ ਖਰਚਾ।

ਫਿਰ ਵੀ ਇਹ ਭਰਮ ਬਣਿਆ ਹੋਇਆ ਹੈ। ਇਸ ਉਲਝਣ ਦਾ ਇੱਕ ਹਿੱਸਾ ਸੰਰਚਨਾਤਮਕ (structural) ਹੈ। ਇੰਜੀਨੀਅਰ ਆਪਣੀ ਸ਼ੁਰੂਆਤੀ ਊਰਜਾ ਇੰਜੈਸਸ਼ਨ ਪਾਈਪਲਾਈਨ 'ਤੇ ਖਰਚ ਕਰਦੇ ਹਨ। ਤੁਸੀਂ ਚੰਕਰ (chunker) ਲਿਖਦੇ ਹੋ, ਟੋਕਨਾਈਜ਼ਰ (tokenizer) ਨਾਲ ਲੜਦੇ ਹੋ, ਅਤੇ ਆਪਣੇ ਟਰਮੀਨਲ 'ਤੇ ਪ੍ਰਗਤੀ ਬਾਰ (progress bars) ਨੂੰ ਹੌਲੀ-ਹੌਲੀ ਚਲਦੇ ਦੇਖਦੇ ਹੋ। ਇਹ ਦਿਖਾਈ ਦੇਣ ਵਾਲੀ ਕੋਸ਼ਿਸ਼ ਅਨੁਪਾਤ ਦਾ ਇੱਕ ਭਰਮ ਪੈਦਾ ਕਰਦੀ ਹੈ। ਇਹ ਮਹਿੰਗਾ ਹਿੱਸਾ ਲੱਗਦਾ ਹੈ ਕਿਉਂਕਿ ਇਹ ਮਿਹਨਤ ਵਾਲਾ ਹਿੱਸਾ ਹੈ। ਪਰ ਮਿਹਨਤ ਅਤੇ ਲਾਗਤ ਇੱਕੋ ਚੀਜ਼ ਨਹੀਂ ਹਨ, ਅਤੇ RAG ਵਿੱਚ ਉਹ ਅਕਸਰ ਉਲਟ ਅਨੁਪਾਤ ਵਿੱਚ ਹੁੰਦੇ ਹਨ।

ਤਿੰਨ ਬਿਲਕੁਲ ਵੱਖਰੇ ਬਿੱਲ

ਇੱਕ ਵਾਰ ਜਦੋਂ ਮੈਂ ਲਾਗਤਾਂ ਨੂੰ ਇਕੱਠਾ ਕਰਨ ਦੀ ਬਜਾਏ ਪੜਾਵਾਂ ਅਨੁਸਾਰ ਵੱਖ ਕੀਤਾ, ਤਾਂ ਸਭ ਕੁਝ ਸਾਫ਼ ਹੋ ਗਿਆ। ਇੱਕ RAG ਸਿਸਟਮ ਤਿੰਨ ਵੱਖ-ਵੱਖ ਆਰਥਿਕ ਮਾਡਲਾਂ 'ਤੇ ਚੱਲਦਾ ਹੈ, ਅਤੇ ਜੇਕਰ ਤੁਸੀਂ ਆਪਣੇ ਬਜਟ ਨੂੰ ਕੰਟਰੋਲ ਵਿੱਚ ਰੱਖਣਾ ਚਾਹੁੰਦੇ ਹੋ ਤਾਂ ਇਹਨਾਂ ਦੇ ਅੰਤਰ ਨੂੰ ਸਮਝਣਾ ਜ਼ਰੂਰੀ ਹੈ।

ਐਂਬੈਡਿੰਗਜ਼ ਇੱਕ ਵਾਰ ਦਾ ਮੈਨੂਫੈਕਚਰਿੰਗ ਖਰਚਾ ਹਨ। ਤੁਸੀਂ ਦਸਤਾਵੇਜ਼ਾਂ ਨੂੰ ਵੈਕਟਰਾਂ ਵਿੱਚ ਬਦਲਣ ਲਈ ਭੁਗਤਾਨ ਕਰਦੇ ਹੋ, ਅਤੇ ਫਿਰ ਤੁਹਾਡਾ ਕੰਮ ਖਤਮ ਹੋ ਜਾਂਦਾ ਹੈ। ਜੇਕਰ ਤੁਹਾਡੇ ਦਸਤਾਵੇਜ਼ ਸਟੈਟਿਕ ਹਨ, ਤਾਂ ਇਹ ਖਰਚਾ ਤੁਹਾਡੇ ਮਹੀਨਾਵਾਰ ਬਿੱਲ ਵਿੱਚ ਬਹੁਤ ਘੱਟ ਦਿਖਾਈ ਦਿੰਦਾ ਹੈ।

ਵੈਕਟਰ ਡਾਟਾਬੇਸ ਇਨਫਰਾਸਟ੍ਰਕਚਰ ਦਾ ਕਿਰਾਇਆ ਹਨ। ਤੁਸੀਂ ਸਿਸਟਮ ਨੂੰ ਚੌਵੀ ਘੰਟੇ ਚਾਲੂ ਰੱਖਣ ਲਈ ਭੁਗਤਾਨ ਕਰਦੇ ਹੋ। ਤੁਸੀਂ ਲੱਖਾਂ ਚੰਕਸ (chunks) ਨੂੰ ਰੱਖਣ ਵਾਲੇ SSDs, ਇੰਡੈਕਸਾਂ ਨੂੰ ਬਣਾਈ ਰੱਖਣ ਵਾਲੇ CPU ਕੋਰਜ਼, ਅਤੇ 100-ਮਿਲੀਸਕਿੰਡ ਤੋਂ ਘੱਟ ਸਮੇਂ ਵਿੱਚ ਸਰਚ ਕਰਨ ਵਾਲੇ ਨੈੱਟਵਰਕ ਲਈ ਭੁਗਤਾਨ ਕਰਦੇ ਹੋ। ਇਹ ਲਾਗਤ ਅਸਲੀ ਹੈ, ਅਤੇ ਇਹ ਡਾਟਾ ਦੀ ਮਾਤਰਾ ਦੇ ਨਾਲ ਵਧਦੀ ਹੈ, ਪਰ ਇਹ ਆਮ ਤ

Most organizational knowledge bases move slowly. Policies, handbooks, research PDFs, and archived reports sit untouched for months. In many pipelines, about eighty percent of source documents stay identical between ingestion runs. Despite this, plenty of systems drop the entire corpus and rebuild the index from scratch on a schedule. Do not do that. Build a gate at the entry to your pipeline. Hash incoming files. Compare last-modified timestamps. If a document has not changed, skip it entirely. Re-processing static files is pure waste. It costs compute, it wears SSDs unnecessarily, and it balloons your ingestion logs with false activity.

In practice, store a lightweight manifest that maps file paths to checksums. When the scheduler wakes up, let it check the manifest first. Only the minority of changed files should ever see a chunker.

Patch Documents, Do Not Replace Them

When a document does change, resist the instinct to treat it as a brand-new file. A fifty-page technical spec might receive a two-paragraph revision in section four. If your pipeline replaces the entire file, you will re-chunk and re-embed forty-nine perfectly good pages for no reason.

Instead, compare the new version against the old one. Identify the delta. Then re-chunk and re-embed only the sections that changed. Use metadata like page numbers, section IDs, header anchors, or paragraph ranges to track boundaries. If your chunking strategy respects document structure, this is straightforward. If it does not, fixing your chunker is a better investment than buying a bigger inference cluster. The engineering cost of maintaining a diff-aware pipeline pays for itself within weeks once your document count scales.

Attack the Recurring Costs Head-On

Since LLM calls run on every query, shaving even a few tokens or caching a handful of responses creates outsized returns. Start with prompt caching. If one user asks about your refund policy and another asks the same thing ten minutes later, there is no reason to hit the model twice. Store recent query-response pairs with semantic similarity matching. When a new question lands within a similarity threshold of a cached one, return the stored answer directly. No tokens generated, no dollars spent.

Next, look hard at your retrieval quality. A sloppy retriever forces the LLM to read a haystack to find the needle. If you stuff the prompt with twenty irrelevant chunks because your top-k cutoff is too loose, you are paying the model to skim noise. Tighten your retrieval. Trim your top-k. Compress chunks before sending them. Remove boilerplate footers and headers during ingestion so they never reach the prompt. Every token you remove from the context window is a fraction of a cent saved, and those fractions accumulate across thousands of daily queries.

Better retrieval also improves latency, which is another form of cost. Users abandon slow interfaces. A faster answer is both cheaper to produce and better for retention.

The Real Takeaway

Stop optimizing what feels expensive and start optimizing what your invoice says is expensive. Measure each stage independently. You will likely find that embeddings are the cheap part, vector storage is the steady part, and LLM inference is the part that bleeds. Focus your energy on query-time efficiency, incremental updates, and surgical deduplication. Build for the thousandth user question, not the fiftieth document upload. The bottleneck is rarely where you think it is.

Source: Where Does RAG Actually Cost You Money? I Decided to Stop Guessing

Join the discussion in the GyaanSetu AI learning community.