Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for SPARQL #7165

Merged
merged 15 commits into from
Jul 5, 2023
Merged

Support for SPARQL #7165

merged 15 commits into from
Jul 5, 2023

Conversation

felixocker
Copy link
Contributor

SPARQL for LangChain

Description

LangChain support for knowledge graphs relying on W3C standards using RDFlib: SPARQL/ RDF(S)/ OWL with special focus on RDF \

  • Works with local files, files from the web, and SPARQL endpoints
  • Supports both SELECT and UPDATE queries
  • Includes both a Jupyter notebook with an example and integration tests

Contribution compared to related PRs and discussions

  • Wikibase agent - uses SPARQL, but specifically for wikibase querying
  • Cypher qa - graph DB question answering for Neo4J via Cypher
  • PR 6050 - tries something similar, but does not cover UPDATE queries and supports only RDF
  • Discussions on w3c mailing list related to the combination of LLMs (specifically ChatGPT) and knowledge graphs

Dependencies

Tag maintainer

Graph database related to memory -> @hwchase17

@vercel
Copy link

vercel bot commented Jul 4, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
langchain ⬜️ Ignored (Inspect) Jul 4, 2023 11:25pm

@dosubot dosubot bot added 🤖:docs Changes to documentation and examples, like .md, .rst, .ipynb files. Changes to the docs/ folder 🤖:enhancement A large net-new component, integration, or chain. Use sparingly. The largest features labels Jul 4, 2023
Copy link
Contributor

@hwchase17 hwchase17 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks fantastic! thanks so much

@hwchase17 hwchase17 merged commit db98c44 into langchain-ai:master Jul 5, 2023
14 checks passed
@marioscrock
Copy link
Contributor

@felixocker thank you for this PR! I would like to kindly ask if you can help me with a related issue. I keep receiving warning messages from rdflib when loading an RDF file even if URIs are valid.

<http://xmlns.com/foaf/0.1/title does not look like a valid URI, trying to serialize this will break.
<http://xmlns.com/foaf/0.1/title> ( does not look like a valid URI, trying to serialize this will break.
<http://xmlns.com/foaf/0.1/title> (title does not look like a valid URI, trying to serialize this will break.
<http://xmlns.com/foaf/0.1/title> (title,  does not look like a valid URI, trying to serialize this will break.
<http://xmlns.com/foaf/0.1/title> (title, ) does not look like a valid URI, trying to serialize this will break.

I did some tests locally and it seems to me that the problem may be related to the implementation of the _res_to_str function. I modified this as follows and it seems to work fine (return f"<{res[var]}> ({self._get_local_name(res[var])}, {str(res['com'])})").

@felixocker
Copy link
Contributor Author

@marioscrock thanks! yeah, seems like this is due to the concatenation of strings and the URI in the _res_to_str function. I just created PR #8025 with a fix

@marioscrock
Copy link
Contributor

@felixocker thank you for the quick feedback and fix!

baskaryan pushed a commit that referenced this pull request Jul 20, 2023
#8025)

- Description: fix to avoid rdflib warnings when concatenating URIs and
strings to create the text snippet for the knowledge graph's schema.
@marioscrock pointed this out in a comment related to #7165
- Issue: None, but the problem was mentioned as a comment in #7165
- Dependencies: None
- Tag maintainer: Related to memory -> @hwchase17, maybe @baskaryan as
it is a fix
baskaryan added a commit that referenced this pull request Jul 24, 2023
**Description**: Serves as an introduction to LangChain's support for
[ArangoDB](https://github.com/arangodb/arangodb), similar to
#7165 and
#4881

**Issue**: No issue has been created for this feature

**Dependencies**: `python-arango` has been added as an optional
dependency via the `CONTRIBUTING.md` guidelines
 
**Twitter handle**: [at]arangodb

- Integration test has been added
- Notebook has been added:
[graph_arangodb_qa.ipynb](https://github.com/amahanna/langchain/blob/master/docs/extras/modules/chains/additional/graph_arangodb_qa.ipynb)

[![Open In
Collab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/amahanna/langchain/blob/master/docs/extras/modules/chains/additional/graph_arangodb_qa.ipynb)

```
docker run -p 8529:8529 -e ARANGO_ROOT_PASSWORD= arangodb/arangodb
```

```
pip install git+https://github.com/amahanna/langchain.git
```

```python
from arango import ArangoClient

from langchain.chat_models import ChatOpenAI
from langchain.graphs import ArangoGraph
from langchain.chains import ArangoGraphQAChain

db = ArangoClient(hosts="localhost:8529").db(name="_system", username="root", password="", verify=True)

graph = ArangoGraph(db)

chain = ArangoGraphQAChain.from_llm(ChatOpenAI(temperature=0), graph=graph)

chain.run("Is Ned Stark alive?")
```

---------

Co-authored-by: Bagatur <baskaryan@gmail.com>
@felixocker felixocker deleted the swt branch July 31, 2023 09:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤖:docs Changes to documentation and examples, like .md, .rst, .ipynb files. Changes to the docs/ folder 🤖:enhancement A large net-new component, integration, or chain. Use sparingly. The largest features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants