datasets.ts 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
  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. 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. job_id: string
  207. url: string
  208. }
  209. export type InitialDocumentDetail = {
  210. id: string
  211. batch: string
  212. position: number
  213. dataset_id: string
  214. data_source_type: DataSourceType
  215. data_source_info: DataSourceInfo
  216. dataset_process_rule_id: string
  217. name: string
  218. created_from: 'api' | 'web'
  219. created_by: string
  220. created_at: number
  221. indexing_status: DocumentIndexingStatus
  222. display_status: DocumentDisplayStatus
  223. completed_segments?: number
  224. total_segments?: number
  225. doc_form: 'text_model' | 'qa_model'
  226. doc_language: string
  227. }
  228. export type SimpleDocumentDetail = InitialDocumentDetail & {
  229. enabled: boolean
  230. word_count: number
  231. error?: string | null
  232. archived: boolean
  233. updated_at: number
  234. hit_count: number
  235. dataset_process_rule_id?: string
  236. data_source_detail_dict?: {
  237. upload_file: {
  238. name: string
  239. extension: string
  240. }
  241. }
  242. }
  243. export type DocumentListResponse = {
  244. data: SimpleDocumentDetail[]
  245. has_more: boolean
  246. total: number
  247. page: number
  248. limit: number
  249. }
  250. export type DocumentReq = {
  251. original_document_id?: string
  252. indexing_technique?: string
  253. doc_form: 'text_model' | 'qa_model'
  254. doc_language: string
  255. process_rule: ProcessRule
  256. }
  257. export type CreateDocumentReq = DocumentReq & {
  258. data_source: DataSource
  259. retrieval_model: RetrievalConfig
  260. embedding_model: string
  261. embedding_model_provider: string
  262. }
  263. export type IndexingEstimateParams = DocumentReq & Partial<DataSource> & {
  264. dataset_id: string
  265. }
  266. export type DataSource = {
  267. type: DataSourceType
  268. info_list: {
  269. data_source_type: DataSourceType
  270. notion_info_list?: NotionInfo[]
  271. file_info_list?: {
  272. file_ids: string[]
  273. }
  274. website_info_list?: {
  275. provider: string
  276. job_id: string
  277. urls: string[]
  278. }
  279. }
  280. }
  281. export type NotionInfo = {
  282. workspace_id: string
  283. pages: DataSourceNotionPage[]
  284. }
  285. export type NotionPage = {
  286. page_id: string
  287. type: string
  288. }
  289. export type ProcessRule = {
  290. mode: string
  291. rules: Rules
  292. }
  293. export type createDocumentResponse = {
  294. dataset?: DataSet
  295. batch: string
  296. documents: InitialDocumentDetail[]
  297. }
  298. export type FullDocumentDetail = SimpleDocumentDetail & {
  299. batch: string
  300. created_api_request_id: string
  301. processing_started_at: number
  302. parsing_completed_at: number
  303. cleaning_completed_at: number
  304. splitting_completed_at: number
  305. tokens: number
  306. indexing_latency: number
  307. completed_at: number
  308. paused_by: string
  309. paused_at: number
  310. stopped_at: number
  311. indexing_status: string
  312. disabled_at: number
  313. disabled_by: string
  314. archived_reason: 'rule_modified' | 're_upload'
  315. archived_by: string
  316. archived_at: number
  317. doc_type?: DocType | null | 'others'
  318. doc_metadata?: DocMetadata | null
  319. segment_count: number
  320. [key: string]: any
  321. }
  322. export type DocMetadata = {
  323. title: string
  324. language: string
  325. author: string
  326. publisher: string
  327. publicationDate: string
  328. ISBN: string
  329. category: string
  330. [key: string]: string
  331. }
  332. export const CUSTOMIZABLE_DOC_TYPES = [
  333. 'book',
  334. 'web_page',
  335. 'paper',
  336. 'social_media_post',
  337. 'personal_document',
  338. 'business_document',
  339. 'im_chat_log',
  340. ] as const
  341. export const FIXED_DOC_TYPES = ['synced_from_github', 'synced_from_notion', 'wikipedia_entry'] as const
  342. export type CustomizableDocType = typeof CUSTOMIZABLE_DOC_TYPES[number]
  343. export type FixedDocType = typeof FIXED_DOC_TYPES[number]
  344. export type DocType = CustomizableDocType | FixedDocType
  345. export type DocumentDetailResponse = FullDocumentDetail
  346. export const SEGMENT_STATUS_LIST = ['waiting', 'completed', 'error', 'indexing']
  347. export type SegmentStatus = typeof SEGMENT_STATUS_LIST[number]
  348. export type SegmentsQuery = {
  349. last_id?: string
  350. limit: number
  351. // status?: SegmentStatus
  352. hit_count_gte?: number
  353. keyword?: string
  354. enabled?: boolean
  355. }
  356. export type SegmentDetailModel = {
  357. id: string
  358. position: number
  359. document_id: string
  360. content: string
  361. word_count: number
  362. tokens: number
  363. keywords: string[]
  364. index_node_id: string
  365. index_node_hash: string
  366. hit_count: number
  367. enabled: boolean
  368. disabled_at: number
  369. disabled_by: string
  370. status: SegmentStatus
  371. created_by: string
  372. created_at: number
  373. indexing_at: number
  374. completed_at: number
  375. error: string | null
  376. stopped_at: number
  377. answer?: string
  378. }
  379. export type SegmentsResponse = {
  380. data: SegmentDetailModel[]
  381. has_more: boolean
  382. limit: number
  383. total: number
  384. }
  385. export type HitTestingRecord = {
  386. id: string
  387. content: string
  388. source: 'app' | 'hit_testing' | 'plugin'
  389. source_app_id: string
  390. created_by_role: 'account' | 'end_user'
  391. created_by: string
  392. created_at: number
  393. }
  394. export type HitTesting = {
  395. segment: Segment
  396. score: number
  397. tsne_position: TsnePosition
  398. }
  399. export type ExternalKnowledgeBaseHitTesting = {
  400. content: string
  401. title: string
  402. score: number
  403. metadata: {
  404. 'x-amz-bedrock-kb-source-uri': string
  405. 'x-amz-bedrock-kb-data-source-id': string
  406. }
  407. }
  408. export type Segment = {
  409. id: string
  410. document: Document
  411. content: string
  412. position: number
  413. word_count: number
  414. tokens: number
  415. keywords: string[]
  416. hit_count: number
  417. index_node_hash: string
  418. }
  419. export type Document = {
  420. id: string
  421. data_source_type: string
  422. name: string
  423. doc_type: DocType
  424. }
  425. export type HitTestingRecordsResponse = {
  426. data: HitTestingRecord[]
  427. has_more: boolean
  428. limit: number
  429. total: number
  430. page: number
  431. }
  432. export type TsnePosition = {
  433. x: number
  434. y: number
  435. }
  436. export type HitTestingResponse = {
  437. query: {
  438. content: string
  439. tsne_position: TsnePosition
  440. }
  441. records: Array<HitTesting>
  442. }
  443. export type ExternalKnowledgeBaseHitTestingResponse = {
  444. query: {
  445. content: string
  446. }
  447. records: Array<ExternalKnowledgeBaseHitTesting>
  448. }
  449. export type RelatedApp = {
  450. id: string
  451. name: string
  452. mode: AppMode
  453. icon_type: AppIconType | null
  454. icon: string
  455. icon_background: string
  456. icon_url: string
  457. }
  458. export type RelatedAppResponse = {
  459. data: Array<RelatedApp>
  460. total: number
  461. }
  462. export type SegmentUpdater = {
  463. content: string
  464. answer?: string
  465. keywords?: string[]
  466. }
  467. export enum DocForm {
  468. TEXT = 'text_model',
  469. QA = 'qa_model',
  470. }
  471. export type ErrorDocsResponse = {
  472. data: IndexingStatusResponse[]
  473. total: number
  474. }
  475. export type SelectedDatasetsMode = {
  476. allHighQuality: boolean
  477. allHighQualityVectorSearch: boolean
  478. allHighQualityFullTextSearch: boolean
  479. allEconomic: boolean
  480. mixtureHighQualityAndEconomic: boolean
  481. allInternal: boolean
  482. allExternal: boolean
  483. mixtureInternalAndExternal: boolean
  484. inconsistentEmbeddingModel: boolean
  485. }
  486. export enum WeightedScoreEnum {
  487. SemanticFirst = 'semantic_first',
  488. KeywordFirst = 'keyword_first',
  489. Customized = 'customized',
  490. }
  491. export enum RerankingModeEnum {
  492. RerankingModel = 'reranking_model',
  493. WeightedScore = 'weighted_score',
  494. }
  495. export const DEFAULT_WEIGHTED_SCORE = {
  496. allHighQualityVectorSearch: {
  497. semantic: 1.0,
  498. keyword: 0,
  499. },
  500. allHighQualityFullTextSearch: {
  501. semantic: 0,
  502. keyword: 1.0,
  503. },
  504. other: {
  505. semantic: 0.7,
  506. keyword: 0.3,
  507. },
  508. }