datasets.ts 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  1. import type { DataSourceNotionPage } from './common'
  2. import type { AppIconType, AppMode, RetrievalConfig } from '@/types/app'
  3. import type { Tag } from '@/app/components/base/tag-management/constant'
  4. export enum DataSourceType {
  5. FILE = 'upload_file',
  6. NOTION = 'notion_import',
  7. WEB = 'website_crawl',
  8. }
  9. export type DatasetPermission = 'only_me' | 'all_team_members' | 'partial_members'
  10. export type DataSet = {
  11. id: string
  12. name: string
  13. icon: string
  14. icon_background: string
  15. description: string
  16. permission: DatasetPermission
  17. data_source_type: DataSourceType
  18. indexing_technique: 'high_quality' | 'economy'
  19. created_by: string
  20. updated_by: string
  21. updated_at: number
  22. app_count: number
  23. document_count: number
  24. word_count: number
  25. embedding_model: string
  26. embedding_model_provider: string
  27. embedding_available: boolean
  28. retrieval_model_dict: RetrievalConfig
  29. retrieval_model: RetrievalConfig
  30. tags: Tag[]
  31. partial_member_list?: any[]
  32. }
  33. export type CustomFile = File & {
  34. id?: string
  35. extension?: string
  36. mime_type?: string
  37. created_by?: string
  38. created_at?: number
  39. }
  40. export type CrawlOptions = {
  41. crawl_sub_pages: boolean
  42. only_main_content: boolean
  43. includes: string
  44. excludes: string
  45. limit: number | string
  46. max_depth: number | string
  47. }
  48. export type CrawlResultItem = {
  49. title: string
  50. markdown: string
  51. description: string
  52. source_url: string
  53. }
  54. export type FileItem = {
  55. fileID: string
  56. file: CustomFile
  57. progress: number
  58. }
  59. export type DataSetListResponse = {
  60. data: DataSet[]
  61. has_more: boolean
  62. limit: number
  63. page: number
  64. total: number
  65. }
  66. export type QA = {
  67. question: string
  68. answer: string
  69. }
  70. export type IndexingEstimateResponse = {
  71. tokens: number
  72. total_price: number
  73. currency: string
  74. total_segments: number
  75. preview: string[]
  76. qa_preview?: QA[]
  77. }
  78. export type FileIndexingEstimateResponse = {
  79. total_nodes: number
  80. } & IndexingEstimateResponse
  81. export type IndexingStatusResponse = {
  82. id: string
  83. indexing_status: DocumentIndexingStatus
  84. processing_started_at: number
  85. parsing_completed_at: number
  86. cleaning_completed_at: number
  87. splitting_completed_at: number
  88. completed_at: any
  89. paused_at: any
  90. error: any
  91. stopped_at: any
  92. completed_segments: number
  93. total_segments: number
  94. }
  95. export type IndexingStatusBatchResponse = {
  96. data: IndexingStatusResponse[]
  97. }
  98. export type ProcessMode = 'automatic' | 'custom'
  99. export type ProcessRuleResponse = {
  100. mode: ProcessMode
  101. rules: Rules
  102. }
  103. export type Rules = {
  104. pre_processing_rules: PreProcessingRule[]
  105. segmentation: Segmentation
  106. }
  107. export type PreProcessingRule = {
  108. id: string
  109. enabled: boolean
  110. }
  111. export type Segmentation = {
  112. separator: string
  113. max_tokens: number
  114. chunk_overlap: number
  115. }
  116. export const DocumentIndexingStatusList = [
  117. 'waiting',
  118. 'parsing',
  119. 'cleaning',
  120. 'splitting',
  121. 'indexing',
  122. 'paused',
  123. 'error',
  124. 'completed',
  125. ] as const
  126. export type DocumentIndexingStatus = typeof DocumentIndexingStatusList[number]
  127. export const DisplayStatusList = [
  128. 'queuing',
  129. 'indexing',
  130. 'paused',
  131. 'error',
  132. 'available',
  133. 'enabled',
  134. 'disabled',
  135. 'archived',
  136. ] as const
  137. export type DocumentDisplayStatus = typeof DisplayStatusList[number]
  138. export type DataSourceInfo = {
  139. upload_file: {
  140. id: string
  141. name: string
  142. size: number
  143. mime_type: string
  144. created_at: number
  145. created_by: string
  146. extension: string
  147. }
  148. notion_page_icon?: string
  149. job_id: string
  150. url: string
  151. }
  152. export type InitialDocumentDetail = {
  153. id: string
  154. batch: string
  155. position: number
  156. dataset_id: string
  157. data_source_type: DataSourceType
  158. data_source_info: DataSourceInfo
  159. dataset_process_rule_id: string
  160. name: string
  161. created_from: 'api' | 'web'
  162. created_by: string
  163. created_at: number
  164. indexing_status: DocumentIndexingStatus
  165. display_status: DocumentDisplayStatus
  166. completed_segments?: number
  167. total_segments?: number
  168. doc_form: 'text_model' | 'qa_model'
  169. doc_language: string
  170. }
  171. export type SimpleDocumentDetail = InitialDocumentDetail & {
  172. enabled: boolean
  173. word_count: number
  174. error?: string | null
  175. archived: boolean
  176. updated_at: number
  177. hit_count: number
  178. dataset_process_rule_id?: string
  179. data_source_detail_dict?: {
  180. upload_file: {
  181. name: string
  182. extension: string
  183. }
  184. }
  185. }
  186. export type DocumentListResponse = {
  187. data: SimpleDocumentDetail[]
  188. has_more: boolean
  189. total: number
  190. page: number
  191. limit: number
  192. }
  193. export type DocumentReq = {
  194. original_document_id?: string
  195. indexing_technique?: string
  196. doc_form: 'text_model' | 'qa_model'
  197. doc_language: string
  198. process_rule: ProcessRule
  199. }
  200. export type CreateDocumentReq = DocumentReq & {
  201. data_source: DataSource
  202. retrieval_model: RetrievalConfig
  203. }
  204. export type IndexingEstimateParams = DocumentReq & Partial<DataSource> & {
  205. dataset_id: string
  206. }
  207. export type DataSource = {
  208. type: DataSourceType
  209. info_list: {
  210. data_source_type: DataSourceType
  211. notion_info_list?: NotionInfo[]
  212. file_info_list?: {
  213. file_ids: string[]
  214. }
  215. website_info_list?: {
  216. provider: string
  217. job_id: string
  218. urls: string[]
  219. }
  220. }
  221. }
  222. export type NotionInfo = {
  223. workspace_id: string
  224. pages: DataSourceNotionPage[]
  225. }
  226. export type NotionPage = {
  227. page_id: string
  228. type: string
  229. }
  230. export type ProcessRule = {
  231. mode: string
  232. rules: Rules
  233. }
  234. export type createDocumentResponse = {
  235. dataset?: DataSet
  236. batch: string
  237. documents: InitialDocumentDetail[]
  238. }
  239. export type FullDocumentDetail = SimpleDocumentDetail & {
  240. batch: string
  241. created_api_request_id: string
  242. processing_started_at: number
  243. parsing_completed_at: number
  244. cleaning_completed_at: number
  245. splitting_completed_at: number
  246. tokens: number
  247. indexing_latency: number
  248. completed_at: number
  249. paused_by: string
  250. paused_at: number
  251. stopped_at: number
  252. indexing_status: string
  253. disabled_at: number
  254. disabled_by: string
  255. archived_reason: 'rule_modified' | 're_upload'
  256. archived_by: string
  257. archived_at: number
  258. doc_type?: DocType | null | 'others'
  259. doc_metadata?: DocMetadata | null
  260. segment_count: number
  261. [key: string]: any
  262. }
  263. export type DocMetadata = {
  264. title: string
  265. language: string
  266. author: string
  267. publisher: string
  268. publicationDate: string
  269. ISBN: string
  270. category: string
  271. [key: string]: string
  272. }
  273. export const CUSTOMIZABLE_DOC_TYPES = [
  274. 'book',
  275. 'web_page',
  276. 'paper',
  277. 'social_media_post',
  278. 'personal_document',
  279. 'business_document',
  280. 'im_chat_log',
  281. ] as const
  282. export const FIXED_DOC_TYPES = ['synced_from_github', 'synced_from_notion', 'wikipedia_entry'] as const
  283. export type CustomizableDocType = typeof CUSTOMIZABLE_DOC_TYPES[number]
  284. export type FixedDocType = typeof FIXED_DOC_TYPES[number]
  285. export type DocType = CustomizableDocType | FixedDocType
  286. export type DocumentDetailResponse = FullDocumentDetail
  287. export const SEGMENT_STATUS_LIST = ['waiting', 'completed', 'error', 'indexing']
  288. export type SegmentStatus = typeof SEGMENT_STATUS_LIST[number]
  289. export type SegmentsQuery = {
  290. last_id?: string
  291. limit: number
  292. // status?: SegmentStatus
  293. hit_count_gte?: number
  294. keyword?: string
  295. enabled?: boolean
  296. }
  297. export type SegmentDetailModel = {
  298. id: string
  299. position: number
  300. document_id: string
  301. content: string
  302. word_count: number
  303. tokens: number
  304. keywords: string[]
  305. index_node_id: string
  306. index_node_hash: string
  307. hit_count: number
  308. enabled: boolean
  309. disabled_at: number
  310. disabled_by: string
  311. status: SegmentStatus
  312. created_by: string
  313. created_at: number
  314. indexing_at: number
  315. completed_at: number
  316. error: string | null
  317. stopped_at: number
  318. answer?: string
  319. }
  320. export type SegmentsResponse = {
  321. data: SegmentDetailModel[]
  322. has_more: boolean
  323. limit: number
  324. total: number
  325. }
  326. export type HitTestingRecord = {
  327. id: string
  328. content: string
  329. source: 'app' | 'hit_testing' | 'plugin'
  330. source_app_id: string
  331. created_by_role: 'account' | 'end_user'
  332. created_by: string
  333. created_at: number
  334. }
  335. export type HitTesting = {
  336. segment: Segment
  337. score: number
  338. tsne_position: TsnePosition
  339. }
  340. export type Segment = {
  341. id: string
  342. document: Document
  343. content: string
  344. position: number
  345. word_count: number
  346. tokens: number
  347. keywords: string[]
  348. hit_count: number
  349. index_node_hash: string
  350. }
  351. export type Document = {
  352. id: string
  353. data_source_type: string
  354. name: string
  355. doc_type: DocType
  356. }
  357. export type HitTestingRecordsResponse = {
  358. data: HitTestingRecord[]
  359. has_more: boolean
  360. limit: number
  361. total: number
  362. page: number
  363. }
  364. export type TsnePosition = {
  365. x: number
  366. y: number
  367. }
  368. export type HitTestingResponse = {
  369. query: {
  370. content: string
  371. tsne_position: TsnePosition
  372. }
  373. records: Array<HitTesting>
  374. }
  375. export type RelatedApp = {
  376. id: string
  377. name: string
  378. mode: AppMode
  379. icon_type: AppIconType | null
  380. icon: string
  381. icon_background: string
  382. icon_url: string
  383. }
  384. export type RelatedAppResponse = {
  385. data: Array<RelatedApp>
  386. total: number
  387. }
  388. export type SegmentUpdator = {
  389. content: string
  390. answer?: string
  391. keywords?: string[]
  392. }
  393. export enum DocForm {
  394. TEXT = 'text_model',
  395. QA = 'qa_model',
  396. }
  397. export type ErrorDocsResponse = {
  398. data: IndexingStatusResponse[]
  399. total: number
  400. }
  401. export type SelectedDatasetsMode = {
  402. allHighQuality: boolean
  403. allHighQualityVectorSearch: boolean
  404. allHighQualityFullTextSearch: boolean
  405. allEconomic: boolean
  406. mixtureHighQualityAndEconomic: boolean
  407. inconsistentEmbeddingModel: boolean
  408. }
  409. export enum WeightedScoreEnum {
  410. SemanticFirst = 'semantic_first',
  411. KeywordFirst = 'keyword_first',
  412. Customized = 'customized',
  413. }
  414. export enum RerankingModeEnum {
  415. RerankingModel = 'reranking_model',
  416. WeightedScore = 'weighted_score',
  417. }
  418. export const DEFAULT_WEIGHTED_SCORE = {
  419. allHighQualityVectorSearch: {
  420. semantic: 1.0,
  421. keyword: 0,
  422. },
  423. allHighQualityFullTextSearch: {
  424. semantic: 0,
  425. keyword: 1.0,
  426. },
  427. semanticFirst: {
  428. semantic: 0.7,
  429. keyword: 0.3,
  430. },
  431. keywordFirst: {
  432. semantic: 0.3,
  433. keyword: 0.7,
  434. },
  435. other: {
  436. semantic: 0.7,
  437. keyword: 0.3,
  438. },
  439. }