Index Terms: NLP, wink-nlp, singleton, tokenization, analysis
The Unified NLP Service is like the bot's language center—it understands human text. Previously, the bot had multiple copies of this "brain" running (wasting memory). Now there's one shared instance that saves 700MB+ of memory.
It handles:
- Tokenization: Breaking text into words
- Entity recognition: Finding names, places, things
- Sentiment analysis: Understanding emotion
- Intent detection: What does the user want?
Singleton NLP service using wink-nlp with LRU caching for performance.
Location: src/nlp/unifiedNLPService.ts
%%{init: {'theme': 'dark', 'themeVariables': { 'primaryColor': '#3d5a80', 'primaryTextColor': '#e0e0e0', 'lineColor': '#6c757d', 'secondaryColor': '#293241', 'background': '#1a1a2e'}}}%%
flowchart TB
subgraph Service["Unified NLP Service (Singleton)"]
NLP[wink-nlp Instance]
EC[Entity Cache<br/>1000 entries]
SC[Sentiment Cache<br/>1000 entries]
AC[Analysis Cache<br/>500 entries]
end
M[Message] --> Service
Service --> E[Entities]
Service --> S[Sentiment]
Service --> I[Intent]
Service --> T[Topics]
class UnifiedNLPService {
private static instance: UnifiedNLPService;
private nlp: WinkNLP;
private constructor() {
this.nlp = winkNLP(model);
}
static getInstance(): UnifiedNLPService {
if (!UnifiedNLPService.instance) {
UnifiedNLPService.instance = new UnifiedNLPService();
}
return UnifiedNLPService.instance;
}
}| Cache | Size | TTL | Purpose |
|---|---|---|---|
| Entity | 1000 | 15min | NER results |
| Sentiment | 1000 | 15min | Emotion scores |
| Analysis | 500 | 10min | Full analysis |
| Before | After | Savings |
|---|---|---|
| 12 instances × 60MB | 1 instance × 60MB | 700MB+ |
- Entity Extraction - IOC detection
- Intent Classification - Intent detection