From f931a9ce60ba0b4ba2014c6b53743f7140e7698e Mon Sep 17 00:00:00 2001 From: Guilherme Zanotelli <21860048+guizsantos@users.noreply.github.com> Date: Fri, 26 Apr 2024 22:38:29 -0300 Subject: [PATCH] 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`](https://github.com/RDFLib/rdflib/pull/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" ) ) ``` --------- Co-authored-by: Bagatur <22008038+baskaryan@users.noreply.github.com> Co-authored-by: Bagatur --- libs/community/langchain_community/graphs/rdf_graph.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/libs/community/langchain_community/graphs/rdf_graph.py b/libs/community/langchain_community/graphs/rdf_graph.py index d1061cc697..0944981c63 100644 --- a/libs/community/langchain_community/graphs/rdf_graph.py +++ b/libs/community/langchain_community/graphs/rdf_graph.py @@ -117,6 +117,7 @@ class RdfGraph: standard: Optional[str] = "rdf", local_copy: Optional[str] = None, graph_kwargs: Optional[Dict] = None, + store_kwargs: Optional[Dict] = None, ) -> None: """ Set up the RDFlib graph @@ -130,6 +131,9 @@ class RdfGraph: :param graph_kwargs: Additional rdflib.Graph specific kwargs that will be used to initialize it, if query_endpoint is provided. + :param store_kwargs: Additional sparqlstore.SPARQLStore specific kwargs + that will be used to initialize it, + if query_endpoint is provided. """ self.source_file = source_file self.serialization = serialization @@ -174,12 +178,13 @@ class RdfGraph: self.graph.parse(source_file, format=self.serialization) if query_endpoint: + store_kwargs = store_kwargs or {} self.mode = "store" if not update_endpoint: - self._store = sparqlstore.SPARQLStore() + self._store = sparqlstore.SPARQLStore(**store_kwargs) self._store.open(query_endpoint) else: - self._store = sparqlstore.SPARQLUpdateStore() + self._store = sparqlstore.SPARQLUpdateStore(**store_kwargs) self._store.open((query_endpoint, update_endpoint)) graph_kwargs = graph_kwargs or {} self.graph = rdflib.Graph(self._store, **graph_kwargs)