Skip to content
/ rdf-qa Public

Explainable complex question answering over RDF files via Llama Index.

License

Notifications You must be signed in to change notification settings

mommi84/rdf-qa

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rdf-qa

Explainable complex question answering over RDF files via Llama Index.

Usage

Install dependencies:

pip3 install --upgrade llama_index openai

Store OpenAI API key:

export OPENAI_API_KEY=<your-key>

Example usage:

from llama_index import GPTSimpleVectorIndex, download_loader

RDFReader = download_loader("RDFReader")
document = RDFReader().load_data(file="./example.nt")
index = GPTSimpleVectorIndex(document)

result = index.query(
  "list all places in a quoted Python array, then explain why")
print(result.response)
# >>> ['Lombardy', 'Milan', 'Piedmont']
# >>>
# >>> The answer is ['Lombardy', 'Milan', 'Piedmont'] because all three 
# >>> of these are listed as types of places in the context information. 
# >>> Lombardy and Piedmont are both listed as types of regions, and 
# >>> Milan is listed as a type of city. All three of these are 
# >>> subclasses of the type 'place', which is a subclass of 'thing'.

Visualisation of the example RDF graph.

API

pip3 install flask
python3 server.py

The endpoint will be available at localhost:5050 by default.

Indexing

Endpoint: /index (POST)

Form data:

  • file: the RDF file to index

This will return the internal ID of the index, to be used for querying.

Query

Endpoint: /query (GET)

Parameters:

  • id: internal ID of the index
  • query: url-encoded query

E.g., http://localhost:5050/query?id=5aa30cf341cc0fd1494da302649b04&query=list%20all%20regions

Webapp

pip3 install flask streamlit

Refresh terminal session or open new terminal.

streamlit run app.py 

Screenshot of the webapp.