UNPKG

@forge-ml/rag

Version:

A RAG (Retrieval-Augmented Generation) package for Forge ML

11 lines (10 loc) 375 B
export const estimateTokens = (chunks) => { return chunks.reduce((total, chunk) => { // Estimate tokens using a simple heuristic (4 characters per token) const estimatedTokens = Math.ceil(chunk.text.length / 4); return total + estimatedTokens; }, 0); }; export const estimateTokensByLength = (length) => { return Math.ceil(length / 4); };