A TypeScript library for processing large text inputs using AI models through chunking and recursive generation.
npm install cag-algorithm
- Text chunking with configurable size and overlap
- Sequential and recursive processing modes
- Configurable iteration limits and output token limits
- TypeScript support
- Built on LangChain's text splitters
import { CAG } from 'cag-algorithm';
// Configure CAG
const config = {
chunkSize: 1000,
chunkOverlap: 200,
iteration_limit: 5,
iteration_output_token_limit: 2000
};
// Create prompt template
const promptTemplate = "Please summarize the following text: {text}";
// Initialize CAG
const cag = new CAG(config, promptTemplate);
// Process text sequentially
const sequentialResult = await cag.generate_sequential(longText);
// Process text recursively
const recursiveResult = await cag.generate_recursive(longText);
chunkSize
: Number of characters per chunkchunkOverlap
: Number of characters to overlap between chunksiteration_limit
: Maximum number of recursive iterationsiteration_output_token_limit
: Target length for output text
- Browser environment with
window.ai
available - Node.js 14.0.0 or higher
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.