Setup & Installation
Prerequisites:- SAP HANA Cloud instance with the triple store feature enabled
- See: Enable Triple Store
@sap/hana-langchain package along with its peer dependencies:
HanaRdfGraph Class.
Creating a HanaRdfGraph instance
The constructor requires:
connection: an active@sap/hana-client ConnectioninstancegraphUri: the named graph (or"DEFAULT") where your RDF data lives- One of:
ontologyQuery: a SPARQL CONSTRUCT to extract schema triplesontologyUri: a hosted ontology graph URIontologyLocalFile+ontologyLocalFileFormat: a local Turtle/RDF fileautoExtractOntology: true(not recommended for production—see note)
graphUri vs. Ontology
graphUri: The named graph in your SAP HANA Cloud instance that contains your instance data (sometimes 100k+ triples). If nographUri,""or"DEFAULT"is provided, the default graph is used.- Ontology: a lean schema (typically ~50-100 triples) describing classes, properties, domains, ranges, labels, comments, and subclass relationships. The ontology guides SPARQL generation and result interpretation.
Creating a graph instance with DEFAULT graph
More info on the DEFAULT graph can be found at DEFAULT Graph and Named Graphs.Creating a graph instance with a graph_uri
Creating a graph instance with a remote ontology_uri
Creating a graph instance with a custom ontology_query
Use a custom CONSTRUCT query to selectively extract schema triples.
Load ontology from a local RDF file
Supported RDF formats:Turtle, N-Triples, Notation-3, Trig, N-Quads.
Auto extraction of ontology
(auto_extract_ontology=True): Infer schema information directly from your instance data.
Note: Auto-extraction is not recommended for production—it omits important triples likerdfs:label,rdfs:comment, andrdfs:subClassOfin general.
Executing SPARQL Queries
You can use thequery() method to execute arbitrary SPARQL queries (SELECT, ASK, CONSTRUCT, etc.) on the data graph.
The function has the following parameters
- query: the SPARQL query string.
- content_type: the response format for the output (Default is CSV)
- CSV:
"sparql-results+xml" - JSON:
"sparql-results+json" - XML:
"sparql-results+csv" - TSV:
"sparql-results+tsv"
Note: CONSTRUCT and ASK Queries returnLet us insert some data into theturtleandbooleanformats respectively.
Puppets graph.
Puppets graph.
Puppets graph.
Connect these docs to Claude, VSCode, and more via MCP for real-time answers.

