A simple RAG (Retrieval-Augmented Generation) library that lets you ask questions about your documents using OpenAI and Pinecone.
npm install context-windowOPENAI_API_KEY=sk-...
PINECONE_API_KEY=...
PINECONE_INDEX=context-window
PINECONE_ENVIRONMENT=us-east-1import { createCtxWindow, getCtxWindow } from "context-window";
// Ingest documents
await createCtxWindow({
namespace: "my-docs",
data: ["./my-book.pdf"], // .txt, .md, .pdf supported
ai: { provider: "openai", model: "gpt-4o-mini" },
vectorStore: { provider: "pinecone" }
});
// Ask questions
const cw = getCtxWindow("my-docs");
const { text, sources } = await cw.ask("What is this document about?");
console.log(text);
console.log(sources);createCtxWindow(options) - Ingest documents and create a context window
namespace: Unique identifierdata: File paths or directories (.txt,.md,.pdf)ai:{ provider: "openai", model?: "gpt-4o-mini" }vectorStore:{ provider: "pinecone" }chunk:{ size?: 1000, overlap?: 150 }limits:{ topK?: 8, maxContextChars?: 8000, scoreThreshold?: 0 }
getCtxWindow(namespace) - Retrieve a context window
cw.ask(question) - Returns { text: string, sources: string[] }
hasCtxWindow(namespace)- Check if existsdeleteCtxWindow(namespace)- Remove from registryclearCtxWindows()- Clear alllistCtxWindows()- List all
MIT