knowledge.ts
Overview
The knowledge.ts file defines a collection of enumerations (enums) and constant objects that provide standardized keys, status codes, configuration presets, and type definitions used throughout a knowledge management or AI-driven application. These definitions facilitate consistent referencing of routes, running statuses, model variable presets, model types, document types, and parser types.
This file acts as a central reference point for key constants related to knowledge processing workflows, model configurations, and document handling, enabling cleaner code elsewhere in the system by preventing magic strings and hardcoded values.
Detailed Explanation of Enums and Constants
1. KnowledgeRouteKey (enum)
Defines route keys for navigating or referencing different functional areas related to knowledge management.
Member | Value | Description |
|---|---|---|
|
| Route key for dataset management |
| Route key for testing functionality | |
| Route key for configuration settings | |
| Route key for knowledge graph visualization or interaction |
Usage Example:
import { KnowledgeRouteKey } from './knowledge';
function navigateTo(routeKey: KnowledgeRouteKey) {
console.log(`Navigating to ${routeKey}`);
}
navigateTo(KnowledgeRouteKey.Dataset); // Output: Navigating to dataset
2. DatasetBaseKey (constant)
A string constant set to 'dataset', providing a base key related to dataset identification or storage.
Usage Example:
console.log(DatasetBaseKey); // Output: dataset
3. RunningStatus (enum)
Represents the different states of a running process or task, likely within asynchronous operations such as model training, data processing, or job execution.
Member | Value | Description |
|---|---|---|
| '0' | Task has not started (needs to run) |
| '1' | Task is currently running (can be canceled) |
| '2' | Task was canceled (needs refresh) |
| '3' | Task completed successfully (needs refresh) |
| '4' | Task failed (needs refresh) |
Usage Example:
function isTaskActive(status: RunningStatus): boolean {
return status === RunningStatus.RUNNING;
}
console.log(isTaskActive(RunningStatus.RUNNING)); // true
console.log(isTaskActive(RunningStatus.DONE)); // false
4. ModelVariableType (enum)
Defines preset categories for model behavior tuning, influencing how the model responds in terms of creativity, precision, or balance.
Member | Value | Description |
|---|---|---|
| 'Improvise' | Model behaves creatively, more exploratory |
| 'Precise' | Model behaves conservatively, precise outputs |
| 'Balance' | Balanced approach between creativity and precision |
5. settledModelVariableMap (constant object)
Maps each ModelVariableType to a configuration object containing parameters used to control the behavior of language models (e.g., GPT-like models).
Parameters explained:
Parameter | Description |
|---|---|
| Controls randomness in output; higher values = more random |
| Nucleus sampling threshold; limits which tokens can be chosen |
| Penalizes repeated tokens based on frequency |
| Penalizes repeated tokens based on presence |
| Maximum number of tokens generated |
Configuration per model type:
ModelVariableType | temperature | top_p | frequency_penalty | presence_penalty | max_tokens |
|---|---|---|---|---|---|
Improvise | 0.8 | 0.9 | 0.1 | 0.1 | 4096 |
Precise | 0.2 | 0.75 | 0.5 | 0.5 | 4096 |
Balance | 0.5 | 0.85 | 0.3 | 0.2 | 4096 |
Usage Example:
import { settledModelVariableMap, ModelVariableType } from './knowledge';
const preciseConfig = settledModelVariableMap[ModelVariableType.Precise];
console.log(preciseConfig.temperature); // 0.2
6. LlmModelType (enum)
Enumerates types of large language models or AI model categories supported by the system.
Member | Value | Description |
|---|---|---|
| 'embedding' | Models that generate embeddings |
| 'chat' | Conversational/chat-based models |
| 'image2text' | Models converting images to text |
| 'speech2text' | Speech recognition models |
| 'rerank' | Models that rerank or reorder results |
| 'tts' | Text-to-speech models |
7. KnowledgeSearchParams (enum)
Defines standard parameter keys used in searching or querying knowledge bases or documents.
Member | Value | Description |
|---|---|---|
| 'doc_id' | Parameter key for document ID |
| 'id' | Parameter key for knowledge entry ID |
8. DocumentType (enum)
Specifies types of documents handled by the system.
Member | Value | Description |
|---|---|---|
| 'virtual' | Documents represented virtually (e.g., metadata or abstract) |
| 'visual' | Documents with visual content (e.g., images, scans) |
9. DocumentParserType (enum)
Enumerates available document parser types for processing various document formats or content types, likely used in ingestion or extraction workflows.
Member | Value | Description |
|---|---|---|
| 'naive' | Basic or generic parser |
| 'qa' | Question-answering optimized parser |
| 'resume' | Resume parser |
| 'manual' | Manually configured parser |
| 'table' | Table-structured document parser |
| 'paper' | Academic paper parser |
| 'book' | Book content parser |
| 'laws' | Legal document parser |
| 'presentation' | Slide/presentation parser |
| 'picture' | Image document parser |
| 'one' | Possibly a single page or unified parser |
| 'audio' | Audio content parser |
| 'email' | Email parser |
| 'tag' | Tag metadata parser |
| 'knowledge_graph' | Knowledge graph parser |
Implementation Details and Algorithms
Enums are implemented using TypeScript's
enumand constant objects to ensure type safety and easy referencing throughout the codebase.The
settledModelVariableMapprovides a pre-configured mapping of AI model parameters to facilitate quick model configuration without recalculating or redefining parameters.The file does not include any algorithms or functions; instead, it serves as a static configuration and enumeration resource.
By using string enums and constants, this file ensures consistency in keys and values used across the system, which is critical for routing, status handling, and model configuration.
Interaction with Other Parts of the System
Routing and Navigation:
KnowledgeRouteKeyis likely used by UI components or routing modules to determine page views or API endpoints.Task Management:
RunningStatusintegrates with task schedulers, job managers, or asynchronous process controllers to track and control task lifecycle.Model Configuration:
ModelVariableTypeandsettledModelVariableMapare used by AI model handlers or services to initialize and tune model parameters dynamically.Document Processing:
DocumentTypeandDocumentParserTypeare used by document ingestion pipelines, parsers, or extractors to select appropriate parsing strategies.Search and Retrieval:
KnowledgeSearchParamskeys are used in query construction or API calls related to knowledge base searches.Model Handling:
LlmModelTypehelps determine the type of AI model to instantiate or invoke for a given task (e.g., embedding generation vs chat).
This file is foundational and referenced by multiple modules including UI routing, backend services for task management, AI model pipelines, and document ingestion workflows.
Mermaid Diagram
classDiagram
class KnowledgeRouteKey {
<<enumeration>>
+Dataset: string
+Testing: string
+Configuration: string
+KnowledgeGraph: string
}
class RunningStatus {
<<enumeration>>
+UNSTART: string
+RUNNING: string
+CANCEL: string
+DONE: string
+FAIL: string
}
class ModelVariableType {
<<enumeration>>
+Improvise: string
+Precise: string
+Balance: string
}
class SettledModelVariableMap {
<<constant>>
+Improvise: ModelParameters
+Precise: ModelParameters
+Balance: ModelParameters
}
class ModelParameters {
+temperature: number
+top_p: number
+frequency_penalty: number
+presence_penalty: number
+max_tokens: number
}
class LlmModelType {
<<enumeration>>
+Embedding: string
+Chat: string
+Image2text: string
+Speech2text: string
+Rerank: string
+TTS: string
}
class KnowledgeSearchParams {
<<enumeration>>
+DocumentId: string
+KnowledgeId: string
}
class DocumentType {
<<enumeration>>
+Virtual: string
+Visual: string
}
class DocumentParserType {
<<enumeration>>
+Naive: string
+Qa: string
+Resume: string
+Manual: string
+Table: string
+Paper: string
+Book: string
+Laws: string
+Presentation: string
+Picture: string
+One: string
+Audio: string
+Email: string
+Tag: string
+KnowledgeGraph: string
}
SettledModelVariableMap --> ModelParameters
Summary
The knowledge.ts file is a core configuration and enumeration module for a knowledge-centric application. It standardizes keys and parameters for routing, status management, AI model configurations, and document parsing. It does not contain executable logic but provides essential constants that other system components rely on for consistent operation. Its use improves maintainability, reduces errors from hardcoded strings, and organizes critical configuration data in a centralized location.