AI-powered document analysis and question answering system
npm install doc-clerk
const DocClerk = require('doc-clerk');
const clerk = new DocClerk({ apiKey: process.env.OPENAI_KEY });
clerk.ingest('./documents/report.pdf');
const answer = await clerk.ask('What were Q3 revenues?');
console.log(answer);Chunks documents, builds embeddings, retrieves relevant context for LLM queries. Supports PDF, DOCX, TXT, MD. Uses OpenAI by default but works with local models via Ollama.
Indexing happens in memory by default. For persistence, pass { storage: 'sqlite' } or implement custom storage adapter.
const clerk = new DocClerk({
apiKey: process.env.OPENAI_KEY,
storage: 'sqlite',
dbPath: './doc-index.db',
chunkSize: 1000,
chunkOverlap: 200,
model: 'gpt-4'
});
// Batch ingest
await clerk.ingestDir('./docs', { recursive: true });
// Stream responses
const stream = clerk.askStream('Summarize key findings');
for await (const chunk of stream) {
process.stdout.write(chunk);
}
// Get citations
const result = await clerk.ask('What is the policy?', { citations: true });
console.log(result.answer);
console.log(result.sources); // [{ file: 'policy.pdf', page: 3, snippet: '...' }]
// Use local model
const localClerk = new DocClerk({
provider: 'ollama',
model: 'llama2',
embedModel: 'nomic-embed-text'
});MIT