LlamaIndex Integration
Using Forge with LlamaIndex.
LlamaIndex Integration
LlamaIndex works with Forge through the OpenAI-compatible API. Use Forge as your LLM and embedding provider to get intelligent routing and security for all your RAG pipelines.
Setup
pip install llama-index llama-index-llms-openai-like
Configure LLM
from llama_index.llms.openai_like import OpenAILike
llm = OpenAILike(
model="auto",
api_key="forge_sk_your_key",
api_base="https://api.optima-forge.com/v1",
is_chat_model=True,
)
response = llm.complete("Summarize the benefits of RAG architectures.")
print(response.text)
RAG Pipeline
from llama_index.core import VectorStoreIndex, SimpleDirectoryReader
documents = SimpleDirectoryReader("./data").load_data()
index = VectorStoreIndex.from_documents(documents, llm=llm)
query_engine = index.as_query_engine()
response = query_engine.query("What are the key findings?")
print(response)
Benefits with Forge
- Automatic model selection based on query complexity
- Provider failover if your primary LLM is unavailable
- Cost optimization for embedding and completion calls
- Security scanning on all inputs and outputs
- Full tracing via Langfuse for every LlamaIndex operation