Package io.agentscope.core.rag.reader
Class ReaderUtils
java.lang.Object
io.agentscope.core.rag.reader.ReaderUtils
Utility class for common reader operations.
This class provides shared functionality for document readers, including:
- Document ID generation using hash algorithms
- Byte array to hex string conversion
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringbytesToHex(byte[] bytes) Converts byte array to hexadecimal string.static StringgenerateDocId(String input, String algorithm) Generates a deterministic document ID using the specified hash algorithm.static StringgenerateDocIdMD5(String input) Generates a deterministic document ID using MD5 hash.static StringgenerateDocIdSHA256(String input) Generates a deterministic document ID using SHA-256 hash.
-
Method Details
-
generateDocId
Generates a deterministic document ID using the specified hash algorithm.This method is useful for creating consistent document IDs based on file paths or other identifying information.
- Parameters:
input- the input string to hash (typically a file path)algorithm- the hash algorithm to use (e.g., "MD5", "SHA-256")- Returns:
- the hash of the input as a hexadecimal string
- Throws:
RuntimeException- if the specified algorithm is not available
-
generateDocIdMD5
Generates a deterministic document ID using MD5 hash.This is a convenience method that uses MD5 as the hash algorithm.
- Parameters:
input- the input string to hash (typically a file path)- Returns:
- MD5 hash of the input as a hexadecimal string
-
generateDocIdSHA256
Generates a deterministic document ID using SHA-256 hash.This is a convenience method that uses SHA-256 as the hash algorithm.
- Parameters:
input- the input string to hash (typically a file path)- Returns:
- SHA-256 hash of the input as a hexadecimal string
-
bytesToHex
Converts byte array to hexadecimal string.- Parameters:
bytes- the byte array to convert- Returns:
- hexadecimal string representation (lowercase)
-