datasets.ts 11 KB

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