ContextGlow 🌟
ContextGlow is a plug-and-play Python middleware and React component that visualizes exactly what your RAG (Retrieval-Augmented Generation) pipeline is "thinking" about in real-time.
Drop it into your existing LangChain, LlamaIndex, or custom FastAPI pipeline in 3 lines of code to generate gorgeous, real-time attention heatmaps that expose why the AI answered the way it did.
Why ContextGlow?
RAG applications often fail silently. When a model hallucinates, developers usually blame the vector database retriever. But often, the retriever works perfectly, and the LLM just ignores the context.
ContextGlow extracts the raw, 4D cross-attention tensors during generation and dynamically maps them back to your source sentences, giving you:
- X-Ray Vision: See exactly which sentence the LLM is focusing on, token by token.
- Utilization Scoring: Measure how much of the retrieved context actually influenced the final answer.
- Lost In The Middle Detection: Automatically flag if the LLM completely ignored the middle chunks of your context.
🚀 Quick Start
1. Install the SDK
pip install contextglow
npm install @contextglow/react
2. Add to your Backend (LangChain Example)
ContextGlow ships with native adapters. You don't need to rewrite your pipeline.
from contextglow.adapters.langchain import ContextGlowCallbackHandler
from langchain.chains import RetrievalQA
# Initialize the adapter
glow_handler = ContextGlowCallbackHandler(model_name="meta-llama/Llama-3-8B")
# Pass it into your existing LangChain setup!
qa_chain = RetrievalQA.from_chain_type(
llm=llm,
retriever=vectorstore.as_retriever(),
callbacks=[glow_handler] # ContextGlow silently extracts attention here!
)
qa_chain.run("what is spacetime")
3. Add to your Frontend (React)
import { ContextViewer, useAttentionStream } from '@contextglow/react';
export default function App() {
const { context, attentionMap } = useAttentionStream('/api/chat');
return (
<ContextViewer
documents={context}
attentionMap={attentionMap}
/>
);
}
Features
- Model Agnostic: Supports any HuggingFace model (Llama-3, Mistral, Phi-3).
- Streaming Native: Heatmaps update live as tokens stream to the user.
- Low Overhead: Operates entirely in inference mode without gradients.
Coming Soon
- API Model Support (OpenAI / Anthropic) via self-reflection.
- LlamaIndex Adapters.
License
MIT
Metadata
Release files for contextglow 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| contextglow-0.1.0.tar.gz | 139.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| contextglow-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 147.6 kB
Release files / contextglow-0.1.0.tar.gz
| Download URL | contextglow-0.1.0.tar.gz |
|---|---|
| Size | 139.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8e092ed5ef488480a14c6e59684ebe2a173e51617a9d0f62bab669ff0927e583
|
|
BLAKE2b-256 checksum How to use checksums |
bc58c9135ca820b16e0a5909f9a62b5800cc72a83ffa646608798709db3a304c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.11
|
Release files / contextglow-0.1.0-py3-none-any.whl
| Download URL | contextglow-0.1.0-py3-none-any.whl |
|---|---|
| Size | 8.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a665bde508b341d55d643853db7860739ec096122f61f9e6f9685068e109e56a
|
|
BLAKE2b-256 checksum How to use checksums |
a9eb7b5dd8b1f7af4122c2aad426ef22f52228e25a4ccdb0605f00448ff941e4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.11
|