Table of Contents
Fetching ...

Representing and querying data tensors in RDF and SPARQL

Piotr Marciniak, Piotr Sowinski, Maria Ganzha

TL;DR

The paper addresses the lack of native tensor representation in RDF for embeddings and ML data by introducing two datatypes, dt:NumericDataTensor and dt:BooleanDataTensor, whose JSON lexical form encodes data and shape; it also provides a comprehensive SPARQL extension with a large set of tensor functions and four aggregates to enable in-RDF tensor processing. Implemented on Apache Jena using the ND4J library, the system supports CPU vectorization and CUDA acceleration, with unit/integration tests validating correctness. A public specification, open-source implementation, and example KG with queries illustrate the practical integration of ML-like tensor processing into knowledge graphs. This work enables more efficient, semantically rich querying of embeddings within RDF ecosystems, bridging machine learning representations with semantic data management; future refinements and binary representations are discussed to further reduce serialization overhead.

Abstract

Embedding tensors in databases has recently gained in significance, due to the rapid proliferation of machine learning methods (including LLMs) which produce embeddings in the form of tensors. To support emerging use cases hybridizing machine learning with knowledge graphs, a robust and efficient tensor representation scheme is needed. We introduce a novel approach for representing data tensors as literals in RDF, along with an extension of SPARQL implementing specialized functionalities for handling such literals. The extension includes 36 SPARQL functions and four aggregates. To support this approach, we provide a thoroughly tested, open-source implementation based on Apache Jena, along with an exemplary knowledge graph and query set.

Representing and querying data tensors in RDF and SPARQL

TL;DR

The paper addresses the lack of native tensor representation in RDF for embeddings and ML data by introducing two datatypes, dt:NumericDataTensor and dt:BooleanDataTensor, whose JSON lexical form encodes data and shape; it also provides a comprehensive SPARQL extension with a large set of tensor functions and four aggregates to enable in-RDF tensor processing. Implemented on Apache Jena using the ND4J library, the system supports CPU vectorization and CUDA acceleration, with unit/integration tests validating correctness. A public specification, open-source implementation, and example KG with queries illustrate the practical integration of ML-like tensor processing into knowledge graphs. This work enables more efficient, semantically rich querying of embeddings within RDF ecosystems, bridging machine learning representations with semantic data management; future refinements and binary representations are discussed to further reduce serialization overhead.

Abstract

Embedding tensors in databases has recently gained in significance, due to the rapid proliferation of machine learning methods (including LLMs) which produce embeddings in the form of tensors. To support emerging use cases hybridizing machine learning with knowledge graphs, a robust and efficient tensor representation scheme is needed. We introduce a novel approach for representing data tensors as literals in RDF, along with an extension of SPARQL implementing specialized functionalities for handling such literals. The extension includes 36 SPARQL functions and four aggregates. To support this approach, we provide a thoroughly tested, open-source implementation based on Apache Jena, along with an exemplary knowledge graph and query set.
Paper Structure (4 sections, 2 figures)

This paper contains 4 sections, 2 figures.

Figures (2)

  • Figure 1: Representation as rdf:List
  • Figure 2: Representation as rdf:Seq