knowledge.ts
Overview
The knowledge.ts file defines TypeScript interfaces representing various entities related to a knowledge base system. These interfaces specify the shapes of data objects used throughout the knowledge management domain, including knowledge bases, knowledge files, tenants, data chunks, testing results, parser configurations, and knowledge graph structures.
This file acts as a foundational schema layer, providing strong typing for consistent data handling, validation, and interaction between different parts of the knowledge system. It does not contain executable logic, but the interfaces are crucial for ensuring data integrity and facilitating communication between APIs, UI components, parsers, and backend services.
Interfaces and Types
1. IKnowledge
Represents a knowledge base entity in the system.
Property | Type | Description |
|---|---|---|
| Optional avatar or image associated with the KB. | |
|
| Number of chunks in the KB. |
|
| Date when the KB was created (formatted string). |
|
| Creation time as a timestamp or numeric value. |
|
| Identifier of the creator. |
|
| Description or summary of the KB. |
|
| Number of documents included. |
|
| Unique identifier of the KB. |
|
| Name of the knowledge base. |
|
| Configuration settings for the parser. |
|
| Identifier for the parser used. |
|
| Permission level or access control string. |
|
| Threshold for similarity-based operations. |
|
| Current status of the KB (e.g., active, inactive). |
|
| Tenant or organization identifier. |
|
| Number of tokens contained in the KB. |
|
| Last update date. |
|
| Last update time as a timestamp or numeric value. |
|
| Weight factor used for vector similarity calculations. |
|
| Embedding model or vector ID used. |
|
| Optional nickname or alias for the KB. |
|
| Numeric permission level for operators. |
|
| Size of the KB (units not specified, likely bytes or token count). |
Usage example:
const kb: IKnowledge = {
chunk_num: 10,
create_date: "2024-06-01",
create_time: 1685600000,
created_by: "user123",
description: "Technical documentation KB",
doc_num: 5,
id: "kb001",
name: "TechDocs",
parser_config: { chunk_token_num: 512, layout_recognize: true },
parser_id: "parserA",
permission: "read-write",
similarity_threshold: 0.8,
status: "active",
tenant_id: "tenantX",
token_num: 10000,
update_date: "2024-06-10",
update_time: 1686300000,
vector_similarity_weight: 0.5,
embd_id: "embedModel1",
nickname: "TechDocsKB",
operator_permission: 2,
size: 2048,
};
2. IKnowledgeResult
A container for paginated or bulk knowledge base results.
Property | Type | Description |
|---|---|---|
|
| Array of knowledge base entities. |
|
| Total number of knowledge bases available. |
3. Raptor
Parser-related flag indicating usage of a "Raptor" feature.
Property | Type | Description |
|---|---|---|
|
| Indicates if Raptor is used. |
4. ParserConfig
Configuration settings for parsing documents within a knowledge base.
Property | Type | Description |
|---|---|---|
|
| Starting page number to parse. |
|
| Ending page number to parse. |
|
| Number of automatic keywords to extract. |
|
| Number of automatic questions to generate. |
|
| Number of tokens per chunk. |
|
| Delimiter used for chunking. |
|
| Whether to parse HTML for Excel files. |
|
| Whether to use layout recognition. |
|
| Raptor feature configuration. |
|
| IDs of tagged KBs. |
|
| Number of top tags to consider. |
|
| Graphrag feature toggle. |
5. IKnowledgeFileParserConfig
Subset of parser config specifically for knowledge file parsing.
Property | Type | Description |
|---|---|---|
|
| Tokens per chunk. |
|
| Layout recognition enabled or not. |
|
| Array representing page ranges or groups. |
|
| Number of pages to process per task batch. |
6. IKnowledgeFile
Represents a file within a knowledge base, including parsing status and metadata.
Property | Type | Description |
|---|---|---|
|
| Number of chunks in the file. |
|
| Creation date of the file. |
|
| Creation timestamp or numeric time. |
|
| Creator identifier. |
|
| Unique file ID. |
|
| ID of the knowledge base this file belongs to. |
|
| Storage location or path. |
|
| File name. |
|
| ID of the parser used. |
|
| Timestamp when processing started. |
|
| Duration of the parse process in milliseconds. |
|
| Parsing progress percentage (0-100). |
|
| Parsing log or status message. |
|
| Parsing status enum (imported externally). |
|
| File size (probably in bytes). |
|
| Source type (e.g., PDF, DOCX). |
|
| Status of the file (e.g., enabled). |
|
| Optional base64 image thumbnail. |
|
| Number of tokens in the file. |
|
| File type or category. |
|
| Last updated date. |
|
| Last updated timestamp. |
|
| Parser configuration for this file. |
7. ITenantInfo
Represents tenant-specific configuration and identifiers, likely for integration with various AI or processing services.
Property | Type | Description |
|---|---|---|
|
| ASR (Automatic Speech Recognition) service ID. |
|
| Embedding service/model ID. |
|
| Image to Text service ID. |
|
| Large Language Model ID. |
|
| Tenant or organization name. |
|
| Comma-separated parser IDs associated. |
|
| Role designation (e.g., admin, user). |
|
| Unique tenant identifier. |
|
| Chat service or bot ID. |
|
| Speech to text service ID. |
|
| Text to speech service ID. |
8. IChunk
Represents a chunk of content within a document or knowledge file, including keywords and positioning data.
Property | Type | Description |
|---|---|---|
|
| Enable flag (0 = disabled, 1 = enabled). |
|
| Unique chunk identifier. |
|
| Content text possibly annotated with weights. |
|
| Document ID the chunk belongs to. |
|
| Document name. |
|
| Associated image ID if any. |
|
| Array of important keywords related to chunk. |
|
| Question keywords extracted from content. |
|
| Tag keywords associated with the chunk. |
|
| Coordinates or positions within the document. |
|
| Tag features with numeric values. |
9. ITestingChunk
Extended chunk interface used for testing or evaluation purposes, including similarity metrics and vector embeddings.
Property | Type | Description |
|---|---|---|
|
| Chunk identifier. |
|
| Content for long-term knowledge search? |
|
| Content with weighting information. |
|
| Document ID. |
|
| Document name. |
|
| Image ID (possibly deprecated as |
|
| Image ID. |
|
| Array of important keywords. |
|
| Knowledge base ID this chunk belongs to. |
|
| Similarity score. |
|
| Term-based similarity score. |
|
| Embedding vector representation. |
|
| Similarity based on vector comparison. |
|
| Highlighted text or terms. |
|
| Positions in the document. |
|
| Document name keywords. |
|
| Document type keywords. |
10. ITestingDocument
Represents metadata summary for a document in testing contexts.
Property | Type | Description |
|---|---|---|
|
| Number of occurrences or matches. |
|
| Document identifier. |
|
| Document name. |
11. ITestingResult
Testing results container including chunks and documents.
Property | Type | Description |
|---|---|---|
|
| Array of testing chunks. |
|
| Array of testing documents. |
|
| Total number of results. |
|
| Optional label counts or scores. |
12. INextTestingResult
Similar to ITestingResult but with additional properties.
Property | Type | Description |
|---|---|---|
|
| Array of testing chunks. |
|
| Aggregated documents. |
|
| Total count. |
|
| Optional labels. |
|
| Flag indicating if the test has run. |
13. IRenameTag
Defines a rename operation for tags.
Property | Type | Description |
|---|---|---|
|
| Existing tag name. |
|
| New tag name to rename to. |
14. IKnowledgeGraph
Represents a knowledge graph structure and associated mind map visualization data.
Property | Type | Description |
|---|---|---|
|
| Core graph data structure (nodes, edges). |
|
| Tree structure for mind map visualization (from |
Important Implementation Details
The interfaces strongly leverage TypeScript's optional properties (
?) to allow flexible configuration and partial data where applicable.The file imports
RunningStatusfrom an external module (@/constants/knowledge), indicating integration with status enums elsewhere.The
TreeDatatype from@antv/g6suggests the system uses the G6 graph visualization library for rendering mind maps or graph structures.The data models reflect a modular approach separating knowledge base metadata (
IKnowledge), file-specific data (IKnowledgeFile), and granular content chunks (IChunk,ITestingChunk).Parser configuration interfaces allow customization and fine-grained control over document parsing strategies, including page ranges, token chunk sizes, and feature toggles like layout recognition and Raptor usage.
Testing result interfaces provide a structured format for evaluation outputs, supporting similarity metrics, keyword tagging, and document aggregations.
Interactions with Other System Components
Parser Components: The
ParserConfigandIKnowledgeFileParserConfiginterfaces are used by document parsing modules to control how documents within a knowledge base are processed and chunked.Knowledge Management UI: Interfaces like
IKnowledge,IKnowledgeFile, andIChunkprovide typed data structures for frontend components displaying knowledge bases, files, and content chunks.Search and Similarity Engines: The similarity-related fields in
IKnowledge,ITestingChunk, and testing result interfaces suggest integration with vector search or semantic similarity modules.Graph Visualization: The
IKnowledgeGraphinterface integrates with the@antv/g6visualization library, enabling rendering of knowledge graphs and mind maps within the UI.Tenant and Multi-Tenancy: The
ITenantInfointerface supports multi-tenant environments, storing configuration IDs for AI services, parsers, and roles per tenant.Status Tracking:
RunningStatusused inIKnowledgeFileindicates the file’s parsing lifecycle management, probably controlled by backend services.
Visual Diagram
classDiagram
class IKnowledge {
+avatar?: any
+chunk_num: number
+create_date: string
+create_time: number
+created_by: string
+description: string
+doc_num: number
+id: string
+name: string
+parser_config: ParserConfig
+parser_id: string
+permission: string
+similarity_threshold: number
+status: string
+tenant_id: string