RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.
Go agent-harnessagent-native-databaseagentic-aiagentic-retrievalagentic-searchaiai-agentscontext-enginecontext-engineeringcontext-managementharness-engineeringknowledge-compilationragretrieval-augmented-generationretrieval-harnesssearch-harness
/*
* Copyright 2026 The InfiniFlow Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Images, SupportedPreviewDocumentTypes } from '@/constants/common';
import { UploadFile } from '@/interfaces/antd-compat';
import { IReferenceChunk } from '@/interfaces/database/chat';
import { IChunk } from '@/interfaces/database/dataset';
import { get } from 'lodash';
import { v4 as uuid } from 'uuid';
export const buildChunkHighlights = (
selectedChunk: IChunk | IReferenceChunk,
size: { width: number; height: number },
) => {
return Array.isArray(selectedChunk?.positions) &&
selectedChunk.positions.every((x) => Array.isArray(x))
? selectedChunk?.positions?.map((x) => {
const boundingRect = {
width: size.width,
height: size.height,
x1: x[1],
x2: x[2],
y1: x[3],
y2: x[4],
};
return {
id: uuid(),
comment: {
text: '',
emoji: '',
},
content: {
text:
get(selectedChunk, 'content_with_weight') ||
get(selectedChunk, 'content', ''),
},
position: {
boundingRect: boundingRect,
rects: [boundingRect],
pageNumber: x[0],
},
};
})
: [];
};
export const isFileUploadDone = (file: UploadFile) => file.status === 'done';
export const getExtension = (name: string) =>
name
?.slice(name.lastIndexOf('.') + 1)
.trim()
.toLowerCase() ?? '';
export const isPdf = (name: string) => {
return getExtension(name) === 'pdf';
};
export const getUnSupportedFilesCount = (message: string) => {
return message.split('\n').length;
};
export const isSupportedPreviewDocumentType = (fileExtension: string) => {
return SupportedPreviewDocumentTypes.includes(fileExtension);
};
export const isImage = (image: string) => {
return [...Images, 'svg'].some((x) => x === image);
};