Skip to content

Commit f931a9c

Browse files
community[patch]: Pass kwargs to SPARQLStore from RdfGraph (#20385)
This introduces `store_kwargs` which behaves similarly to `graph_kwargs` on the `RdfGraph` object, which will enable users to pass `headers` and other arguments to the underlying `SPARQLStore` object. I have also made a [PR in `rdflib` to support passing `default_graph`](RDFLib/rdflib#2761). Example usage: ```python from langchain_community.graphs import RdfGraph graph = RdfGraph( query_endpoint="http://localhost/sparql", standard="rdf", store_kwargs=dict( default_graph="http://example.com/mygraph" ) ) ``` <!--If no one reviews your PR within a few days, please @-mention one of baskaryan, efriis, eyurtsev, hwchase17.--> --------- Co-authored-by: Bagatur <[email protected]> Co-authored-by: Bagatur <[email protected]>
1 parent e57cf73 commit f931a9c

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

libs/community/langchain_community/graphs/rdf_graph.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ def __init__(
117117
standard: Optional[str] = "rdf",
118118
local_copy: Optional[str] = None,
119119
graph_kwargs: Optional[Dict] = None,
120+
store_kwargs: Optional[Dict] = None,
120121
) -> None:
121122
"""
122123
Set up the RDFlib graph
@@ -130,6 +131,9 @@ def __init__(
130131
:param graph_kwargs: Additional rdflib.Graph specific kwargs
131132
that will be used to initialize it,
132133
if query_endpoint is provided.
134+
:param store_kwargs: Additional sparqlstore.SPARQLStore specific kwargs
135+
that will be used to initialize it,
136+
if query_endpoint is provided.
133137
"""
134138
self.source_file = source_file
135139
self.serialization = serialization
@@ -174,12 +178,13 @@ def __init__(
174178
self.graph.parse(source_file, format=self.serialization)
175179

176180
if query_endpoint:
181+
store_kwargs = store_kwargs or {}
177182
self.mode = "store"
178183
if not update_endpoint:
179-
self._store = sparqlstore.SPARQLStore()
184+
self._store = sparqlstore.SPARQLStore(**store_kwargs)
180185
self._store.open(query_endpoint)
181186
else:
182-
self._store = sparqlstore.SPARQLUpdateStore()
187+
self._store = sparqlstore.SPARQLUpdateStore(**store_kwargs)
183188
self._store.open((query_endpoint, update_endpoint))
184189
graph_kwargs = graph_kwargs or {}
185190
self.graph = rdflib.Graph(self._store, **graph_kwargs)

0 commit comments

Comments
 (0)