### Setup Python Environment and Install Dependencies Source: https://github.com/xberg-io/xberg/blob/main/tools/benchmark-harness/python_baselines/README.md Navigate to the directory, create a virtual environment, activate it, and install required packages from requirements.txt. ```bash cd tools/benchmark-harness/python_baselines python -m venv venv source venv/bin/activate # or venv\Scripts\activate on Windows pip install -r requirements.txt ``` -------------------------------- ### Start MCP Server in Go Source: https://github.com/xberg-io/xberg/blob/main/docs/guides/api-server.md This Go code example shows the basic implementation for starting the MCP server. Import the necessary xberg package. ```go package main import "github.com/xberg-io/xberg-go/mcp" func main() { mcp.Start() } ``` -------------------------------- ### Setup Development Environment Source: https://github.com/xberg-io/xberg/blob/main/CONTRIBUTING.md Run this command to install all toolchains and dependencies. It is safe to re-run anytime. ```bash task setup ``` -------------------------------- ### Start MCP Server in C# Source: https://github.com/xberg-io/xberg/blob/main/docs/guides/api-server.md This C# code example shows how to start the MCP server. Ensure the xberg C# SDK is referenced in your project. ```csharp using Xberg.Mcp; public class Program { public static void Main(string[] args) { McpServer.Start(); } } ``` -------------------------------- ### Start MCP Server in Python Source: https://github.com/xberg-io/xberg/blob/main/docs/guides/api-server.md This snippet shows how to start the MCP server using Python. Ensure you have the necessary xberg libraries installed. ```python import xberg xberg.mcp.start() ``` -------------------------------- ### Serve with Custom Configuration Source: https://github.com/xberg-io/xberg/blob/main/docs/snippets/cli/serve_rust.md Starts the development server using a specified TOML configuration file. This allows for more complex setup options. ```bash # With custom config xberg serve --config production.toml ``` -------------------------------- ### Install Xberg Go Package Source: https://github.com/xberg-io/xberg/blob/main/templates/readme/go.md Use 'go get' to install the latest release or a specific version of the Xberg Go package. Ensure the static library is provided at build time. ```bash # Get the latest release go get {{ package_name }}@latest # Or a specific version go get {{ package_name }}@v{{ version }} ``` -------------------------------- ### Run MCP Server from Source Source: https://github.com/xberg-io/xberg/blob/main/README.md Install the Xberg CLI from source with the 'mcp' feature enabled and start the MCP server. ```sh # From source — enable the mcp feature cargo install xberg-cli --features mcp xberg mcp ``` -------------------------------- ### Start API Server via Python Source: https://github.com/xberg-io/xberg/blob/main/docs/guides/api-server.md Initiate the Xberg API server using Python. This requires the xberg library to be installed. ```python from xberg.api_server import serve serve() ``` -------------------------------- ### Elixir PostProcessorConfig default() Example Source: https://github.com/xberg-io/xberg/blob/main/docs/reference/api-elixir.md Example of calling the `default` function to get the default configuration for `PostProcessorConfig`. This provides a starting point for configuring post-processors. ```elixir {:ok, result} = PostProcessorConfig.default() ``` -------------------------------- ### Quickstart: Extract File Content Source: https://github.com/xberg-io/xberg/blob/main/packages/go/README.md Demonstrates basic file extraction using the Xberg Go SDK. Ensure the static library is available before building. ```go package main import ( "fmt" "log" "github.com/xberg-io/xberg" ) func main() { result, err := v4.ExtractFileSync("document.pdf", nil) if err != nil { log.Fatalf("extract failed: %v", err) } fmt.Println("MIME:", result.MimeType) fmt.Println("First 200 chars:") fmt.Println(result.Content[:200]) } ``` -------------------------------- ### Get Default Server Configuration Source: https://github.com/xberg-io/xberg/blob/main/docs/reference/api-go.md Retrieves the default server configuration. Use this for a standard setup or as a starting point for customization. ```go result := ServerConfig.Default() ``` -------------------------------- ### Get Default Embedding Configuration Source: https://github.com/xberg-io/xberg/blob/main/docs/reference/api-java.md Retrieves the default configuration options for embedding generation. This is useful for starting with a standard setup. ```java var result = EmbeddingConfig.defaultOptions(); ``` -------------------------------- ### ProcessingStage Method Example Source: https://github.com/xberg-io/xberg/blob/main/docs/reference/api-csharp.md An example demonstrating how to call the ProcessingStage method to get the processing stage. ```csharp var result = instance.ProcessingStage(); ``` -------------------------------- ### Example Usage of listRerankerPresets() Source: https://github.com/xberg-io/xberg/blob/main/docs/reference/api-php.md Example of how to call listRerankerPresets to get a list of available preset names. ```php $result = listRerankerPresets(); ``` -------------------------------- ### Go Quickstart: Extract File Synchronously Source: https://github.com/xberg-io/xberg/blob/main/templates/readme/go.md Demonstrates the basic usage of Xberg in Go to extract content from a PDF file synchronously. Ensure the static library is available during the build process. ```go package main import ( "fmt" "log" "{{ package_name }}" ) func main() { result, err := v4.ExtractFileSync("document.pdf", nil) if err != nil { log.Fatalf("extract failed: %v", err) } fmt.Println("MIME:", result.MimeType) fmt.Println("First 200 chars:") fmt.Println(result.Content[:200]) } ``` -------------------------------- ### EstimatedDurationMs Method Example Source: https://github.com/xberg-io/xberg/blob/main/docs/reference/api-csharp.md An example demonstrating how to call the EstimatedDurationMs method to get the estimated processing time. ```csharp var result = instance.EstimatedDurationMs(new ExtractionResult()); ``` -------------------------------- ### Build and Serve Documentation Locally Source: https://github.com/xberg-io/xberg/blob/main/docs/guides/development.md Synchronize documentation dependencies and then build and serve the documentation locally for preview. ```bash uv sync --group doc zensical build --clean zensical serve ``` -------------------------------- ### Get Default Reranker Configuration Source: https://github.com/xberg-io/xberg/blob/main/docs/reference/api-elixir.md Retrieves the default configuration for the reranker. Use this to initialize or get a baseline reranker setup. ```elixir def default() ``` ```elixir {:ok, result} = RerankerConfig.default() ``` -------------------------------- ### Start MCP Server with Python Source: https://github.com/xberg-io/xberg/blob/main/docs/snippets/python/mcp/mcp_server_start.md Use this snippet to start the MCP server as a subprocess. Ensure the 'xberg' module is installed and accessible. ```python import subprocess import time from typing import Optional mcp_process: subprocess.Popen = subprocess.Popen( ["python", "-m", "xberg", "mcp"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, ) pid: Optional[int] = mcp_process.pid print(f"MCP server started with PID: {pid}") time.sleep(1) print("Server is running, listening for connections") ``` -------------------------------- ### Source Library Path Setup Script Source: https://github.com/xberg-io/xberg/blob/main/scripts/ci/README.md Source a library path setup script and then execute another script. This is useful for setting up the environment before running tests or builds. ```bash source ./scripts/lib/library-paths.sh setup_all_library_paths ./scripts/ci/python/run-tests.sh true ``` -------------------------------- ### Elixir PostProcessor estimated_duration_ms() Example Source: https://github.com/xberg-io/xberg/blob/main/docs/reference/api-elixir.md Example of calling `estimated_duration_ms` to get an estimate of the processing time in milliseconds. This is used for logging and debugging. ```elixir {:ok, result} = instance.estimated_duration_ms(%{{}}) ``` -------------------------------- ### Hello World Example in Swift Source: https://github.com/xberg-io/xberg/blob/main/docs/snippets/swift/getting-started/hello_world.md Demonstrates a basic 'Hello World' program using Swift with Xberg and RustBridge. Includes file extraction with JSON configuration. ```swift import Foundation import Xberg import RustBridge print("Hello") let config = try extractionConfigFromJson("{}") let result = try extractFileSync("document.pdf", nil, config) print("MIME type: \(result.mime_type().toString())") ``` -------------------------------- ### Extension Setup PHP Source: https://github.com/xberg-io/xberg/blob/main/docs/snippets/php/README.md Guides on setting up the native PHP extension (xberg.so/.dll) and checking for optional dependencies like Tesseract and ONNX Runtime. ```php check_dependency('tesseract')) { echo "Tesseract is installed and available.\n"; } else { echo "Tesseract is not installed or not found in PATH.\n"; } // Check for ONNX Runtime if ($xberg->check_dependency('onnxruntime')) { echo "ONNX Runtime is installed and available.\n"; } else { echo "ONNX Runtime is not installed or not found in PATH.\n"; } } catch (\Exception $e) { die("Error: " . $e->getMessage()); } ``` -------------------------------- ### Start MCP Server with Configuration Source: https://github.com/xberg-io/xberg/blob/main/templates/readme/cli.md Starts the Model Context Protocol (MCP) server using a specified configuration file. ```bash # With configuration file xberg mcp --config xberg.toml ``` -------------------------------- ### Get Default Extraction Configuration - C Source: https://github.com/xberg-io/xberg/blob/main/docs/reference/api-c.md Initializes and returns a default XbergExtractionConfig structure. Use this to get a starting configuration for extraction tasks. ```c XbergExtractionConfig *result = xberg_default(); ``` -------------------------------- ### Zig PostProcessor estimatedDurationMs() Method Example Source: https://github.com/xberg-io/xberg/blob/main/docs/reference/api-zig.md Example of calling the estimatedDurationMs method on a PostProcessor instance to get an estimate of the processing time in milliseconds. ```zig const result = instance.estimatedDurationMs(.{}); ``` -------------------------------- ### Download and Link Pre-built Static Library (Linux/macOS) Source: https://github.com/xberg-io/xberg/blob/main/packages/go/README.md Download a pre-built static library from GitHub Releases and link it using CGO_LDFLAGS. This example shows the process for Linux x86_64. ```bash # Example: Linux x86_64 curl -LO https://github.com/xberg-io/xberg/releases/download/v1.0.0-rc.1/go-ffi-linux-x86_64.tar.gz tar -xzf go-ffi-linux-x86_64.tar.gz # Copy to a permanent location mkdir -p ~/xberg/lib cp xberg-ffi/lib/libxberg_ffi.a ~/xberg/lib/ # Linux/macOS CGO_LDFLAGS="-L$HOME/xberg/lib -lxberg_ffi" go build ``` -------------------------------- ### Build Language-Specific Project Source: https://github.com/xberg-io/xberg/blob/main/CONTRIBUTING.md Example of building a specific language's project, like Python. ```bash task python:build ``` -------------------------------- ### PHP PostProcessor estimatedDurationMs() Method Example Source: https://github.com/xberg-io/xberg/blob/main/docs/reference/api-php.md An example demonstrating how to call the estimatedDurationMs method to get the estimated processing time for an extraction result. ```php $result = $instance->estimatedDurationMs(new ExtractionResult()); ``` -------------------------------- ### by_framework_mode Key Examples Source: https://github.com/xberg-io/xberg/blob/main/tools/benchmark-harness/SCHEMA.md Illustrates the key formats used in the 'by_framework_mode' section, which differ based on whether the framework is 'xberg' or a competitor. ```string xberg-markdown-baseline:single ``` ```string xberg-plaintext-paddle-ocr:batch ``` ```string unstructured:plaintext:single ``` ```string docling:markdown:single ``` -------------------------------- ### Install uv and Set Up Git Hooks Source: https://github.com/xberg-io/xberg/blob/main/crates/xberg-tesseract/README.md Commands to install the 'uv' package manager and set up git hooks for contributing to the project. ```bash curl -LsSf https://astral.sh/uv/install.sh | sh ``` ```bash uvx prek install ``` -------------------------------- ### OCR Configuration Example Source: https://github.com/xberg-io/xberg/blob/main/docs/reference/api-go.md Demonstrates the structure of OCR configuration, including enabled status, backend selection, language settings, and specific configurations for Tesseract and PaddleOCR. This is useful for setting up OCR processing pipelines. ```go type OcrConfig struct { Enabled bool `json:"enabled,omitempty"` Backend string `json:"backend,omitempty"` Language []string `json:"language,omitempty"` TesseractConfig *TesseractConfig `json:"tesseract_config,omitempty"` OutputFormat *OutputFormat `json:"output_format,omitempty"` PaddleOcrConfig *interface{} `json:"paddleocr_config,omitempty"` BackendOptions *interface{} `json:"backend_options,omitempty"` ElementConfig *OcrElementConfig `json:"element_config,omitempty"` QualityThresholds *OcrQualityThresholds `json:"quality_thresholds,omitempty"` Pipeline *OcrPipelineConfig `json:"pipeline,omitempty"` AutoRotate bool `json:"auto_rotate,omitempty"` VlmFallback VlmFallbackPolicy `json:"vlm_fallback,omitempty"` VlmConfig *LlmConfig `json:"vlm_config,omitempty"` VlmPrompt *string `json:"vlm_prompt,omitempty"` Acceleration *AccelerationConfig `json:"acceleration,omitempty"` TessdataBytes *map[string][]byte `json:"tessdata_bytes,omitempty"` TessdataPath *string `json:"tessdata_path,omitempty"` } ``` -------------------------------- ### Get Default Image Preprocessing Configuration Source: https://github.com/xberg-io/xberg/blob/main/docs/reference/api-ruby.md Retrieves the default configuration for image preprocessing. Use this to get a starting point for customizing OCR image preparation. ```ruby result = ImagePreprocessingConfig.default() ``` -------------------------------- ### Install xberg CLI from Source Source: https://github.com/xberg-io/xberg/blob/main/crates/xberg-cli/README.md Install the xberg CLI by building it directly from the source code. ```bash cargo install --path crates/xberg-cli ``` ```bash cargo build --release -p xberg-cli ``` -------------------------------- ### WASM Keyword Extraction Setup Source: https://github.com/xberg-io/xberg/blob/main/docs/snippets/wasm/advanced/keyword_extraction_config.md Configure WASM for keyword extraction by setting the output format. This example shows basic setup and post-processing for keyword extraction. ```typescript import init, { extractBytes } from "xberg-wasm"; await init(); // Note: Keyword extraction requires the 'keywords' feature, // which may not be available in all WASM builds. // This example shows the configuration structure. const config = { // Extraction configuration outputFormat: "markdown", }; const bytes = new Uint8Array(buffer); const result = await extractBytes(bytes, "application/pdf", config); // Keyword extraction would be performed on the extracted text // using external libraries or post-processing console.log(`Extracted text: ${result.content.substring(0, 100)}...`); // Example post-processing to extract keywords // (requires external keyword extraction library) const keywords = new Set(); const words = result.content .toLowerCase() .split(/\s+/) .filter((w) => w.length > 4); // Simple heuristic: words > 4 chars words.forEach((word) => { keywords.add(word); }); console.log(`Extracted keywords: ${Array.from(keywords).slice(0, 10).join(", ")}`); ``` -------------------------------- ### Start API Server with Configuration Source: https://github.com/xberg-io/xberg/blob/main/templates/readme/cli.md Starts the xberg API server using a specified configuration file and custom host/port. ```bash # With configuration file xberg serve --config xberg.toml --host 127.0.0.1 --port 8080 ``` -------------------------------- ### Clone and Setup Xberg Source: https://github.com/xberg-io/xberg/blob/main/packages/ruby/README.md Clone the Xberg repository and install its Ruby dependencies. ```bash git clone https://github.com/xberg-io/xberg.git cd xberg bundle install ``` -------------------------------- ### Serve Project with xberg CLI Source: https://github.com/xberg-io/xberg/blob/main/docs/snippets/api_server/cli.md Use the `xberg serve` command to start a local development server. Options include specifying the host and port, or using a configuration file. ```bash # Default: http://127.0.0.1:8000 xberg serve ``` ```bash # Custom host and port xberg serve -H 0.0.0.0 -p 3000 ``` ```bash # With configuration file xberg serve --config xberg.toml ``` -------------------------------- ### Start Server via TypeScript CLI Proxy Source: https://github.com/xberg-io/xberg/blob/main/docs/snippets/cli/serve_typescript.md Use this command to start the xberg development server for your TypeScript project. This is the most basic way to get the server running. ```bash npx xberg serve ``` ```bash npx xberg serve --host 0.0.0.0 --port 3000 ``` ```bash npx xberg serve --config production.toml ``` -------------------------------- ### Install Xberg Go SDK Source: https://github.com/xberg-io/xberg/blob/main/docs/cli/usage.md Install the Xberg Go SDK for programmatic access. ```bash go install github.com/xberg-io/xberg/cmd/xberg@latest ``` -------------------------------- ### Get Default FootnoteConfig Source: https://github.com/xberg-io/xberg/blob/main/docs/reference/api-elixir.md Retrieves the default configuration for footnote parsing. No setup is required. ```elixir def default() ``` ```elixir {:ok, result} = FootnoteConfig.default() ``` -------------------------------- ### Run live browser demo locally Source: https://github.com/xberg-io/xberg/blob/main/docs/guides/development.md Builds Wasm and TypeScript, patches the demo with local URLs, and starts development servers for the browser demo. ```bash task demo:dev ``` -------------------------------- ### Plugin Logging Example (Python) Source: https://github.com/xberg-io/xberg/blob/main/docs/guides/plugins.md Demonstrates how to implement logging within a Python plugin. Ensure the logger is configured before use. ```Python import logging from xberg.plugins import Plugin, PluginContext class PluginWithLogging(Plugin): def __init__(self): self.logger = logging.getLogger(__name__) async def run(self, ctx: PluginContext): self.logger.info("Starting plugin execution.") # Simulate some work await asyncio.sleep(1) self.logger.warning("Plugin execution completed with a warning.") ``` -------------------------------- ### Get Default HeuristicsConfig Source: https://github.com/xberg-io/xberg/blob/main/docs/reference/api-dart.md Instantiates the default HeuristicsConfig. Use this as a starting point for custom configurations. ```dart final result = HeuristicsConfig.default(); ``` -------------------------------- ### Start Go API Server Source: https://github.com/xberg-io/xberg/blob/main/docs/snippets/api_server/go.md Use this snippet to start the API server programmatically in Go. Ensure the 'xberg' command is in your PATH. ```go package main import ( "log" "os/exec" ) func main() { cmd := exec.Command("xberg", "serve", "-H", "0.0.0.0", "-p", "8000") cmd.Stdout = log.Writer() cmd.Stderr = log.Writer() if err := cmd.Run(); err != nil { log.Fatalf("failed to start server: %v", err) } } ``` -------------------------------- ### Get Default Transcription Configuration Source: https://github.com/xberg-io/xberg/blob/main/docs/reference/api-c.md Retrieves the default XbergTranscriptionConfig structure. No setup or imports are required. ```c XbergTranscriptionConfig *result = xberg_default(); ``` -------------------------------- ### Create Default TranscriptionConfig Source: https://github.com/xberg-io/xberg/blob/main/docs/reference/api-csharp.md Generates a default TranscriptionConfig object. This is useful for starting with a pre-configured setup. ```csharp var result = TranscriptionConfig.CreateDefault(); ``` -------------------------------- ### Start Xberg Server Source: https://github.com/xberg-io/xberg/blob/main/docs/snippets/cli/serve_rust.md Starts the development server using default settings (127.0.0.1:8000). ```bash # Start server (default: 127.0.0.1:8000) xberg serve ``` -------------------------------- ### Default ExtractionConfig Source: https://github.com/xberg-io/xberg/blob/main/docs/reference/api-swift.md Creates a default configuration for document extraction. Use this to get a standard setup. ```swift let result = ExtractionConfig.default() ``` -------------------------------- ### Download and Link Pre-built Static Library (Linux/macOS) Source: https://github.com/xberg-io/xberg/blob/main/templates/readme/go.md Download the pre-built static library for your platform from GitHub Releases. Copy it to a permanent location and then use CGO_LDFLAGS to link it during the Go build process. ```bash # Example: Linux x86_64 curl -LO https://github.com/xberg-io/xberg/releases/download/v{{ version }}/go-ffi-linux-x86_64.tar.gz tar -xzf go-ffi-linux-x86_64.tar.gz # Copy to a permanent location mkdir -p ~/xberg/lib cp xberg-ffi/lib/libxberg_ffi.a ~/xberg/lib/ # Linux/macOS CGO_LDFLAGS="-L$HOME/xberg/lib -lxberg_ffi" go build ``` -------------------------------- ### Example Success Output Source: https://github.com/xberg-io/xberg/blob/main/scripts/test/USAGE.md This is an example of a successful test run, showing configuration details and a passing test case. ```text ╔════════════════════════════════════════════════════════╗ ║ Docker Configuration Volume Mount Test Suite ║ ╚════════════════════════════════════════════════════════╝ [INFO] Configuration: [INFO] [INFO] Variant: all [INFO] Verbose: false [INFO] Keep Containers: false [INFO] Port Range: 18100-18199 [INFO] Docker is available Test 01: Volume mount to /etc/xberg/xberg.toml (variant: core) [PASS] Test passed ``` -------------------------------- ### Start API Server in Python Source: https://github.com/xberg-io/xberg/blob/main/docs/snippets/api_server/python.md Use this snippet to start the xberg API server programmatically using Python's subprocess module. Ensure the xberg CLI is installed and accessible in your environment. ```python # Start server import subprocess subprocess.Popen(["python", "-m", "xberg", "serve", "-H", "0.0.0.0", "-p", "8000"]) ``` -------------------------------- ### Install xberg with All Features Source: https://github.com/xberg-io/xberg/blob/main/packages/python/README.md Install the xberg package with all available features enabled. ```bash pip install "xberg[all]" ``` -------------------------------- ### Get Default RerankerConfig Source: https://github.com/xberg-io/xberg/blob/main/docs/reference/api-go.md Retrieves the default configuration for the reranker. Use this as a starting point for custom configurations. ```go result := RerankerConfig.Default() ``` -------------------------------- ### Plugin Logging Example (Java) Source: https://github.com/xberg-io/xberg/blob/main/docs/guides/plugins.md Shows how to integrate logging into a Java plugin. Assumes a logging framework like SLF4j is configured. ```Java package com.example.plugins; import com.xberg.plugins.Plugin; import com.xberg.plugins.PluginContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class PluginWithLogging implements Plugin { private static final Logger logger = LoggerFactory.getLogger(PluginWithLogging.class); @Override public void run(PluginContext ctx) { logger.info("Starting plugin execution."); // Simulate some work try { Thread.sleep(1000); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } logger.warn("Plugin execution completed with a warning."); } } ``` -------------------------------- ### Get Default TranscriptionConfig Instance Source: https://github.com/xberg-io/xberg/blob/main/docs/reference/api-php.md Instantiates a default TranscriptionConfig object. This is useful for starting with a pre-configured object. ```php $result = TranscriptionConfig::default(); ``` -------------------------------- ### Start MCP Server with Configuration Source: https://github.com/xberg-io/xberg/blob/main/docs/snippets/rust/mcp/mcp_server_start.md Use this snippet to start the MCP server. It discovers the configuration automatically and starts the server asynchronously. ```rust use xberg::{ExtractionConfig, mcp::start_mcp_server_with_config}; #[tokio::main] async fn main() -> Result<(), Box> { let config = ExtractionConfig::discover()?; start_mcp_server_with_config(config).await?; Ok(()) } ``` -------------------------------- ### Example OCR Backend Options Source: https://github.com/xberg-io/xberg/blob/main/docs/reference/api-csharp.md Illustrates how to configure arbitrary per-call options for OCR backends, allowing for runtime tuning and backend-specific parameters. ```json { "mode": "fast", "enable_layout": true } ``` -------------------------------- ### ImagePreprocessingConfig::default() Source: https://github.com/xberg-io/xberg/blob/main/docs/reference/api-php.md Returns a default ImagePreprocessingConfig object. This is useful for getting a standard configuration to start with, which can then be customized. ```APIDOC ## ImagePreprocessingConfig::default() ### Description Returns a default ImagePreprocessingConfig object. This is useful for getting a standard configuration to start with, which can then be customized. ### Method ```php public static function default(): ImagePreprocessingConfig ``` ### Returns `ImagePreprocessingConfig` ### Example ```php $result = ImagePreprocessingConfig::default(); ``` ``` -------------------------------- ### Default Server Configuration Source: https://github.com/xberg-io/xberg/blob/main/docs/reference/api-rust.md Demonstrates setting up a default server configuration and checking the maximum request body size. ```rust use xberg::core::ServerConfig; let mut config = ServerConfig::default(); assert_eq!(config.max_request_body_mb(), 100); ```