RAG
← Back to Blog
RAGOctober 25, 2026·7 min read

Scalable Enterprise RAG Architecture: Embeddings to Monitoring

Opening: The 73% surprise

73% of internal search queries in large organizations never return a useful answer on the first try. That number pops up in a few internal audits and it hurts productivity more than any single outage. The reason is simple: traditional keyword matching can’t keep up with the growing amount of unstructured content, and the models that could understand the nuance are left out of the loop because they don’t know where to look. In this post I walk through a practical, end‑to‑end design for a Retrieval‑Augmented Generation (RAG) pipeline that can be dropped into an existing enterprise knowledge base, keep latency low, and keep hallucinations in check.

Why it matters now

Enterprises are hoarding PDFs, tickets, chat logs and internal wikis at a rate that outpaces any manual curation effort. At the same time, large language models (LLMs) have become cheap enough to run inference on‑premise or via managed services. Marrying the two – letting an LLM fetch the right chunk of text before it generates an answer – is the core of RAG. The upside is immediate: answers become up‑to‑date without retraining the model, and you can surface the exact source material for compliance. The downside is new complexity: you need to choose an embedding strategy, a vector store, an indexing workflow, and a set of prompt constraints that together keep the system fast and trustworthy.

Technical deep dive

Let’s start with the embedding choice. Dense embeddings (e.g., OpenAI text-embedding-3-large or Cohere embed‑english‑v3.0) capture semantic similarity well but can be pricey at scale. Sparse embeddings (e.g., BM25‑style token weighting or the recent splade model) are cheaper to compute and store, and they shine when exact term matching still matters. A hybrid approach – dense for high‑level semantic recall and sparse for precise term matching – often gives the best of both worlds.

Next, the vector store. FAISS (v1.8.0) is fast and free but requires a GPU for large index sizes and lacks built‑in durability. Pinecone (v2.1) offers managed persistence, automatic sharding, and a query latency around 20‑30 ms for 10 M vectors, but the cost climbs with throughput. For a typical enterprise with 50 M documents and a budget of $0.08 per 1 M queries, a mixed setup works: a local FAISS index for the most recent 5 M vectors (updated in real time) and a Pinecone replica for the long‑term store. The local index handles the low‑latency “freshness” slice, while Pinecone guarantees durability and cross‑region replication.

Below is a minimal Python snippet (tested on Python 3.11) that shows how to embed a document, store it in both FAISS and Pinecone, and keep a mapping table in PostgreSQL 15 for metadata.

import os
import uuid
from datetime import datetime

import psycopg2
import pinecone
from langchain.embeddings import OpenAIEmbeddings
from langchain.vectorstores import FAISS

# Configuration
OPENAI_API_KEY = os.getenv('OPENAI_API_KEY')
PINECONE_API_KEY = os.getenv('PINECONE_API_KEY')
PINECONE_ENV = 'us-west1-gcp'
INDEX_NAME = 'enterprise-rag'

# Init services
emb = OpenAIEmbeddings(model='text-embedding-3-large')
faiss_index = FAISS.from_embeddings([], [])  # empty index
pinecone.init(api_key=PINECONE_API_KEY, environment=PINECONE_ENV)
pinecone_index = pinecone.Index(INDEX_NAME)

# PostgreSQL connection for metadata
pg_conn = psycopg2.connect(
    dbname='rag_meta',
    user='rag_user',
    password=os.getenv('PG_PASSWORD'),
    host='pg.internal'
)
pg_cur = pg_conn.cursor()

def index_document(text: str, source_id: str):
    # 1. Create embedding
    vec = emb.embed_query(text)
    doc_id = str(uuid.uuid4())
    # 2. Store in FAISS (in‑memory slice)
    faiss_index.add_texts([text], [doc_id])
    # 3. Store in Pinecone (persistent slice)
    pinecone_index.upsert(vectors=[(doc_id, vec)])
    # 4. Persist metadata
    pg_cur.execute(
        """INSERT INTO documents (id, source_id, created_at) VALUES (%s, %s, %s)""",
        (doc_id, source_id, datetime.utcnow())
    )
    pg_conn.commit()
    return doc_id
