General Questions
Can I use this in production?
Yes! context-window is production-ready with:- ✅ TypeScript for type safety
- ✅ Idempotent operations (safe to re-run)
- ✅ Proper error handling
- ✅ Battle-tested dependencies (OpenAI, Pinecone)
- Use environment-specific API keys
- Implement rate limiting for public endpoints
- Monitor API costs
- Add caching for repeated questions
- Use a secret manager (AWS Secrets Manager, Vault, etc.)
How much does it cost to run?
Example: 100-page book (~50,000 words)- Ingestion: ~$0.10 (one time)
- Per question: ~$0.001-0.002
- Pinecone storage: Free (under 100K vectors)
- OpenAI: ~$30-60/month
- Pinecone: Free tier or ~$20/month
- Embeddings: $0.02 per 1M tokens (very cheap)
- Chat (gpt-4o-mini): $0.15 per 1M input tokens
- Chat (gpt-4o): $5.00 per 1M input tokens
- Pinecone: Free tier includes 100K vectors
Can I update documents without re-ingesting everything?
Yes! context-window is idempotent:- ✅ Add new files → only new files are processed
- ✅ Update existing files → only changed chunks are updated
- ✅ Re-run with same files → no duplicates created
How do I delete old documents?
Currently, you need to delete via Pinecone Console:- Go to your Pinecone index
- Find the namespace (matches your index name)
- Delete specific vectors by ID or delete the entire namespace
Built-in deletion functionality is on the roadmap for future versions.
Technical Questions
How accurate is it?
Accuracy depends on:- Document quality: Clear, well-written docs → better answers
- Chunk size: Appropriate for your content type
- Question phrasing: Specific questions → better retrieval
- Content coverage: Answer must be IN your documents
Can I use a different AI model?
Yes! Change themodel parameter:
Does it work with scanned PDFs?
No, scanned PDFs (images of text) won’t work. You need:- Text-based PDFs (searchable/selectable text)
- Or use OCR software first to convert scans to text
What file formats are supported?
Currently supported:.txt- Plain text files.md- Markdown files.pdf- Text-based PDF documents
.docx- Microsoft Word.html- HTML documents.csv- CSV files.json- JSON documents.epub- EPUB books
Can I use this for real-time chat?
Yes, but responses are not streamed. Each question takes:- Embedding: ~100-200ms
- Vector search: ~50-100ms
- LLM generation: ~1-3 seconds
- Use
gpt-4o-mini(faster thangpt-4o) - Reduce
maxContextCharsto send less context - Implement client-side caching
- Show a “thinking” indicator to users
Can I run this offline?
No, currently requires:- Internet connection
- OpenAI API access
- Pinecone API access
Data & Privacy
What about data privacy?
Your data flow:- Files are parsed locally on your machine
- Only extracted text is sent to OpenAI for embedding
- Vectors + text are stored in your Pinecone index
- Questions and context are sent to OpenAI for answers
- OpenAI: Data sent via API is not used for training (per their policy)
- Pinecone: You control the index, can delete anytime
- No data is stored by this library itself
- Self-hosted vector stores (pgvector)
- Local LLMs (future feature)
- OpenAI’s Azure deployment (GDPR compliant)
Where is my data stored?
- Documents: Never sent to any service, parsed locally
- Text chunks: Stored in your Pinecone index
- Embeddings: Stored in your Pinecone index
- Questions/answers: Processed by OpenAI, not stored (per their API policy)
Is my API key secure?
Your API keys should be:- ✅ Stored in environment variables (
.env) - ✅ Never committed to version control
- ✅ Loaded securely in production (secrets manager)
- ❌ Never hardcoded in your source code
- ❌ Never logged or exposed to users
Performance Questions
Why is ingestion slow?
Ingestion time depends on:- Number and size of documents
- OpenAI API rate limits
- Network latency
- Pinecone write throughput
- Small (10 files, 100KB): ~10-30 seconds
- Medium (100 files, 1MB): ~1-3 minutes
- Large (1000 files, 10MB): ~10-30 minutes
- Increase chunk size to reduce total chunks
- Upgrade OpenAI API rate limits
- Process files in batches
Why am I getting “I don’t know” for every question?
Possible causes:- Documents didn’t ingest: Check for errors during
createCtxWindow() - Wrong namespace: Ensure you’re using the same
namespace - Score threshold too high: Try lowering or removing
scoreThreshold - Question too different from content: Try rephrasing your question
Can I improve response speed?
Yes! Several strategies: 1. Use faster model:Troubleshooting
Error: “Pinecone index not found”
Solution: Ensure your Pinecone index exists and the name matches your.env configuration.
Error: “Incorrect dimensions”
Solution: Your Pinecone index must have 1536 dimensions to work with OpenAI’s text-embedding-3-small model. If you created an index 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”
Solution: Verify your API keys are correct:PDF parsing fails
Possible causes:- Scanned PDF (image-based)
- Corrupted file
- Password-protected PDF
- Ensure PDF is text-based (try selecting text)
- If scanned, use OCR software first
- Extract text and save as
.txtor.md - Remove password protection
Out of memory errors
Solution: For large files:- Increase Node.js memory:
- Or split large files into smaller chunks
-
Or increase
chunk.sizeto reduce total chunks
Integration Questions
Can I use this with Next.js?
Yes! Example:Can I use this with Express?
Yes! See the Examples page for complete Express integration examples.Does it work with TypeScript?
Yes! context-window is written in TypeScript with full type definitions:Can I use it in a serverless function?
Yes, but be aware:- Cold starts will be slower (context window initialization)
- Consider creating context windows outside the handler
- Use the registry pattern (
createCtxWindow/getCtxWindow) - May need to increase function timeout
Billing & Costs
How can I reduce costs?
1. Optimize chunk size:Do I get charged for ingestion?
Yes, ingestion costs include:- OpenAI embeddings: ~$0.02 per 1M tokens
- Pinecone storage: Free tier (100K vectors) or paid
What’s included in the free tier?
OpenAI:- New accounts may have trial credits
- After that, pay-per-use
- 1 serverless index
- 100K vectors (~100MB of text)
- Sufficient for testing and small projects