Skip to content

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

fix(parser): drop eager base64 table image from pdf.TableItem (#20051)

xugangqiang36e1f7cffbe2
diff --git a/internal/deepdoc/parser/pdf/parser_mock_test.go b/internal/deepdoc/parser/pdf/parser_mock_test.go
index b31bcaaa2c..0fef4875e3 100644
--- a/internal/deepdoc/parser/pdf/parser_mock_test.go
+++ b/internal/deepdoc/parser/pdf/parser_mock_test.go
@@ -94,10 +94,6 @@ func TestEnrichOnePageWithDeepDoc_Mock(t *testing.T) {
if len(tbl.Cells) != 4 {
t.Errorf("expected 4 cells, got %d", len(tbl.Cells))
}
- // Rows populated later by constructTable via extractTableAndReplace.
- if tbl.ImageB64 == "" {
- t.Error("ImageB64 empty")
- }
if len(tbl.Positions) != 2 {
t.Errorf("expected 2 Positions, got %d", len(tbl.Positions))
}
@@ -162,10 +158,7 @@ func TestEnrichOnePageWithDeepDoc_TSRError(t *testing.T) {
dummy := image.NewRGBA(image.Rect(0, 0, 2000, 3000))
_, tables, _ := p.enrichOnePageWithDeepDoc(t.Context(), dummy, boxes, 0, nil, mock, NewTableBuilderFor(mock), pdf.DlaScale)
if len(tables) != 1 {
- t.Fatalf("TSR failure: expected 1 pdf.TableItem with image+positions, got %d", len(tables))
- }
- if tables[0].ImageB64 == "" {
- t.Error("should have image despite TSR failure")
+ t.Fatalf("TSR failure: expected 1 pdf.TableItem with positions, got %d", len(tables))
}
if len(tables[0].Positions) == 0 {
t.Error("should have positions despite TSR failure")
diff --git a/internal/deepdoc/parser/pdf/parser_pipeline_integration_test.go b/internal/deepdoc/parser/pdf/parser_pipeline_integration_test.go
index f1fcda09ab..aba74972f7 100644
--- a/internal/deepdoc/parser/pdf/parser_pipeline_integration_test.go
+++ b/internal/deepdoc/parser/pdf/parser_pipeline_integration_test.go
@@ -3,11 +3,7 @@
package pdf
import (
- "bytes"
- "encoding/base64"
"encoding/json"
- "image"
- _ "image/png"
"os"
"path/filepath"
"ragflow/internal/common"
@@ -215,45 +211,6 @@ func TestIntegration_TableStructure(t *testing.T) {
}
}
-// TestIntegration_TableImageB64 verifies table ImageB64 is valid base64 PNG.
-func TestIntegration_TableImageB64(t *testing.T) {
- client := mustConnectInProcessAnalyzer(t)
- data := mustReadPDF(t, "06_table_content.pdf")
-
- cfg := pdf.DefaultParserConfig()
- p := NewParser(cfg)
- result, err := p.Parse(t.Context(), data, client)
- if err != nil {
- t.Fatalf("Parse: %v", err)
- }
- if len(result.Tables) == 0 {
- t.Skip("DLA did not detect any tables in fixture — skipping image check")
- }
-
- for i, tbl := range result.Tables {
- if tbl.ImageB64 == "" {
- t.Errorf("table[%d] ImageB64 is empty", i)
- continue
- }
- // Verify base64 decodable.
- raw, err := base64.StdEncoding.DecodeString(tbl.ImageB64)
- if err != nil {
- t.Errorf("table[%d] ImageB64: not valid base64: %v", i, err)
- continue
- }
- // Verify it's a valid image.
- img, _, err := image.Decode(bytes.NewReader(raw))
- if err != nil {
- t.Errorf("table[%d] ImageB64: not a valid image: %v", i, err)
- continue
- }
- b := img.Bounds()
- if b.Dx() <= 0 || b.Dy() <= 0 {
- t.Errorf("table[%d] ImageB64: zero-size image %dx%d", i, b.Dx(), b.Dy())
- }
- }
-}
-
// TestIntegration_LayoutTypes verifies DLA labels boxes with expected types.
func TestIntegration_LayoutTypes(t *testing.T) {
client := mustConnectInProcessAnalyzer(t)
diff --git a/internal/deepdoc/parser/pdf/parser_pipeline_manual_test.go b/internal/deepdoc/parser/pdf/parser_pipeline_manual_test.go
index cfb20952e9..aa0405b1b3 100644
--- a/internal/deepdoc/parser/pdf/parser_pipeline_manual_test.go
+++ b/internal/deepdoc/parser/pdf/parser_pipeline_manual_test.go
@@ -79,9 +79,6 @@ func TestIntegration_NoCrash(t *testing.T) {
}
for i, tbl := range result.Tables {
- if tbl.ImageB64 == "" {
- t.Errorf("table[%d] ImageB64 is empty", i)
- }
if len(tbl.Positions) == 0 {
t.Errorf("table[%d] has no positions", i)
}
diff --git a/internal/deepdoc/parser/pdf/table_extract.go b/internal/deepdoc/parser/pdf/table_extract.go
index 818c85a4a5..c7c2d7e9e6 100644
--- a/internal/deepdoc/parser/pdf/table_extract.go
+++ b/internal/deepdoc/parser/pdf/table_extract.go
@@ -6,9 +6,6 @@ import (
"math"
"strings"
- "go.uber.org/zap"
-
- "ragflow/internal/common"
lyt "ragflow/internal/deepdoc/parser/pdf/layout"
tbl "ragflow/internal/deepdoc/parser/pdf/table"
pdf "ragflow/internal/deepdoc/parser/pdf/type"
@@ -100,7 +97,7 @@ func (p *Parser) enrichOnePageWithDeepDoc(ctx context.Context,
// TSR call back to the correct Python intermediate table.
tctx := context.WithValue(ctx, tableIdxCtxKey, i)
item := p.processOneTable(tctx, pageImg, annotated, pg, docAnalyzer, tb, tm, scale)
- if item.ImageB64 != "" || len(item.Cells) > 0 || len(item.Positions) > 0 {
+ if len(item.Cells) > 0 || len(item.Positions) > 0 {
items = append(items, item)
}
}
@@ -126,10 +123,6 @@ func (p *Parser) processOneTable(ctx context.Context, pageImg image.Image, boxes
bestAngle = angle
tsrImg = rotated
}
- imgB64, encErr := util.EncodeImageToBase64PNG(cropped)
- if encErr != nil {
- common.Warn("table PNG encode failed", zap.Int("page", pageNum), zap.Error(encErr))
- }
// Hand the crop origin to TSR so a replay TableBuilder can map Python
// page-space TSR cells into this exact crop frame. Production callers
// (DeepDocTableBuilder) ignore the value and use the cropped image pixels.
@@ -214,7 +207,7 @@ func (p *Parser) processOneTable(ctx context.Context, pageImg image.Image, boxes
}
}
item := pdf.TableItem{
- ImageB64: imgB64, Cells: cells, Grid: grid, Positions: positions,
+ Cells: cells, Grid: grid, Positions: positions,
Scale: scale, CropOffX: cropOffX, CropOffY: cropOffY,
RegionLeft: tm.Region.X0 / scale, RegionRight: tm.Region.X1 / scale,
RegionTop: tm.Region.Y0 / scale, RegionBottom: tm.Region.Y1 / scale,
diff --git a/internal/deepdoc/parser/pdf/tool/types.go b/internal/deepdoc/parser/pdf/tool/types.go
index c924279c0a..ee11c187ca 100644
--- a/internal/deepdoc/parser/pdf/tool/types.go
+++ b/internal/deepdoc/parser/pdf/tool/types.go
@@ -31,29 +31,6 @@ type PyResult struct {
Error string `json:"error,omitempty"`
}
-// TableItem stores per-table output.
-type TableItem struct {
- ImageB64 string `json:"image_b64"`
- Rows [][]string `json:"rows"`
- Cells []TSRCell `json:"cells,omitempty"`
- Positions []Position `json:"positions"`
-}
-
-// TSRCell mirrors parser.TSRCell for serialization.
-type TSRCell struct {
- X0 float64 `json:"x0"`
- Y0 float64 `json:"y0"`
- X1 float64 `json:"x1"`
- Y1 float64 `json:"y1"`
- Text string `json:"text"`
- Label string `json:"label"`
-}
-
-// Position stores a bounding box.
-type Position struct {
- Left, Right, Top, Bottom float64
-}
-
// RealPDFResult holds per-PDF stats for Go vs Python comparison.
type RealPDFResult struct {
File string `json:"file"`
diff --git a/internal/deepdoc/parser/pdf/util/image_utils.go b/internal/deepdoc/parser/pdf/util/image_utils.go
index 26d9f1469b..604d19c674 100644
--- a/internal/deepdoc/parser/pdf/util/image_utils.go
+++ b/internal/deepdoc/parser/pdf/util/image_utils.go
@@ -16,15 +16,6 @@ func EncodePNG(img image.Image) ([]byte, error) {
return buf.Bytes(), nil
}
-// EncodeImageToBase64PNG encodes img as a base64-encoded PNG string.
-func EncodeImageToBase64PNG(img image.Image) (string, error) {
- data, err := EncodePNG(img)
- if err != nil {
- return "", err
- }
- return base64.StdEncoding.EncodeToString(data), nil
-}
-
// DecodeBase64PNG decodes a base64-encoded PNG string to an image.Image.
func DecodeBase64PNG(b64 string) (image.Image, error) {
data, err := base64.StdEncoding.DecodeString(b64)
diff --git a/internal/deepdoc/parser/pdf/util/image_utils_test.go b/internal/deepdoc/parser/pdf/util/image_utils_test.go
index 55fd4b11dd..5e773439ee 100644
--- a/internal/deepdoc/parser/pdf/util/image_utils_test.go
+++ b/internal/deepdoc/parser/pdf/util/image_utils_test.go
@@ -17,29 +17,11 @@ func TestEncodePNG(t *testing.T) {
}
}
-func TestEncodeImageToBase64PNG(t *testing.T) {
- img := image.NewRGBA(image.Rect(0, 0, 10, 10))
- b64, err := EncodeImageToBase64PNG(img)
- if err != nil {
- t.Fatalf("EncodeImageToBase64PNG: %v", err)
- }
- if b64 == "" {
- t.Error("base64 string should not be empty")
- }
- // Should be valid base64 and decode to valid PNG
- data, err := base64.StdEncoding.DecodeString(b64)
- if err != nil {
- t.Fatalf("invalid base64: %v", err)
- }
- if len(data) == 0 {
- t.Error("decoded data should not be empty")
- }
-}
-
func TestDecodeBase64PNG(t *testing.T) {
// Encode → base64 → decode roundtrip
img := image.NewRGBA(image.Rect(0, 0, 10, 10))
- b64, _ := EncodeImageToBase64PNG(img)
+ data, _ := EncodePNG(img)
+ b64 := base64.StdEncoding.EncodeToString(data)
decoded, err := DecodeBase64PNG(b64)
if err != nil {
t.Fatalf("DecodeBase64PNG: %v", err)
diff --git a/internal/deepdoc/parser/type/types.go b/internal/deepdoc/parser/type/types.go
index 92ded7bb62..1c175a286b 100644
--- a/internal/deepdoc/parser/type/types.go
+++ b/internal/deepdoc/parser/type/types.go
@@ -171,7 +171,6 @@ func CollectFigures(sections []Section) []Section {
// TableItem represents a detected table or figure region.
type TableItem struct {
- ImageB64 string
Rows [][]string
Cells []TSRCell
Positions []Position