Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

Fix re-parse complete document need pass delete:true for go (#19936)

Wang Qide989f2259a3
diff --git a/web/src/hooks/use-document-request.ts b/web/src/hooks/use-document-request.ts
index 21ddd73368..fc017ceb00 100644
--- a/web/src/hooks/use-document-request.ts
+++ b/web/src/hooks/use-document-request.ts
@@ -37,6 +37,7 @@ import i18n from '@/locales/config';
import { EMPTY_METADATA_FIELD } from '@/pages/dataset/dataset/use-select-filters';
import { isDocumentProcessing } from '@/pages/dataset/dataset/utils';
import documentStructureService from '@/services/document-structure-service';
+import { buildDocumentIngestPayload } from '@/services/document-ingest-adapter';
import kbService, {
changeDocumentParser,
changeDocumentsStatus,
@@ -445,11 +446,9 @@ export const useRunDocument = () => {
queryKey: DocumentKeys.all(),
});
}
- const ret = await kbService.documentIngest({
- doc_ids: documentIds,
- run,
- ...(option || {}),
- });
+ const ret = await kbService.documentIngest(
+ buildDocumentIngestPayload({ documentIds, run, option }),
+ );
const code = get(ret, 'data.code');
if (code === 0) {
// For a start request, keep the optimistic running state until the
diff --git a/web/src/services/document-ingest-adapter.test.ts b/web/src/services/document-ingest-adapter.test.ts
new file mode 100644
index 0000000000..dc9799fcb2
--- /dev/null
+++ b/web/src/services/document-ingest-adapter.test.ts
@@ -0,0 +1,53 @@
+let mockIsGo = false;
+
+jest.mock('@/utils/backend-variant', () => ({
+ pickByBackend: ({ go, python }: { go: unknown; python: unknown }) =>
+ mockIsGo ? go : python,
+}));
+
+import { buildDocumentIngestPayload } from './document-ingest-adapter';
+
+describe('buildDocumentIngestPayload', () => {
+ beforeEach(() => {
+ mockIsGo = false;
+ });
+
+ it('forces delete for a Go parse request', () => {
+ mockIsGo = true;
+
+ expect(
+ buildDocumentIngestPayload({
+ documentIds: ['doc-1'],
+ run: 1,
+ option: { delete: false, apply_kb: true },
+ }),
+ ).toEqual({
+ doc_ids: ['doc-1'],
+ run: 1,
+ delete: true,
+ apply_kb: true,
+ });
+ });
+
+ it('adds delete when a Go parse request has no options', () => {
+ mockIsGo = true;
+
+ expect(
+ buildDocumentIngestPayload({ documentIds: ['doc-1'], run: 1 }),
+ ).toEqual({ doc_ids: ['doc-1'], run: 1, delete: true });
+ });
+
+ it('does not add delete to a Go cancel request', () => {
+ mockIsGo = true;
+
+ expect(
+ buildDocumentIngestPayload({ documentIds: ['doc-1'], run: 2 }),
+ ).toEqual({ doc_ids: ['doc-1'], run: 2 });
+ });
+
+ it('preserves the Python parse payload', () => {
+ expect(
+ buildDocumentIngestPayload({ documentIds: ['doc-1'], run: 1 }),
+ ).toEqual({ doc_ids: ['doc-1'], run: 1 });
+ });
+});
diff --git a/web/src/services/document-ingest-adapter.ts b/web/src/services/document-ingest-adapter.ts
new file mode 100644
index 0000000000..5393aea4a1
--- /dev/null
+++ b/web/src/services/document-ingest-adapter.ts
@@ -0,0 +1,34 @@
+import { pickByBackend } from '@/utils/backend-variant';
+
+export type DocumentIngestOption = {
+ delete: boolean;
+ apply_kb: boolean;
+};
+
+export type DocumentIngestPayload = {
+ doc_ids: string[];
+ run: number;
+ delete?: boolean;
+ apply_kb?: boolean;
+};
+
+export const buildDocumentIngestPayload = ({
+ documentIds,
+ run,
+ option,
+}: {
+ documentIds: string[];
+ run: number;
+ option?: DocumentIngestOption;
+}): DocumentIngestPayload => {
+ const payload = {
+ doc_ids: documentIds,
+ run,
+ ...(option || {}),
+ };
+
+ return pickByBackend({
+ go: run === 1 ? { ...payload, delete: true } : payload,
+ python: payload,
+ });
+};