GoodMemGoodMem
ReferenceSdkV2Go

OCR

package goodmem // import "fury.io/pairsys/goodmem"

Document OCR — text extraction from PDFs / images.

Methods are called as client.OCR().<Method>(ctx, ...) on a *goodmem.Client. Service: OCRService.

Index

type OCRService

type OCRService struct{ … }

Access this service as client.OCR() on a *goodmem.Client. Its methods follow.

func (s *OCRService) Document

func (s *OCRService) Document(ctx context.Context, req *models.OCRDocumentRequest) (*models.OCRDocumentResponse, error)

Run OCR on a document or image. Pass base64-encoded document bytes as content. The server auto-detects format; set format explicitly only if needed.

HTTPPOST /v1/ocr:document

Parameters

  • ctx (context.Context) — carries the deadline and cancellation signal for the call.
  • req (*models.OCRDocumentRequest) — the request payload. The linked type documents every field and its JSON wire name.

Returns(*models.OCRDocumentResponse, error)

Example

imageB64 := base64.StdEncoding.EncodeToString([]byte("not-a-real-image"))
result, err := client.OCR().Document(ctx, &models.OCRDocumentRequest{
	Content:         goodmem.Ptr(imageB64),
	Format:          goodmem.Ptr(models.OCRInputFormatPNG),
	IncludeMarkdown: goodmem.Ptr(true),
})
if err == nil {
	_ = result.PageCount
}

func (s *OCRService) DocumentFromFile

func (s *OCRService) DocumentFromFile(ctx context.Context, filePath string, req *models.OCRDocumentRequest) (*models.OCRDocumentResponse, error)

Run OCR on a document or image. Pass base64-encoded document bytes as content. The server auto-detects format; set format explicitly only if needed.

Convenience variant: reads filePath from disk, base64-encodes the bytes, infers the content type from the file extension, and POSTs a JSON request.

HTTPPOST /v1/ocr:document

Parameters

  • ctx (context.Context) — carries the deadline and cancellation signal for the call.
  • filePath (string) — path to a local file. It is read into memory, base64-encoded, and the content type is inferred from the extension.
  • req (*models.OCRDocumentRequest) — the request payload. The linked type documents every field and its JSON wire name.

Returns(*models.OCRDocumentResponse, error)

Example

resp, err := client.OCR().DocumentFromFile(ctx, "/tmp/file.bin", &models.OCRDocumentRequest{ /* required fields */ })
if err != nil {
    log.Fatal(err)
}
_ = resp

type OcrDocumentRequest

type OcrDocumentRequest struct{ … }

Request body for OCR document processing.

  • Content (string, wire content) — Base64-encoded document bytes
  • Format (models.OcrInputFormat, optional, wire format) — Input format hint (AUTO, PDF, TIFF, PNG, JPEG, BMP)
  • IncludeRawJSON (bool, optional, wire includeRawJson) — Include raw OCR JSON payload in the response
  • IncludeMarkdown (bool, optional, wire includeMarkdown) — Include markdown rendering in the response
  • StartPage (int32, optional, wire startPage) — 0-based inclusive start page
  • EndPage (int32, optional, wire endPage) — 0-based inclusive end page

type OcrInputFormat

type OcrInputFormat string

OCR input format hint.

String enum (type OcrInputFormat string): "AUTO" · "PDF" · "TIFF" · "PNG" · "JPEG" · "BMP"

type OcrDocumentResponse

type OcrDocumentResponse struct{ … }

Response containing page-ordered OCR results.

  • DetectedFormat (models.OcrInputFormat, wire detectedFormat) — Detected input format
  • PageCount (int32, wire pageCount) — Number of pages processed after applying the range
  • Pages ([]models.OcrPageResult, wire pages) — Ordered per-page OCR results
  • Timings (models.DocumentTimings, wire timings) — Aggregate timing statistics

type OcrPageResult

type OcrPageResult struct{ … }

Per-page OCR result containing output or error status.

  • PageIndex (int32, wire pageIndex) — 0-based page index
  • Page (models.OcrPage, optional, wire page) — OCR output for the page
  • Status (models.RpcStatus, optional, wire status) — Error status for the page

type DocumentTimings

type DocumentTimings struct{ … }

Aggregate timing statistics for an OCR request.

  • WallTimeMs (int64, wire wallTimeMs) — End-to-end request time (ms)
  • SumQueueWaitMs (int64, wire sumQueueWaitMs) — Sum of per-page queue wait times (ms)
  • SumRenderMs (int64, wire sumRenderMs) — Sum of per-page render times (ms)
  • SumOCRMs (int64, wire sumOcrMs) — Sum of per-page OCR times (ms)
  • SumPageTotalMs (int64, wire sumPageTotalMs) — Sum of per-page total times (ms)

type OcrPage

type OcrPage struct{ … }

OCR output for a single page.

  • RawJSON (string, optional, wire rawJson) — Raw OCR JSON payload when requested
  • Markdown (string, optional, wire markdown) — Markdown rendering when requested
  • Layout (models.OcrLayout, wire layout) — Parsed layout output
  • Timings (models.PageTimings, wire timings) — Timing breakdown for the page
  • Image (models.ImageInfo, wire image) — Rendered image metadata

type RpcStatus

type RpcStatus struct{ … }

Status payload for per-page OCR errors.

  • Code (int32, wire code) — gRPC status code as defined by google.rpc.Code
  • Message (string, optional, wire message) — Human-readable error message

type OcrLayout

type OcrLayout struct{ … }

Parsed OCR layout output for a page.

  • Cells ([]models.OcrCell, wire cells) — Layout cells in reading order

type PageTimings

type PageTimings struct{ … }

Per-page timing breakdown for OCR processing.

  • QueueWaitMs (int64, wire queueWaitMs) — Time spent waiting in the render queue (ms)
  • RenderMs (int64, wire renderMs) — Time spent rendering the page image (ms)
  • OCRMs (int64, wire ocrMs) — Time spent running OCR (ms)
  • TotalMs (int64, wire totalMs) — Total page processing time (ms)

type ImageInfo

type ImageInfo struct{ … }

Rendered image metadata for an OCR page.

  • WidthPx (int32, wire widthPx) — Rendered image width in pixels
  • HeightPx (int32, wire heightPx) — Rendered image height in pixels
  • Dpi (int32, wire dpi) — Rendering DPI

type OcrCell

type OcrCell struct{ … }

Single OCR layout element.

  • Bbox (models.BoundingBox, optional, wire bbox) — Bounding box in page coordinates
  • CategoryLabel (string, wire categoryLabel) — Raw category label emitted by OCR
  • Category (models.OcrCategory, wire category) — Normalized OCR category
  • Text (string, wire text) — OCR text content

type BoundingBox

type BoundingBox struct{ … }

Bounding box coordinates in page space.

  • X1 (float64, wire x1) — Left coordinate
  • Y1 (float64, wire y1) — Top coordinate
  • X2 (float64, wire x2) — Right coordinate
  • Y2 (float64, wire y2) — Bottom coordinate

type OcrCategory

type OcrCategory string

Normalized OCR layout category.

String enum (type OcrCategory string): "UNSPECIFIED" · "CAPTION" · "FOOTNOTE" · "FORMULA" · "LIST_ITEM" · "PAGE_FOOTER" · "PAGE_HEADER" · "PICTURE" · "SECTION_HEADER" · "TABLE" · "TEXT" · "TITLE" · "OTHER" · "UNKNOWN"