"""Example usage"""
doc_id = index_document(open('policy.pdf','rb').read().decode('utf-8'), 'policy-2024')
print(f'Document indexed with id {doc_id}')

Trade‑offs explained:

Common pitfalls and what tends to go wrong

Even with a solid architecture, teams stumble on a few recurring issues. First, the “embedding drift” problem: as you upgrade the embedding model, old vectors become incomparable, leading to a sudden drop in retrieval relevance. The fix is to version your index and re‑embed in batches, keeping the old version live until the new one is fully populated.

Second, forgetting to prune stale vectors. Over months, deleted or superseded documents linger in the vector store, causing the LLM to hallucinate references that no longer exist. A nightly job that cross‑checks the metadata table against the vector IDs solves this.

Third, prompt leakage. If you simply prepend the retrieved chunks to the LLM prompt, the model may ignore them and generate a fabricated answer. Constraining the prompt with a “ground‑truth” template – for example, forcing the model to answer only if a citation is present – reduces hallucinations dramatically.

Lastly, monitoring latency without context. A spike in query time could be due to a cold FAISS cache, network jitter to Pinecone, or a sudden surge in concurrent users. Tagging each latency metric with its source (FAISS vs Pinecone) lets you pinpoint the bottleneck.

Practical implementation guide

Here’s a step‑by‑step checklist you can copy into a sprint:

  1. Pick the embedding strategy: Start with text-embedding-3-large for semantic recall. Add a sparse BM25 vector using elasticsearch‑7.17 if term precision is critical.
  2. Spin up the vector stores: Deploy a GPU‑enabled VM (e.g., AWS g4dn.xlarge) for FAISS, and create a Pinecone index with metric=cosine, dimension=1536, replicas=2.
  3. Set up metadata persistence: Use PostgreSQL with a documents table (id UUID PK, source_id TEXT, created_at TIMESTAMP). Add a deleted BOOLEAN flag for soft deletes.
  4. Build the ingestion pipeline: Use a message queue like RabbitMQ 3.11. Publish new document events; a worker reads the event, extracts text with Apache Tika 2.8.0, embeds, and calls the index_document function shown above.
  5. Design the retrieval‑generation flow: Query FAISS first for the freshest 5 K vectors, fall back to Pinecone for the next 20 K. Merge results, rank by combined dense+BM25 score, then feed the top 3 chunks into an LLM prompt that includes a “cite‑only‑if‑present” clause.
  6. Implement hallucination guard: Prompt template example:
    Answer the question using only the provided excerpts. If none of the excerpts contain the answer, respond with "I don't have enough information." Include a citation in the form [doc_id] for each fact.
  7. Monitoring stack: Export query_latency_seconds, retrieval_success_rate, and hallucination_rate (derived from a downstream audit) to Prometheus. Alert on >200 ms latency for FAISS or >5% hallucination spikes.
  8. Drift detection: Every 24 h run a similarity check between the latest query embeddings and the stored vectors. If the average distance shifts >0.15, trigger a re‑embedding job.

Closing thoughts

Designing a scalable RAG pipeline is less about picking the flashiest model and more about stitching together reliable components that respect the enterprise’s latency budget and compliance needs. Dense embeddings give you the semantic reach, sparse embeddings keep the needle‑in‑haystack precision, a hybrid vector store balances cost and durability, and a well‑crafted prompt template is your first line of defense against hallucination. Keep an eye on drift – both in the embeddings and in the relevance of retrieved chunks – and let automated monitoring close the loop.

Take the next step

If you’re ready to prototype a production‑grade RAG service for your organization, visit akkistech.com for a starter kit, consulting hours, and a community of engineers who’ve walked this path.

Ready to find your automation candidates?

We run a structured AI Readiness Assessment for SMEs — two weeks, concrete output, no fluff. You’ll hear back directly from Kerim.

Start with an AI Assessment