Welcome to context-window
Building AI applications that answer questions from your documents shouldn’t be complicated. context-window provides a simple, elegant API that handles the entire RAG (Retrieval-Augmented Generation) pipeline.Why context-window?
context-window eliminates the complexity of building RAG systems by providing a complete solution:📄 Ingest Documents
Support for
.txt, .md, and .pdf files with automatic text extraction✂️ Smart Chunking
Intelligent text chunking with configurable overlap to preserve context
🧮 OpenAI Embeddings
Powered by OpenAI’s text-embedding-3-small model for high-quality vector representations
🗄️ Pinecone Storage
Scalable vector storage with Pinecone’s serverless infrastructure
🔍 Semantic Search
Fast similarity search to retrieve relevant context for any question
💬 Accurate Answers
LLM-powered answers with source citations and strict RAG guardrails
Key Features
Strict RAG - No Hallucinations
Unlike general chat models, context-window only answers from YOUR documents. If the answer isn’t found, it says “I don’t know based on the uploaded files.”Idempotent Ingestion
Re-running ingestion with the same files won’t create duplicates. Chunk IDs are content-based and stable, making updates safe and predictable.Source Citations
Every answer includes references to the source documents used, making it easy to verify information and maintain trust.Installation
1
Install the package
Install context-window using npm or your preferred package manager:
2
Create a Pinecone Index
First-time setup requires creating a Pinecone index:
- Go to Pinecone Console
- Click Create Index
- Configure your index:
- Name:
context-window(or any name you prefer) - Dimensions:
1536(required for OpenAI embeddings) - Metric:
cosine(recommended) - Cloud: AWS or GCP (AWS us-east-1 for free tier)
- Name:
- Click Create Index
The free tier includes 1 serverless index with 100K vectors, perfect for testing and small projects.
3
Get your API keys
You’ll need API keys from both OpenAI and Pinecone:
OpenAI API Key
OpenAI API Key
- Visit OpenAI API Keys
- Click Create new secret key
- Copy the key (starts with
sk-...) - Store it securely - you won’t be able to see it again
Pinecone API Key
Pinecone API Key
- Visit Pinecone Console
- Go to API Keys in the left sidebar
- Copy your API key
- Note your environment/region (e.g.,
us-east-1)
4
Configure environment variables
Create a
.env file in your project root:Never commit your
.env file to version control. Add it to .gitignore.Quick Start
Create your first RAG application in minutes:You can pass a single file, multiple files, or entire directories to the
data parameter. Supported formats: .txt, .md, .pdfWhat Happens Behind the Scenes
When you create a context window, here’s what happens:- Ingests your documents by reading all
.txt,.md, and.pdffiles - Chunks the text into overlapping segments (default: 1000 chars)
- Embeds each chunk using OpenAI’s text-embedding-3-small
- Stores vectors in your Pinecone index
- Retrieves relevant chunks when you ask a question
- Generates an answer using GPT-4o-mini with strict RAG instructions
Common Customizations
Using Different Models
Adjusting Chunk Size
Fine-tuning Retrieval
Troubleshooting
Error: Pinecone index not found
Error: Pinecone index not found
Make sure:
- Your Pinecone index exists in the console
PINECONE_INDEXin.envmatches your index name- You’re using the correct environment/region
Error: Incorrect dimensions
Error: Incorrect dimensions
Your Pinecone index must have 1536 dimensions. If you created it with wrong dimensions:
- Delete the old index in Pinecone Console
- Create a new one with 1536 dimensions
- Re-run your ingestion
Error: Invalid API key
Error: Invalid API key
Verify your API keys:
- OpenAI key starts with
sk- - Keys are correctly set in
.env - No extra spaces or quotes around the keys
Always returns "I don't know"
Always returns "I don't know"
Try:
- Lowering
scoreThresholdor removing it entirely - Increasing
topKto retrieve more chunks - Rephrasing your question to match document content
- Verifying documents were ingested successfully
Next Steps
Use Cases
Explore real-world applications and examples
API Reference
Complete API documentation and configuration options
Best Practices
Tips for optimizing performance and accuracy
Examples
Browse complete code examples for common scenarios
Need more help? Check out the Troubleshooting guide or open an issue on GitHub.