Contextual AI Component APIs
State-of-the-art components to enhance every step of your RAG pipeline

CORE RAG BUILDING BLOCKS
Optimize your RAG pipeline end-to-end with powerful APIs for document understanding, reranking, generation, and evaluation

STATE-OF-THE-ART PERFORMANCE
Build more powerful agents with components that outperform competing solutions on industry-leading benchmarks

SIMPLE, FLEXIBLE INTEGRATION
Incorporate components into your existing RAG pipeline without needing to overhaul your entire architecture
Build better RAG agents
Powerful RAG components for when accuracy and performance matter

Our document understanding pipeline, capable of processing complex, multimodal content
(Coming Soon)

The first instruction-following reranker, providing greater control over how retrievals are prioritized

The most grounded language model in the world, engineered specifically to minimize hallucinations

Our evaluation-optimized model for preference, direct scoring, and granular unit test evaluation
Achieve even greater performance
with the Contextual AI Platform
Each component API achieves state-of-the-art performance. The Contextual AI Platform achieves even greater end-to-end performance by jointly optimizing the components as a single, unified system.
State-of-the-art Capabilities

PARSE
Extract complex multimodal content from any document
- Convert unstructured documents into structured output optimized for your RAG pipeline
- Easily process text, charts, tables, code, and other complex modalities
- Enhance responses with precise bounding box attributions over the retrieved document

RERANK
Resolve knowledge conflicts with the only instruction-following reranker
- Steer how your reranker prioritizes information with natural language instructions
- Serve the most relevant content to your model’s context—with or without instructions
- Drop into your existing RAG pipeline with just a few lines of code

GENERATE
Maximize accuracy with the world’s most grounded language model
- Generate answers strongly grounded in your retrieved documents
- Minimize hallucinations with response tags to delineate between facts and model commentary
- Provide in-line attributions to source documents for end-users to verify responses

LMUnit
Evaluate LLM responses with fine-grained natural language unit tests
- Assess responses for your defined criteria, like conciseness, technical precision, and more
- Test for accuracy with out-of-the-box evaluation tests for equivalence and groundedness
- Reduce your dependence on end-user testing and get to production faster
Simple APIs to improve your RAG pipelines
# Rank retrieved documents using instructions
import os
from contextual import ContextualAI
client = ContextualAI(api_key=os.environ.get("CONTEXTUAL_API_KEY"))
rerank_response = client.rerank.create(
query = "your query",
instruction = "your instructions",
documents = ["your documents"],
metadata = ["your metadata"],
model = "ctxl-rerank-en-v1-instruct"
)
print(rerank_response.to_dict())
# Generate highly grounded responses
import os
from contextual import ContextualAI
client = ContextualAI(api_key=os.environ.get("CONTEXTUAL_API_KEY"))
generate_response = client.generate.create(
model="v1",
messages=[{
"content": "content",
"role": "user",
}],
knowledge=["your knowledge"],
avoid_commentary=False
)
print(generate_response.response)
# Evaluate responses with user-defined unit tests
import os
from contextual import ContextualAI
client = ContextualAI(api_key=os.environ.get("CONTEXTUAL_API_KEY"))
response = client.lmunit.create(
query="your query",
response="your response",
unit_test="your unit test"
)
print(response)