LlamaIndex for Enterprise: Architecture, Secure Deployment, and Production RAG Patterns
Prerequisites
- Python 3.10+ and pip
- Basic knowledge of vector databases and APIs
Steps
LlamaIndex is a data framework for building retrieval-augmented generation applications over enterprise content. This guide explains its architecture, secure deployment options, implementation steps, and operational practices for production environments.
Overview
LlamaIndex is an application data framework that connects large language models to private enterprise data sources such as SharePoint, Confluence, S3, databases, ticketing systems, and document repositories. Its core purpose is to ingest, structure, index, retrieve, and orchestrate context so teams can build reliable RAG, agentic search, knowledge assistants, and document automation workflows.
Enterprises use LlamaIndex because it separates data connectors, indexing, retrieval, and response synthesis into composable building blocks. This makes it easier to enforce governance, swap vector stores or models, support hybrid search, and integrate with existing security controls.
Architecture
Core components typically include:
- Data connectors for filesystems, object stores, SaaS apps, and databases
- Parsers and chunkers to normalize PDFs, HTML, Office files, and structured records
- Embeddings and indexes for vector, keyword, or graph-based retrieval
- Retrievers and query engines to combine semantic search, metadata filters, reranking, and response synthesis
- Storage backends such as PostgreSQL, Qdrant, Weaviate, Pinecone, or Azure AI Search
- LLM providers such as OpenAI, Azure OpenAI, Anthropic, or self-hosted models via vLLM
View as text
[Enterprise Sources] ---- 1. ingest ----> [LlamaIndex Ingestion Service] ---- 2. parse/chunk ----> [Embedding Model] [Embedding Model] ---- 3. vectors ----> [Vector Store] [Metadata DB] <---- 4. document metadata ---- [LlamaIndex Ingestion Service] [User App] ---- 5. query ----> [Query API] [Query API] ---- 6. retrieve ----> [Vector Store] [Query API] ---- 7. synthesize ----> [LLM] [LLM] ---- 8. answer ----> [Query API] ---- 9. response ----> [User App]
Deployment models:
- Single VPC deployment for internal applications with private subnets and managed databases
- Kubernetes microservice deployment with separate ingestion, query, and worker services
- Hybrid deployment where embeddings and storage remain private while inference uses a managed API through private networking
Implementation Guide
- Create a Python environment and install core packages.
python3 -m venv .venv
source .venv/bin/activate
pip install --upgrade pip
pip install llama-index llama-index-vector-stores-qdrant llama-index-embeddings-openai qdrant-client fastapi uvicorn[standard] pydantic
- Start a local Qdrant instance for testing.
docker run -d --name qdrant -p 6333:6333 -v $(pwd)/qdrant_storage:/qdrant/storage qdrant/qdrant:v1.9.0
curl http://localhost:6333/healthz
- Set secrets as environment variables.
export OPENAI_API_KEY='sk-...'
export QDRANT_URL='http://localhost:6333'
export COLLECTION='enterprise_docs'
- Create an ingestion config.
app:
collection: enterprise_docs
chunk_size: 512
chunk_overlap: 64
metadata_fields: [source, owner, classification, region]
security:
pii_redaction: true
allowed_classifications: [public, internal, confidential]
retrieval:
top_k: 5
similarity_cutoff: 0.78
- Load documents, build the index, and expose a query API.
- Place the API behind an enterprise gateway, enforce SSO, and log all retrieval requests for audit.
Code Examples
from llama_index.core import VectorStoreIndex, SimpleDirectoryReader, StorageContext
from llama_index.embeddings.openai import OpenAIEmbedding
from llama_index.vector_stores.qdrant import QdrantVectorStore
from qdrant_client import QdrantClient
import os
docs = SimpleDirectoryReader("./docs").load_data()
client = QdrantClient(url=os.environ["QDRANT_URL"])
vector_store = QdrantVectorStore(client=client, collection_name=os.environ["COLLECTION"])
index = VectorStoreIndex.from_documents(docs, embed_model=OpenAIEmbedding(model="text-embedding-3-large"), storage_context=StorageContext.from_defaults(vector_store=vector_store))
query_engine = index.as_query_engine(similarity_top_k=5)
print(query_engine.query("Summarize security obligations in the vendor policy."))
from fastapi import FastAPI
from pydantic import BaseModel
app = FastAPI()
class QueryRequest(BaseModel):
question: str
@app.post("/query")
def query(req: QueryRequest):
response = query_engine.query(req.question)
return {"answer": str(response), "sources": [n.node.metadata for n in response.source_nodes]}
apiVersion: apps/v1
kind: Deployment
metadata:
name: llamaindex-query
spec:
replicas: 3
selector:
matchLabels:
app: llamaindex-query
template:
metadata:
labels:
app: llamaindex-query
spec:
containers:
- name: api
image: ghcr.io/example/llamaindex-api:1.0.0
ports:
- containerPort: 8000
env:
- name: QDRANT_URL
value: http://qdrant:6333
- name: COLLECTION
value: enterprise_docs
- name: OPENAI_API_KEY
valueFrom:
secretKeyRef:
name: llm-secrets
key: openai_api_key
securityContext:
runAsNonRoot: true
readOnlyRootFilesystem: true
Security Hardening
- Use TLS everywhere between application, vector store, and model endpoints.
- Encrypt documents and vector storage at rest with cloud KMS or HSM-backed keys.
- Enforce RBAC on ingestion pipelines so only approved services can write indexes.
- Apply metadata-based authorization filters, for example
classification=internalandregion=eu. - Redact secrets and PII before embedding; embeddings can leak sensitive semantics.
- Use private networking to Azure OpenAI or self-hosted inference where regulatory controls require data residency.
- Enable audit logs for prompts, retrieved document IDs, user identity, and policy decisions.
Comparison
| Product | Pricing | Deployment | Scalability | Security |
|---|---|---|---|---|
| LlamaIndex | Open-source core; enterprise cost depends on hosting and model usage | Self-managed, cloud, Kubernetes, hybrid | High with external vector DB and stateless APIs | Strong when paired with enterprise IAM, private networking, and metadata filters |
| LangChain | Open-source core; added cost for LangSmith and infrastructure | Self-managed and cloud tooling | High, but orchestration can become complex at scale | Good, but security posture depends heavily on custom implementation |
| Haystack by deepset | Open-source plus commercial offerings | Self-managed, Kubernetes, managed options | Strong for search-heavy pipelines and modular components | Mature enterprise controls in commercial deployments |
Troubleshooting
- Qdrant connection failure
ERROR:qdrant_client.http.api_client:Connection refused to http://localhost:6333/collections/enterprise_docs
requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=6333): Max retries exceeded
Fix: verify the container is running, check curl http://localhost:6333/healthz, and confirm firewall or Docker port mapping.
- Embedding authentication error
openai.AuthenticationError: Error code: 401 - {'error': {'message': 'Incorrect API key provided'}}
Fix: rotate the secret, validate the environment variable in the runtime, and avoid baking keys into images.
- Dimension mismatch after model change
ValueError: expected vector size 3072, got 1536 for collection enterprise_docs
Fix: recreate the collection or use a separate collection per embedding model version.
Best Practices
Do
- Version indexes and embedding models, for example
enterprise_docs_v3_text-embedding-3-large. - Keep ingestion asynchronous and idempotent using document checksums.
- Add reranking for high-value workflows such as legal, security, and compliance search.
- Store source metadata and citations to support explainability and auditability.
Don't
- Do not mix confidential and public data in the same unrestricted collection.
- Do not let the LLM answer without retrieval for regulated enterprise use cases.
- Do not ignore chunking strategy; a 20-page PDF embedded as one chunk will degrade recall.
- Do not expose query APIs directly to the internet without WAF, SSO, rate limiting, and request logging.
Have a project in mind?
Get an instant AI price estimate for it, or talk directly to our team.
One email a month on what we learn building with AI