Using LangChain with Ontotext GraphDB
Posted: Jan 30, 2025.
The Ontotext GraphDB integration in LangChain allows you to interact with GraphDB, a powerful RDF and SPARQL-compliant graph database. In this guide, we'll explore how to use the OntotextGraphDBGraph class to query and work with graph data.
What is OntotextGraphDBGraph?
OntotextGraphDBGraph is a wrapper class that enables interaction with Ontotext GraphDB graph databases. It provides functionality to:
- Execute SPARQL queries against a GraphDB endpoint
- Load and work with ontology schemas from either SPARQL CONSTRUCT queries or local RDF files
- Handle authentication for secured GraphDB instances
The class is particularly useful when you need to perform semantic queries against RDF data stored in GraphDB and integrate it with LangChain's capabilities.
Reference
Method/Attribute | Description |
---|---|
__init__() | Constructor that takes query endpoint URL and either a CONSTRUCT query or local file path to define the ontology schema |
query() | Executes a SPARQL query against the graph database |
get_schema | Returns the schema of the graph database in turtle format |
How to use OntotextGraphDBGraph
Basic Setup
First, create an instance of OntotextGraphDBGraph by specifying the query endpoint and schema source:
Working with Secured GraphDB
If your GraphDB instance requires authentication, set the credentials using environment variables:
Executing Queries
Use the query()
method to execute SPARQL queries:
Loading Schema from Different RDF Formats
OntotextGraphDBGraph supports various RDF formats when loading from local files:
Supported formats include:
- Turtle (.ttl)
- RDF/XML (.xml)
- JSON-LD (.jsonld)
- N-Triples (.nt)
- Notation-3 (.n3)
- TriG (.trig)
- TriX (.trix)
- N-Quads (.nq)
Integration with Other LangChain Components
OntotextGraphDBGraph is commonly used with OntotextGraphDBQAChain for natural language querying:
This integration enables powerful natural language interactions with your graph database, combining the semantic capabilities of GraphDB with LangChain's LLM features.
An alternative to LangSmith
Open-source LangChain monitoring, prompt management, and magic. Get started in 2 minutes.
LangChain DocsJoin 10,000+ subscribers
Every 2 weeks, latest model releases and industry news.
An alternative to LangSmith
Open-source LangChain monitoring, prompt management, and magic. Get started in 2 minutes.