[PR #3072] [MERGED] Add tokenizer improvements via Singleton class and estimation #4207

Closed
opened 2026-02-22 18:35:22 -05:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Mintplex-Labs/anything-llm/pull/3072
Author: @timothycarambat
Created: 1/30/2025
Status: Merged
Merged: 1/30/2025
Merged by: @timothycarambat

Base: masterHead: 3069-tokenizer-collector-improvements


📝 Commits (4)

  • 076b802 Add tokenizer improvments via Singleton class
  • 17a8cf8 dev build
  • 2f35df6 Estimation fallback when string exceeds a fixed byte size
  • e9a7e22 Add notice to tiktoken on backend

📊 Changes

19 files changed (+125 additions, -29 deletions)

View changed files

📝 .github/workflows/dev-build.yaml (+1 -1)
📝 collector/processLink/convert/generic.js (+1 -1)
📝 collector/processRawText/index.js (+1 -1)
📝 collector/processSingleFile/convert/asAudio.js (+1 -1)
📝 collector/processSingleFile/convert/asDocx.js (+1 -1)
📝 collector/processSingleFile/convert/asEPub.js (+1 -1)
📝 collector/processSingleFile/convert/asMbox.js (+1 -1)
📝 collector/processSingleFile/convert/asOfficeMime.js (+1 -1)
📝 collector/processSingleFile/convert/asPDF/index.js (+1 -1)
📝 collector/processSingleFile/convert/asTxt.js (+1 -1)
📝 collector/processSingleFile/convert/asXlsx.js (+1 -1)
📝 collector/utils/extensions/Confluence/index.js (+1 -1)
📝 collector/utils/extensions/RepoLoader/GithubRepo/index.js (+1 -1)
📝 collector/utils/extensions/RepoLoader/GitlabRepo/index.js (+1 -1)
📝 collector/utils/extensions/WebsiteDepth/index.js (+1 -1)
📝 collector/utils/extensions/YoutubeTranscript/index.js (+1 -1)
📝 collector/utils/tokenizer/index.js (+59 -8)
📝 server/utils/AiProviders/deepseek/index.js (+4 -1)
📝 server/utils/helpers/tiktoken.js (+46 -4)

📄 Description

Pull Request Type

  • feat
  • 🐛 fix
  • ♻️ refactor
  • 💄 style
  • 🔨 chore
  • 📝 docs

Relevant Issues

resolves #3069

What is in this change?

  • Moves getEncoding function to a singleton type class to prevent multiple reallocation and initialization calls from uploading files or performance tracking chat text tokens.
  • removes .length from tokenizeString calls since it now returns a number and not an array
  • Will do approx string count estimation and at ~10kb of size we will do a simple mathmatical approximation
  • Added JSDoc to functions as well

Additional Information

Developer Validations

  • I ran yarn lint from the root of the repo & committed changes
  • Relevant documentation has been updated
  • I have tested my code functionality
  • Docker build succeeds locally

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Mintplex-Labs/anything-llm/pull/3072 **Author:** [@timothycarambat](https://github.com/timothycarambat) **Created:** 1/30/2025 **Status:** ✅ Merged **Merged:** 1/30/2025 **Merged by:** [@timothycarambat](https://github.com/timothycarambat) **Base:** `master` ← **Head:** `3069-tokenizer-collector-improvements` --- ### 📝 Commits (4) - [`076b802`](https://github.com/Mintplex-Labs/anything-llm/commit/076b80256e0029ea61f6be424e819817d430e003) Add tokenizer improvments via Singleton class - [`17a8cf8`](https://github.com/Mintplex-Labs/anything-llm/commit/17a8cf807351d23fe1b903d1a6b787108ef90407) dev build - [`2f35df6`](https://github.com/Mintplex-Labs/anything-llm/commit/2f35df692c3c414059075f18b86e737386e7b3fe) Estimation fallback when string exceeds a fixed byte size - [`e9a7e22`](https://github.com/Mintplex-Labs/anything-llm/commit/e9a7e2248d4fdd2a111253316e12ac7bb9ca61c0) Add notice to tiktoken on backend ### 📊 Changes **19 files changed** (+125 additions, -29 deletions) <details> <summary>View changed files</summary> 📝 `.github/workflows/dev-build.yaml` (+1 -1) 📝 `collector/processLink/convert/generic.js` (+1 -1) 📝 `collector/processRawText/index.js` (+1 -1) 📝 `collector/processSingleFile/convert/asAudio.js` (+1 -1) 📝 `collector/processSingleFile/convert/asDocx.js` (+1 -1) 📝 `collector/processSingleFile/convert/asEPub.js` (+1 -1) 📝 `collector/processSingleFile/convert/asMbox.js` (+1 -1) 📝 `collector/processSingleFile/convert/asOfficeMime.js` (+1 -1) 📝 `collector/processSingleFile/convert/asPDF/index.js` (+1 -1) 📝 `collector/processSingleFile/convert/asTxt.js` (+1 -1) 📝 `collector/processSingleFile/convert/asXlsx.js` (+1 -1) 📝 `collector/utils/extensions/Confluence/index.js` (+1 -1) 📝 `collector/utils/extensions/RepoLoader/GithubRepo/index.js` (+1 -1) 📝 `collector/utils/extensions/RepoLoader/GitlabRepo/index.js` (+1 -1) 📝 `collector/utils/extensions/WebsiteDepth/index.js` (+1 -1) 📝 `collector/utils/extensions/YoutubeTranscript/index.js` (+1 -1) 📝 `collector/utils/tokenizer/index.js` (+59 -8) 📝 `server/utils/AiProviders/deepseek/index.js` (+4 -1) 📝 `server/utils/helpers/tiktoken.js` (+46 -4) </details> ### 📄 Description ### Pull Request Type <!-- For change type, change [ ] to [x]. --> - [ ] ✨ feat - [ ] 🐛 fix - [x] ♻️ refactor - [ ] 💄 style - [ ] 🔨 chore - [ ] 📝 docs ### Relevant Issues <!-- Use "resolves #xxx" to auto resolve on merge. Otherwise, please use "connect #xxx" --> resolves #3069 ### What is in this change? - Moves `getEncoding` function to a singleton type class to prevent multiple reallocation and initialization calls from uploading files or performance tracking chat text tokens. - removes `.length` from tokenizeString calls since it now returns a number and not an array - Will do approx string count estimation and at ~10kb of size we will do a simple mathmatical approximation - Added JSDoc to functions as well ### Additional Information <!-- Add any other context about the Pull Request here that was not captured above. --> ### Developer Validations <!-- All of the applicable items should be checked. --> - [x] I ran `yarn lint` from the root of the repo & committed changes - [x] Relevant documentation has been updated - [x] I have tested my code functionality - [x] Docker build succeeds locally --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-02-22 18:35:22 -05:00
yindo closed this issue 2026-02-22 18:35:22 -05:00
yindo changed title from [PR #3072] Add tokenizer improvements via Singleton class and estimation to [PR #3072] [MERGED] Add tokenizer improvements via Singleton class and estimation 2026-06-05 15:17:24 -04:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Mintplex-Labs/anything-llm#4207