Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

7.1 KB
Raw Blame
// for the dataset list
// The data structures returned by the `datasets` interface and `/api/v1/datasets/{id}` are inconsistent.

import { IngestionTaskStatus, RunningStatus } from '@/constants/knowledge';
import { DataSourceKey } from '@/pages/user-setting/data-source/constant';
import { IngestionEventItem } from './ingestion';

export interface IConnector {
  id: string;
  name: string;
  status: RunningStatus;
  source: DataSourceKey;
  auto_parse?: '0' | '1';
}

export interface IDataset {
  avatar?: string;
  chunk_count: number;
  chunk_method: string;
  create_date: string;
  create_time: number;
  created_by: string;
  description?: string;
  document_count: number;
  embedding_model: string;
  embedding_model_name?: string;
  size?: number;
  graphrag_task_finish_at: string;
  graphrag_task_id: Nullable<string>;
  id: string;
  language: string;
  mindmap_task_finish_at: null;
  mindmap_task_id: Nullable<string>;
  name: string;
  nickname: string;
  pagerank: number;
  parser_config: Parserconfig;
  parser_id?: string;
  permission: string;
  pipeline_id: string;
  // Pinned dataflow canvas version (design section 5/C2). Absent or empty
  // means the dataset tracks the canvas latest version.
  pipeline_version_id?: string;
  // True when the pinned version is not the canvas latest (design D1/D2/D3).
  pipeline_version_outdated?: boolean;
  raptor_task_finish_at: string;
  raptor_task_id: string;
  similarity_threshold: number;
  status: string;
  tenant_avatar: string;
  tenant_embd_id: number;
  tenant_id: string;
  operator_permission: number;
  token_num: number;
  update_date: string;
  update_time: number;
  keywords_similarity_weight: number;
  connectors: IConnector[];
}

export type IDatasetFilter = {
  owner: Array<{
    id: string;
    label: string;
    count: number;
  }>;
};

interface Parserconfig {
  auto_keywords: number;
  auto_questions: number;
  children_delimiter: string;
  chunk_token_num: number;
  delimiter: string;
  from_page?: number;
  to_page?: number;
  graphrag: Graphrag;
  html4excel: boolean;
  image_context_size: number;
  layout_recognize: string;
  llm_id: string;
  metadata?: any;
  built_in_metadata?: Array<{ key: string; type: string }>;
  enable_metadata?: boolean;
  parent_child: Parentchild;
  raptor: Raptor;
  table_context_size: number;
  tag_kb_ids?: string[];
  topn_tags: number;
}

interface Raptor {
  clustering_method?: 'gmm' | 'ahc';
  max_cluster: number;
  max_token: number;
  prompt: string;
  random_seed: number;
  threshold: number;
  tree_builder?: 'raptor' | 'psi';
  use_raptor: boolean;
}

interface Parentchild {
  children_delimiter: string;
  use_parent_child: boolean;
}

interface Graphrag {
  batch_chunk_token_size?: number;
  entity_types: string[];
  method: string;
  use_graphrag: boolean;
}

export interface IDatasetListResult {
  kbs: IDataset[];
  total_datasets: number;
}

// Types migrated from knowledge.ts

export interface IKnowledgeFileParserConfig {
  chunk_token_num: number;
  layout_recognize: boolean;
  pages: number[][];
  task_page_size: number;
}

export interface IKnowledgeFile {
  chunk_num: number;
  create_date: string;
  create_time: number;
  created_by: string;
  id: string;
  kb_id: string;
  location: string;
  name: string;
  parser_id: string;
  process_begin_at?: any;
  process_duration: number;
  progress: number; // parsing process
  progress_msg: string; // parsing log
  latest_ingestion_event?: IngestionEventItem | null;
  // Python backend only. The Go backend removed this field and reports
  // parsing state exclusively through ingestion_status.
  run?: RunningStatus; // parsing status
  ingestion_status?: IngestionTaskStatus;
  size: number;
  source_type: string;
  status: string; // enabled
  thumbnail?: any; // base64
  token_num: number;
  type: string;
  update_date: string;
  update_time: number;
  parser_config: IKnowledgeFileParserConfig;
}

export interface ITenantInfo {
  name: string;
  parser_ids: string;
  role: string;
  tenant_id: string;
}

export type ChunkDocType = 'image' | 'table' | 'text';

export interface IChunk {
  available_int: number; // Whether to enable, 0: not enabled, 1: enabled
  chunk_id: string;
  content_with_weight: string;
  doc_id: string;
  doc_name: string;
  doc_type_kwd?: ChunkDocType;
  document_url?: string;
  image_id: string;
  important_kwd?: string[];
  question_kwd?: string[]; // keywords
  tag_kwd?: string[];
  positions: number[][];
  tag_feas?: Record<string, number>;
}

export interface ITestingChunk {
  id: string;
  content_ltks: string;
  content: string;
  document_id: string;
  document_keyword: string;
  image_id: string;
  important_keywords: any[];
  questions?: any[];
  dataset_id: string;
  similarity: number;
  term_similarity: number;
  vector_similarity: number;
  highlight: string;
  positions: number[][];
  doc_type_kwd: string;
}

export interface ITestingDocument {
  count: number;
  doc_id: string;
  doc_name: string;
}

export interface ITestingResult {
  chunks: ITestingChunk[];
  documents: ITestingDocument[];
  total: number;
  labels?: Record<string, number>;
}

export interface INextTestingResult {
  chunks: ITestingChunk[];
  doc_aggs: ITestingDocument[];
  total: number;
  labels?: Record<string, number>;
  isRuned?: boolean;
}

export type IRenameTag = { fromTag: string; toTag: string };

export interface IKnowledgeGraph {
  graph: Record<string, any>;
  mind_map: import('@antv/g6/lib/types').TreeData;
}

export interface IArtifact {
  slug: string;
  title: string;
  page_type?: string;
  summary?: string;
}

export interface IArtifactTopic {
  topic: string;
  title: string;
  slug: string;
  page_count?: number;
}

export interface IArtifactPage {
  slug: string;
  title: string;
  page_type: string;
  content_md_rendered: string;
  summary: string;
  entity_names: string[];
  outlinks: string[];
  related_kb_pages: string[];
  source_chunk_ids: string[];
  source_doc_ids: string[];
}

export interface IWikiCommit {
  id: string;
  title: string;
  comments: string;
  user_id: string;
  create_time: number;
  create_date: string;
  user_nickname: string;
}

export interface IWikiCommitDetail extends IWikiCommit {
  diff: string;
  content_after: string;
}

export interface IWikiCommitListResponse {
  total: number;
  items: IWikiCommit[];
}

export interface IArtifactGraphEntity {
  slug: string;
  name: string;
  aliases: string[];
  description: string;
  type: string;
  weight: number;
  source_chunk_ids?: string[];
}

export interface IArtifactAlteration {
  removed: number;
  newly_uploaded: number;
  changed: number;
  removed_doc_ids: string[];
  newly_uploaded_doc_ids: string[];
  changed_doc_ids: string[];
  involved_doc_ids: string[];
  eligible_doc_ids: string[];
  retry_required?: boolean;
  retry_page_count?: number;
  retry_page_slugs?: string[];
}

export interface IArtifactGraphRelation {
  from: string;
  to: string;
  type?: string;
}

export interface IArtifactGraph {
  entities: IArtifactGraphEntity[];
  relations: IArtifactGraphRelation[];
  total_entities?: number;
  returned_entities?: number;
}

// Permission types for dataset configuration
export type DatasetTestingPermission = 'me' | 'team';
export type DatasetParsingPermission = 'me' | 'team';