datasets.ts 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497
  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. }
  170. export type SimpleDocumentDetail = InitialDocumentDetail & {
  171. enabled: boolean
  172. word_count: number
  173. error?: string | null
  174. archived: boolean
  175. updated_at: number
  176. hit_count: number
  177. dataset_process_rule_id?: string
  178. data_source_detail_dict?: {
  179. upload_file: {
  180. name: string
  181. extension: string
  182. }
  183. }
  184. }
  185. export type DocumentListResponse = {
  186. data: SimpleDocumentDetail[]
  187. has_more: boolean
  188. total: number
  189. page: number
  190. limit: number
  191. }
  192. export type DocumentReq = {
  193. original_document_id?: string
  194. indexing_technique?: string
  195. doc_form: 'text_model' | 'qa_model'
  196. doc_language: string
  197. process_rule: ProcessRule
  198. }
  199. export type CreateDocumentReq = DocumentReq & {
  200. data_source: DataSource
  201. retrieval_model: RetrievalConfig
  202. }
  203. export type IndexingEstimateParams = DocumentReq & Partial<DataSource> & {
  204. dataset_id: string
  205. }
  206. export type DataSource = {
  207. type: DataSourceType
  208. info_list: {
  209. data_source_type: DataSourceType
  210. notion_info_list?: NotionInfo[]
  211. file_info_list?: {
  212. file_ids: string[]
  213. }
  214. website_info_list?: {
  215. provider: string
  216. job_id: string
  217. urls: string[]
  218. }
  219. }
  220. }
  221. export type NotionInfo = {
  222. workspace_id: string
  223. pages: DataSourceNotionPage[]
  224. }
  225. export type NotionPage = {
  226. page_id: string
  227. type: string
  228. }
  229. export type ProcessRule = {
  230. mode: string
  231. rules: Rules
  232. }
  233. export type createDocumentResponse = {
  234. dataset?: DataSet
  235. batch: string
  236. documents: InitialDocumentDetail[]
  237. }
  238. export type FullDocumentDetail = SimpleDocumentDetail & {
  239. batch: string
  240. created_api_request_id: string
  241. processing_started_at: number
  242. parsing_completed_at: number
  243. cleaning_completed_at: number
  244. splitting_completed_at: number
  245. tokens: number
  246. indexing_latency: number
  247. completed_at: number
  248. paused_by: string
  249. paused_at: number
  250. stopped_at: number
  251. indexing_status: string
  252. disabled_at: number
  253. disabled_by: string
  254. archived_reason: 'rule_modified' | 're_upload'
  255. archived_by: string
  256. archived_at: number
  257. doc_type?: DocType | null | 'others'
  258. doc_metadata?: DocMetadata | null
  259. segment_count: number
  260. [key: string]: any
  261. }
  262. export type DocMetadata = {
  263. title: string
  264. language: string
  265. author: string
  266. publisher: string
  267. publicationDate: string
  268. ISBN: string
  269. category: string
  270. [key: string]: string
  271. }
  272. export const CUSTOMIZABLE_DOC_TYPES = [
  273. 'book',
  274. 'web_page',
  275. 'paper',
  276. 'social_media_post',
  277. 'personal_document',
  278. 'business_document',
  279. 'im_chat_log',
  280. ] as const
  281. export const FIXED_DOC_TYPES = ['synced_from_github', 'synced_from_notion', 'wikipedia_entry'] as const
  282. export type CustomizableDocType = typeof CUSTOMIZABLE_DOC_TYPES[number]
  283. export type FixedDocType = typeof FIXED_DOC_TYPES[number]
  284. export type DocType = CustomizableDocType | FixedDocType
  285. export type DocumentDetailResponse = FullDocumentDetail
  286. export const SEGMENT_STATUS_LIST = ['waiting', 'completed', 'error', 'indexing']
  287. export type SegmentStatus = typeof SEGMENT_STATUS_LIST[number]
  288. export type SegmentsQuery = {
  289. last_id?: string
  290. limit: number
  291. // status?: SegmentStatus
  292. hit_count_gte?: number
  293. keyword?: string
  294. enabled?: boolean
  295. }
  296. export type SegmentDetailModel = {
  297. id: string
  298. position: number
  299. document_id: string
  300. content: string
  301. word_count: number
  302. tokens: number
  303. keywords: string[]
  304. index_node_id: string
  305. index_node_hash: string
  306. hit_count: number
  307. enabled: boolean
  308. disabled_at: number
  309. disabled_by: string
  310. status: SegmentStatus
  311. created_by: string
  312. created_at: number
  313. indexing_at: number
  314. completed_at: number
  315. error: string | null
  316. stopped_at: number
  317. answer?: string
  318. }
  319. export type SegmentsResponse = {
  320. data: SegmentDetailModel[]
  321. has_more: boolean
  322. limit: number
  323. total: number
  324. }
  325. export type HitTestingRecord = {
  326. id: string
  327. content: string
  328. source: 'app' | 'hit_testing' | 'plugin'
  329. source_app_id: string
  330. created_by_role: 'account' | 'end_user'
  331. created_by: string
  332. created_at: number
  333. }
  334. export type HitTesting = {
  335. segment: Segment
  336. score: number
  337. tsne_position: TsnePosition
  338. }
  339. export type Segment = {
  340. id: string
  341. document: Document
  342. content: string
  343. position: number
  344. word_count: number
  345. tokens: number
  346. keywords: string[]
  347. hit_count: number
  348. index_node_hash: string
  349. }
  350. export type Document = {
  351. id: string
  352. data_source_type: string
  353. name: string
  354. doc_type: DocType
  355. }
  356. export type HitTestingRecordsResponse = {
  357. data: HitTestingRecord[]
  358. has_more: boolean
  359. limit: number
  360. total: number
  361. page: number
  362. }
  363. export type TsnePosition = {
  364. x: number
  365. y: number
  366. }
  367. export type HitTestingResponse = {
  368. query: {
  369. content: string
  370. tsne_position: TsnePosition
  371. }
  372. records: Array<HitTesting>
  373. }
  374. export type RelatedApp = {
  375. id: string
  376. name: string
  377. mode: AppMode
  378. icon_type: AppIconType | null
  379. icon: string
  380. icon_background: string
  381. icon_url: string
  382. }
  383. export type RelatedAppResponse = {
  384. data: Array<RelatedApp>
  385. total: number
  386. }
  387. export type SegmentUpdator = {
  388. content: string
  389. answer?: string
  390. keywords?: string[]
  391. }
  392. export enum DocForm {
  393. TEXT = 'text_model',
  394. QA = 'qa_model',
  395. }
  396. export type ErrorDocsResponse = {
  397. data: IndexingStatusResponse[]
  398. total: number
  399. }
  400. export type SelectedDatasetsMode = {
  401. allHighQuality: boolean
  402. allHighQualityVectorSearch: boolean
  403. allHighQualityFullTextSearch: boolean
  404. allEconomic: boolean
  405. mixtureHighQualityAndEconomic: boolean
  406. inconsistentEmbeddingModel: boolean
  407. }
  408. export enum WeightedScoreEnum {
  409. SemanticFirst = 'semantic_first',
  410. KeywordFirst = 'keyword_first',
  411. Customized = 'customized',
  412. }
  413. export enum RerankingModeEnum {
  414. RerankingModel = 'reranking_model',
  415. WeightedScore = 'weighted_score',
  416. }
  417. export const DEFAULT_WEIGHTED_SCORE = {
  418. allHighQualityVectorSearch: {
  419. semantic: 1.0,
  420. keyword: 0,
  421. },
  422. allHighQualityFullTextSearch: {
  423. semantic: 0,
  424. keyword: 1.0,
  425. },
  426. semanticFirst: {
  427. semantic: 0.7,
  428. keyword: 0.3,
  429. },
  430. keywordFirst: {
  431. semantic: 0.3,
  432. keyword: 0.7,
  433. },
  434. other: {
  435. semantic: 0.7,
  436. keyword: 0.3,
  437. },
  438. }