LlamaIndex based Retrieval Augmented Generation (RAG) using a Virtuoso backend via SPARQL

Using Virtuoso as Knowledge Graph RAG backend

What?

Using the SPARQL Connector for LLamaIndex for natural language interactions with a SPARQL endpoint associated with data derived from a Wikipedia document.

Why?

Using SPARQL to drive Retrieval Augmented Generation (RAG) as a hallucination minimization strategy for Large Language Models (LLMs) .

How?

The following post demonstrates how to use the Virtuoso RDF Quad Store as backend for
SPARQL Graph RAG Demo

Preparation

  1. Ensure a working installation of Python is in place
  2. Access to the ~/sparql-auth SPARQL endpoint of a Virtuoso instance
  3. Extract llama_test.zip (1.7 KB) zip file to a directory of choice
  4. Edit the extracted llama_test.py and llama_test2.py files and set the ENDPOINT variable to reference the target Virtuoso http://{CNAME}:{PORT}/sparql-auth SPARQL auth endpoint
  5. If a different version to the python llama_index is already have installed, first uninstall it with the command:
pip uninstall llama_index
  1. Install the OpenLink Software fork of the llama_index with the command:
pip install git+https://github.com/OpenLinkSoftware/llama_index
  1. Set an OpenAI API Key in your terminal shell with the command:
export OPENAI_API_KEY={Your-OpenAI API Key}
  1. Create the following directory for dataset storage:
mkdir llama_storage_graph

Generate RAG Dataset from a Wikipedia Article

  1. Run Python to get a command prompt:
python 
  1. Execute the test program, to load the sample data with the command:
exec(open('llama_test.py').read())
  1. On successful load of the data a question can be asked with the python command
response_graph_rag = kg_rag_query_engine.query("[question text]")
  1. Display response/answer to the question with the command:
print(str(response_graph_rag))
  1. Source code of llama_test.py python script:
$ cat llama_test.py 
from llama_index import download_loader
import os
import logging
from llama_index import (
        KnowledgeGraphIndex,
        ServiceContext,
        )

from llama_index.storage.storage_context import StorageContext
from llama_index.graph_stores import SparqlGraphStore
from llama_index.llms import OpenAI
from llama_index import load_index_from_storage
import openai

openai.api_key = os.environ["OPENAI_API_KEY"];

llm = OpenAI(temperature=0, model="text-davinci-002")
service_context = ServiceContext.from_defaults(llm=llm, chunk_size=512)

ENDPOINT = 'http://localhost:8890/sparql-auth'
GRAPH = 'http://purl.org/stuff/guardians'
BASE_URI = 'http://purl.org/stuff/data'
USER = 'dba'
PASSWORD = 'dba'

graph_store = SparqlGraphStore(
        sparql_endpoint=ENDPOINT,
        sparql_graph=GRAPH,
        sparql_base_uri=BASE_URI,
        create_graph=False,
        user_name=USER,
        user_password=PASSWORD)
storage_context = StorageContext.from_defaults(graph_store=graph_store)

WikipediaReader = download_loader("WikipediaReader")
loader = WikipediaReader()
documents = loader.load_data(
        pages=['Barbie (film)'], auto_suggest=False)

kg_index = KnowledgeGraphIndex.from_documents(
        documents,
        storage_context=storage_context,
        service_context=service_context,
        max_triplets_per_chunk=10,
        sparql_endpoint=ENDPOINT,
        sparql_graph=GRAPH,
        sparql_base_uri=BASE_URI,
        include_embeddings=True,
        )

kg_index.storage_context.persist(persist_dir='./llama_storage_graph')

kg_rag_query_engine = kg_index.as_query_engine(
        include_text=False,
        retriever_mode="keyword",
        response_mode="tree_summarize",
        )

response_graph_rag = kg_rag_query_engine.query("In the movie, what does Barbie think about?")

print(str(response_graph_rag))
$

Sample Session Output from running the`llama_test.py program:

Installation of OpenLink llama_index python package:

$ export OPENAI_API_KEY=sk-***

$ pip3 install git+https://github.com/OpenLinkSoftware/llama_index
Collecting git+https://github.com/OpenLinkSoftware/llama_index
  Cloning https://github.com/OpenLinkSoftware/llama_index to /private/var/folders/h3/d48_9qcd50l1hsszhl5_sbfc0000gn/T/pip-req-build-oj3kybax
  Running command git clone --filter=blob:none --quiet https://github.com/OpenLinkSoftware/llama_index /private/var/folders/h3/d48_9qcd50l1hsszhl5_sbfc0000gn/T/pip-req-build-oj3kybax
  Resolved https://github.com/OpenLinkSoftware/llama_index to commit 7a7e6f42e807d64df9b3737604bb434edb9fb93c
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Requirement already satisfied: tiktoken in /opt/homebrew/lib/python3.11/site-packages (from llama-index==0.8.29) (0.5.1)
Requirement already satisfied: dataclasses-json in /opt/homebrew/lib/python3.11/site-packages (from llama-index==0.8.29) (0.6.1)
Requirement already satisfied: langchain>=0.0.262 in /opt/homebrew/lib/python3.11/site-packages (from llama-index==0.8.29) (0.0.305)
Requirement already satisfied: sqlalchemy>=2.0.15 in /opt/homebrew/lib/python3.11/site-packages (from llama-index==0.8.29) (2.0.21)
Requirement already satisfied: numpy in /opt/homebrew/lib/python3.11/site-packages (from llama-index==0.8.29) (1.26.0)
Requirement already satisfied: tenacity<9.0.0,>=8.2.0 in /opt/homebrew/lib/python3.11/site-packages (from llama-index==0.8.29) (8.2.3)
Requirement already satisfied: openai>=0.26.4 in /opt/homebrew/lib/python3.11/site-packages (from llama-index==0.8.29) (0.28.1)
Requirement already satisfied: pandas in /opt/homebrew/lib/python3.11/site-packages (from llama-index==0.8.29) (2.1.1)
Requirement already satisfied: urllib3<2 in /opt/homebrew/lib/python3.11/site-packages (from llama-index==0.8.29) (1.26.16)
Requirement already satisfied: fsspec>=2023.5.0 in /opt/homebrew/lib/python3.11/site-packages (from llama-index==0.8.29) (2023.9.2)
Requirement already satisfied: typing-inspect>=0.8.0 in /opt/homebrew/lib/python3.11/site-packages (from llama-index==0.8.29) (0.9.0)
Requirement already satisfied: typing-extensions>=4.5.0 in /opt/homebrew/lib/python3.11/site-packages (from llama-index==0.8.29) (4.8.0)
Requirement already satisfied: beautifulsoup4 in /opt/homebrew/lib/python3.11/site-packages (from llama-index==0.8.29) (4.12.2)
Requirement already satisfied: nest-asyncio in /opt/homebrew/lib/python3.11/site-packages (from llama-index==0.8.29) (1.5.8)
Requirement already satisfied: nltk in /opt/homebrew/lib/python3.11/site-packages (from llama-index==0.8.29) (3.8.1)
Requirement already satisfied: sparqlwrapper in /opt/homebrew/lib/python3.11/site-packages (from llama-index==0.8.29) (2.0.0)
Requirement already satisfied: PyYAML>=5.3 in /opt/homebrew/lib/python3.11/site-packages (from langchain>=0.0.262->llama-index==0.8.29) (6.0.1)
Requirement already satisfied: aiohttp<4.0.0,>=3.8.3 in /opt/homebrew/lib/python3.11/site-packages (from langchain>=0.0.262->llama-index==0.8.29) (3.8.5)
Requirement already satisfied: anyio<4.0 in /opt/homebrew/lib/python3.11/site-packages (from langchain>=0.0.262->llama-index==0.8.29) (3.7.1)
Requirement already satisfied: jsonpatch<2.0,>=1.33 in /opt/homebrew/lib/python3.11/site-packages (from langchain>=0.0.262->llama-index==0.8.29) (1.33)
Requirement already satisfied: langsmith<0.1.0,>=0.0.38 in /opt/homebrew/lib/python3.11/site-packages (from langchain>=0.0.262->llama-index==0.8.29) (0.0.41)
Requirement already satisfied: numexpr<3.0.0,>=2.8.4 in /opt/homebrew/lib/python3.11/site-packages (from langchain>=0.0.262->llama-index==0.8.29) (2.8.7)
Requirement already satisfied: pydantic<3,>=1 in /opt/homebrew/lib/python3.11/site-packages (from langchain>=0.0.262->llama-index==0.8.29) (2.4.2)
Requirement already satisfied: requests<3,>=2 in /opt/homebrew/lib/python3.11/site-packages (from langchain>=0.0.262->llama-index==0.8.29) (2.31.0)
Requirement already satisfied: marshmallow<4.0.0,>=3.18.0 in /opt/homebrew/lib/python3.11/site-packages (from dataclasses-json->llama-index==0.8.29) (3.20.1)
Requirement already satisfied: tqdm in /opt/homebrew/lib/python3.11/site-packages (from openai>=0.26.4->llama-index==0.8.29) (4.66.1)
Requirement already satisfied: mypy-extensions>=0.3.0 in /opt/homebrew/lib/python3.11/site-packages (from typing-inspect>=0.8.0->llama-index==0.8.29) (1.0.0)
Requirement already satisfied: soupsieve>1.2 in /opt/homebrew/lib/python3.11/site-packages (from beautifulsoup4->llama-index==0.8.29) (2.5)
Requirement already satisfied: click in /opt/homebrew/lib/python3.11/site-packages (from nltk->llama-index==0.8.29) (8.1.7)
Requirement already satisfied: joblib in /opt/homebrew/lib/python3.11/site-packages (from nltk->llama-index==0.8.29) (1.3.2)
Requirement already satisfied: regex>=2021.8.3 in /opt/homebrew/lib/python3.11/site-packages (from nltk->llama-index==0.8.29) (2023.8.8)
Requirement already satisfied: python-dateutil>=2.8.2 in /opt/homebrew/lib/python3.11/site-packages (from pandas->llama-index==0.8.29) (2.8.2)
Requirement already satisfied: pytz>=2020.1 in /opt/homebrew/lib/python3.11/site-packages (from pandas->llama-index==0.8.29) (2023.3.post1)
Requirement already satisfied: tzdata>=2022.1 in /opt/homebrew/lib/python3.11/site-packages (from pandas->llama-index==0.8.29) (2023.3)
Requirement already satisfied: rdflib>=6.1.1 in /opt/homebrew/lib/python3.11/site-packages (from sparqlwrapper->llama-index==0.8.29) (7.0.0)
Requirement already satisfied: attrs>=17.3.0 in /opt/homebrew/lib/python3.11/site-packages (from aiohttp<4.0.0,>=3.8.3->langchain>=0.0.262->llama-index==0.8.29) (23.1.0)
Requirement already satisfied: charset-normalizer<4.0,>=2.0 in /opt/homebrew/lib/python3.11/site-packages (from aiohttp<4.0.0,>=3.8.3->langchain>=0.0.262->llama-index==0.8.29) (3.3.0)
Requirement already satisfied: multidict<7.0,>=4.5 in /opt/homebrew/lib/python3.11/site-packages (from aiohttp<4.0.0,>=3.8.3->langchain>=0.0.262->llama-index==0.8.29) (6.0.4)
Requirement already satisfied: async-timeout<5.0,>=4.0.0a3 in /opt/homebrew/lib/python3.11/site-packages (from aiohttp<4.0.0,>=3.8.3->langchain>=0.0.262->llama-index==0.8.29) (4.0.3)
Requirement already satisfied: yarl<2.0,>=1.0 in /opt/homebrew/lib/python3.11/site-packages (from aiohttp<4.0.0,>=3.8.3->langchain>=0.0.262->llama-index==0.8.29) (1.9.2)
Requirement already satisfied: frozenlist>=1.1.1 in /opt/homebrew/lib/python3.11/site-packages (from aiohttp<4.0.0,>=3.8.3->langchain>=0.0.262->llama-index==0.8.29) (1.4.0)
Requirement already satisfied: aiosignal>=1.1.2 in /opt/homebrew/lib/python3.11/site-packages (from aiohttp<4.0.0,>=3.8.3->langchain>=0.0.262->llama-index==0.8.29) (1.3.1)
Requirement already satisfied: idna>=2.8 in /opt/homebrew/lib/python3.11/site-packages (from anyio<4.0->langchain>=0.0.262->llama-index==0.8.29) (3.4)
Requirement already satisfied: sniffio>=1.1 in /opt/homebrew/lib/python3.11/site-packages (from anyio<4.0->langchain>=0.0.262->llama-index==0.8.29) (1.3.0)
Requirement already satisfied: jsonpointer>=1.9 in /opt/homebrew/lib/python3.11/site-packages (from jsonpatch<2.0,>=1.33->langchain>=0.0.262->llama-index==0.8.29) (2.4)
Requirement already satisfied: packaging>=17.0 in /opt/homebrew/lib/python3.11/site-packages (from marshmallow<4.0.0,>=3.18.0->dataclasses-json->llama-index==0.8.29) (23.1)
Requirement already satisfied: annotated-types>=0.4.0 in /opt/homebrew/lib/python3.11/site-packages (from pydantic<3,>=1->langchain>=0.0.262->llama-index==0.8.29) (0.5.0)
Requirement already satisfied: pydantic-core==2.10.1 in /opt/homebrew/lib/python3.11/site-packages (from pydantic<3,>=1->langchain>=0.0.262->llama-index==0.8.29) (2.10.1)
Requirement already satisfied: six>=1.5 in /opt/homebrew/lib/python3.11/site-packages (from python-dateutil>=2.8.2->pandas->llama-index==0.8.29) (1.16.0)
Requirement already satisfied: isodate<0.7.0,>=0.6.0 in /opt/homebrew/lib/python3.11/site-packages (from rdflib>=6.1.1->sparqlwrapper->llama-index==0.8.29) (0.6.1)
Requirement already satisfied: pyparsing<4,>=2.1.0 in /opt/homebrew/lib/python3.11/site-packages (from rdflib>=6.1.1->sparqlwrapper->llama-index==0.8.29) (3.1.1)
Requirement already satisfied: certifi>=2017.4.17 in /opt/homebrew/lib/python3.11/site-packages (from requests<3,>=2->langchain>=0.0.262->llama-index==0.8.29) (2023.7.22)
Building wheels for collected packages: llama-index
  Building wheel for llama-index (pyproject.toml) ... done
  Created wheel for llama-index: filename=llama_index-0.8.29-py3-none-any.whl size=812925 sha256=1c014b161f3dbc9b64d69b8f39a7e760da76dbbc99a92fa80531c8c2819be83d
  Stored in directory: /private/var/folders/h3/d48_9qcd50l1hsszhl5_sbfc0000gn/T/pip-ephem-wheel-cache-9o9nedim/wheels/bb/3f/25/d93127d8977002b52809179ac0e9e92fe9b8270b588426c2cc
Successfully built llama-index
Installing collected packages: llama-index
Successfully installed llama-index-0.8.29

Python command-line session:

$ python3
Python 3.11.5 (main, Aug 24 2023, 15:09:45) [Clang 14.0.3 (clang-1403.0.22.14.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

>>> exec(open('llama_test.py').read())
(Barbie, is, 2023 American fantasy comedy film)
(Barbie, directed by, Greta Gerwig)
(Barbie, stars, Margot Robbie)
(Barbie, follows, the pair)
(Barbie, on a journey of, self-discovery)
(Barbie, after, multiple writer and director changes)
(Barbie, with, principal photography occurring primarily at Warner Bros. Studios, Leavesden)
(Barbie, in England and at, the Venice Beach Skatepark)
(Barbie, in Los Angeles from, March to July)
(Barbie, received, critical acclaim)
(Beach Ken, is, happy when with Barbie)
(Beach Ken, seeks, closer relationship with Barbie)
(Barbie, rebuffs, Beach Ken)
(Barbie, develops, bad breath)
(Barbie, develops, cellulite)
(Barbie, develops, flat feet)
(Weird Barbie, tells, Barbie must find child playing with her)
(Ken, stows away, in her convertible)
(Barbie, punches, man)
(Barbie, and Ken, arrested)
(Mattel's CEO, orders, their recapture)
(Barbie, tracks down, her owner)
(Barbie, criticized for, encouraging unrealistic beauty standards)
(Gloria, inadvertently catalyzed, her existential crisis)
(Mattel, attempts to put Barbie, in a toy box)
(Barbie, escapes, with Gloria and Sasha's help)
(Ken, learns about, the patriarchal system)
(Ken, persuades, the other Kens to take over)
(Barbie, unsuccessfully tries, to convince Ken and the other Barbies to return)
(Barbie, becomes, depressed)
(Gloria, gives, an inspirational speech)
(Barbie, restored, self-confidence)
(Barbies, deprogrammed, from their indoctrination)
(Barbies, manipulate, the Kens into fighting amongst themselves)
(Barbies, regain, power)
(Barbies, resolve, to rectify the faults of their previous society)
(Barbie and Ken, apologize, to each other)
(Barbie, has, no set ending)
(Barbie, meets with, Ruth Handler)
(Barbie, meets with, Mattel co-founder)
(Barbie, meets with, creator of Barbie doll)
(Barbie, decides to become, human)
(Barbie, decides to become, return to the real world)
(Gloria, takes, Barbie to her first gynecologist's appointment)
(Gerwig, was given creative freedom, to write the film)
(Baumbach, was given creative freedom, to write the film)
(They, collaborated on, screenplay)
(They, described writing process as, "open" and "free")
(Gerwig, was partially inspired by, book)
(Gerwig, found inspiration in, classic Technicolor musicals)
(The script, contains candid criticism of, Mattel)
(Will Ferrell's portrayal, was meant to be an allegory for, corporate America)
(Gerwig and Robbie, informed the studio that they would also explore, the controversies and problematic parts of Barbie)
(Opting to acknowledge, the controversial nature of the Barbie doll, Gerwig chose to create a film)
(Gerwig would be both "doing the thing and subverting the thing", in the sense that she would be celebrating, the feminism behind Barbie)
(She, was, fascinated by idea)
(humans create dolls, which, imitate humans)
(dolls, convey, message)
(Barbie, desires, to be more than just a plastic doll)
(Gerwig, made the film, as an "earnest attempt to make amends")
(Barbie, being "constrained in multitudes", as "all of these women are Barbie and Barbie is all of these women")
(Barbie, living in, utopia)
(Barbie, facing, the real world)
(She, chose to keep, scene)
(She, felt that, scene epitomized)
(She, also desired, provide a "counterargument")
(Barbie, learns that, some women do not like her)
(Gerwig, felt it gave the film, "real intellectual and emotional power")
(Barbie, is being stared at inappropriately, Venice Beach)
(Gerwig, chose to feature, she felt it was a universal experience)
(Gerwig, was inspired by, audition she did)
(The ending of the film, features, Barbie saying the line)
(Gerwig, had chosen to include, she had wanted to instill confidence)
(Barbie also explores, negative consequences, hierarchical power structures)
(Casting, searching for actresses with, "Barbie energy")
(Ryan Gosling, entered final negotiations to play, Ken)
(Simu Liu, auditioned for the film after, his agent raved about the script)
(Ariana Greenblatt, Alexandra Shipp, and Emma Mackey, were revealed to be in the cast)
(Will Ferrell, joined the cast in, April)
(John Cena, had joined the cast, it was later reported that Cena had spontaneously been offered a part in the film)
(Helen Mirren, narrated the film's trailer and the film itself)
(Robbie and Gosling, were each paid, $12.5 million for their participation as actors)
(Gal Gadot, was unavailable due to scheduling conflicts)
(Timothée Chalamet and Saoirse Ronan, were considered for, cameo appearances)
(Sarah Greenwood, is set designer, of the film)
(Katie Spencer, is decorator, of the film)
(Barbie Dreamhouse, drew inspiration from, mid-century modernist architecture)
(Barbie Dreamhouse, drew inspiration from, Palm Springs)
(Barbie Dreamhouse, drew inspiration from, Kaufmann Desert House)
(Barbie Dreamhouse, drew inspiration from, Richard Neutra)
(Barbie Dreamhouse, drew inspiration from, Slim Aarons)
(Gerwig, wanted to capture, "what was so ridiculously fun about the Dreamhouses")
(Gerwig, referenced, Pee-wee's Big Adventure)
(Gerwig, referenced, Wayne Thiebaud)
(Costume designer Jacqueline Durran, employed, practical approach)
(Jacqueline Durran, collaborated with, Gerwig)
(Jacqueline Durran, created costumes, fifteen color combinations)
(Rodrigo Prieto, served as, cinematographer)
(Gerwig, opted to use, filming techniques)
(Gerwig, watched, Powell and Pressburger's A Matter of Life and Death)
(Robbie and Gosling, played their characters, drama)
(Ivana Primorac, was lead hair and makeup artist, for the film)
(Alexandre Desplat, was set to score, Barbie in early September 2022)
(Mark Ronson and Andrew Wyatt, took over scoring duties)
(WaterTower Music, released, the score on August 4, 2023)
(Ronson, was tasked with curating, a compilation soundtrack)
(Barbie: The Album, was released, on July 21, 2023)
(Dua Lipa, was released, as the album's lead single on May 26, 2023)
(Karol G, was released, on June 2, 2023)
(Pink Pantheress, was released, on June 9, 2023)
(Nicki Minaj and Ice Spice, was released, on June 23, 2023)
(Charli XCX, was released, on June 30, 2023)
(Fifty Fifty and Kaliii, was released, on July 6, 2023)
(Ryan Gosling, was singing, "I'm Just Ken")
(Warner Bros, released, a preview clip of Ryan Gosling singing "I'm Just Ken" on July 10, 2023)
(the album's fourth single, "What Was I Made For?", was released on July 10, 2023)
(Barbie, was promoted with, an extensive marketing campaign)
(Barbie, entered into promotional partnerships with, various brands)
(Barbie, was coproduced by, Mattel Television)
(Variety, reported that, Warner Bros. spent $150 million on marketing for Barbie)
(Barbie, was revealed during, Warner Bros. presentation)
(Barbie, was released to the public on, April 27, 2022)
(Margot Robbie, was made to play, Barbie)
(Ryan Gosling, was released, on June 15, 2022)
(Barbie, was opened at, CCXP event)
(Barbie, debuted during, Avatar: The Way of Water)
(Barbie, was released to the public on, December 16, 2022)
(Greta Gerwig's Barbie movie, will be flooding the screen with variants, of plastic dolls Barbie and Ken)
(The Washington Post, noted that, the teaser captivated multiple demographics)
(An official trailer, was released on, May 25 2023)
(Ben Travis of Empire, said, "There's much to discuss here")
(A parade float, was featured at, the 2023 WeHo Pride Parade)
(In June 2023, a French Barbie poster, went viral)
(Leading up to the release, pink billboards, have appeared worldwide)
(On July 14, 2023, SAG-AFTRA, declared a strike action)
(Robbie showed her support in the action)
(To coincide with the film's release, a stop motion crossover trailer, was released on July 20, 2023)
(Barbie, had world premiere at, Shrine Auditorium)
(Barbie, had European premiere at, Cineworld Leicester Square)
(Barbie, was released theatrically in, United States)
(Barbie, was released theatrically in, United Kingdom)
(Barbie, was released on same day as, Oppenheimer)
(Barbie, will be re-released in, IMAX theaters)
(Barbie, was released on digital download on, September 12)
(Barbie, will be released on Ultra HD Blu-ray on, October 17)
(Barbie, will be released on Blu-ray on, October 17)
(Barbie, will be released on DVD on, October 17)
(Nine-dash line, is, maritime border)
(Nine-dash line, is, between China, Vietnam, Taiwan, Malaysia, Brunei, and the Philippines)
(Nine-dash line, is, controversial)
(Vietnam, banned, Barbie)
(Vietnam, quoted Vi Kiến Thành, as announcing that Barbie would be banned)
(Barbie, would be banned, because it contained "the offending image of the nine-dash line.")
(The Tiền Phong newspaper, reported that, the nine-dash line "appears multiple times in the film")
(Trịnh Hữu Long, said, "The censors will even be praised for overreacting to the unclear map, by both their superiors and the public, because anti-China sentiment runs deep into the country's political culture")
(Michael Caster, said, "Maps are political, and borders often bear historical wounds, but rather than ensuring free and open discussion, the knee jerk response to censor seldom supports historical or transitional justice")
(UC Berkeley professor Peter Zinoman, said, "To the Chinese, the nine-dash line signifies their legitimate claims to the South China Sea")
(Harvard University professor Huệ-Tâm Hồ Tài, said, "they are ready to accept [mainland China's] view of geography. Disinformation works by repetition.")
(New York University professor Kevin Li, said, "In my view, banning [Barbie] was a no-brainer.")
(Chinese Foreign Ministry spokesperson Mao Ning, stated, "The 'South China Sea issue' should not be linked with 'normal cultural exchange'.")
(Senator Francis Tolentino, vice chairman of, Philippine Senate Committee on Foreign Relations)
(Senator Jinggoy Estrada, called to be banned, over the alleged inclusion of the nine-dash line)
(Senator Robin Padilla, chairman of, Senate mass media committee)
(Movie and Television Review and Classification Board, gave the film a PG rating, as well as allowing it to be screened in the country)
(Senator Tolentino, expressed his dismay, at it emerging a day before the seventh anniversary of Philippines' victory in an arbitration over the nine-dash line on July 12, 2016)
(world map drawing, appears in, trailer)
(world map drawing, described as, "child-like crayon drawing")
(Warner Bros., issued statement about, world map drawing)
(world map drawing, depicts, Barbie's journey)
(Muslim-majority countries, attempted to ban, film)
(Pakistan, halted screenings of, film)
(Barbie, was released in, Middle East)
(Barbie, was released in, Algeria)
(Barbie, was released in, Lebanon)
(Barbie, was released in, Kuwait)
(Barbie, promotes, homosexuality)
(Barbie, promotes, Western deviances)
(Barbie, does not comply with, Algeria's religious and cultural beliefs)
(Barbie, grossed, $634.5 million)
(Barbie, became, highest-grossing live-action comedy film)
(Barbie, set the record for, any film that was not a sequel)
(Barbie, became the highest-grossing live-action comedy film of all time)
(Barbie, smashed the domestic record, formerly held by Home Alone)
(Barbie, became the fastest Warner Bros. film to reach $1 billion)
(Barbie, became the highest-grossing film by a solo female director)
(Barbie, became the highest-grossing film of the year)
(Barbie, replaced The Super Mario Bros. Movie, as the highest-grossing film of the year)
(Barbie, scored, biggest opening)
(Barbie, surpassed, Suicide Squad)
(Barbie, dethroned, The Secret Life of Pets)
(Barbie, quickly beat, La La Land)
(Barbie, became, highest-grossing film)
(Barbie, finished in second place, Gran Turismo)
(Barbie, finished in, second place)
(Barbie, opened with, $24.2 million)
(Barbie, became, highest-grossing film)
(Barbie, became, largest second week)
(Barbie, grossed, $74 million)
(Barbie, recorded, 81,000 admissions)
(Barbie, finished, fifth place)
(Barbie, fell behind, Smugglers)
(Barbie, suggested, lack of popularity)
(Barbie, contributed, under-performance)
(Barbie, preached, sexual discrimination)
(Barbie, criticized, negligence)
(Barbie, attained, critical acclaim)
(Barbie, praised, script)
(Robbie, received, acclaim)
(Gosling, received, acclaim)
(Rotten Tomatoes, gave, 88% positive reviews)
(Barbie, is, visually dazzling comedy)
(Barbie, has, meta humor)
(Gerwig, is director of, Barbie)
(Brody, called, Barbie "brilliant, beautiful and fun as hell")
(O'Sullivan, hailed, Barbie as "easily the comedy of the year")
(Jones, said, Barbie is "pretty good")
(The Guardian, awarded, Barbie)
(Peter Bradshaw, described, Barbie)
(Barbie, is, product)
(Gosling, is, scene-stealer)
(India Currents, notes, Barbie)
(Barbie, is, legacy)
(Hollywood Reporter, called, Barbie)
(Gerwig, lauded, Barbie)
(Variety, criticized, Barbie)
(New York, lamented, Barbie)
(Time, praised, Barbie)
(Barbie, explores themes of, existentialism)
(Barbie, is a satire that, pokes fun at capitalism)
(Barbie, is a satire that, cleverly uses capitalist themes)
(Barbie, ruminates on, the very idea of what makes us human)
(Barbie, ruminates on, the idea of 'the other')
(Barbie, ruminates on, whether there's truly such a thing as autonomy or if we're all simply pawns to be picked up and disposed of when we are no longer useful)
(Ford, observed that, in the film Barbie and Ken go on "opposite but equal" journeys of self-discovery)
(Barbie and Ken, go on, "opposite but equal" journeys of self-discovery)
(Barbie and Ken, get "caught in the crosshairs of being both sentient and someone else's idea, battling with free will and the omnipresent predetermined rules about where to go and how to act".)
(Vogue India, Varya Srivastava applied Beauvoirian concepts of existentialism and individualism to Barbie,)
(Barbie, has tried to be inclusive and representative. She has tried to acknowledge the feminist critique and now has jobs like being the President, a scientist, and a doctor. )
(Clark University professor of philosophy Wiebke Deimling compared a scene in the film, in which Barbie has to make a choice between going back to her perfect life in Barbieland or learning the truth about her existence in the Real World, to the experience machine, a thought experiment by American philosopher Robert Nozick. )
(Diemling also observed that gender in Barbieland is performative, noting how the Kens behave before and after a patriarchy is established.Alissa Wilkinson of Vox compared Barbie land to the biblical Garden of Eden, with Barbie and Ken as inverted parallels of Adam and Eve. )
(She saw Barbie and Ken's first impression "that they're suddenly self-conscious and aware of being looked at" in the Real World as the film's version of the Fall. Chinese film critic Li Jingfei (李竞菲) compared Barbie's sudden awareness of death to the moment when Siddhārtha Gautama left the palace of his birth and first learned of suffering and death, which eventually led to his enlightenment. )
(Katie Pickles, said, Barbie shows how the matriarchy can be "as bad" as the patriarchy)
(Pickles, further comments, the true heroes were outcasts such as Weird Barbie and Allan)
(Pickles, believes, this aligns with Gerwig's conception of feminism)
(Jack Butler, argued, the film is instead a "post-feminist satire of what feminists imagine a perfect world looking like")
(Butler, noted, in the Real World, "Ken is rebuffed in all of his attempts to join the male hierarchy that purportedly dominates the world)
(Michelle Goldberg, explained, "beneath their slick, exuberant pop surfaces, [both the film and the tour] tell female coming-of-age stories marked by existential crises and bitter confrontations with sexism.")
(Ben Sisario, considered, both the works as critiques of patriarchy)
(Chris Willman, stated, both use patriarchy as a subject of irony "while being utterly friendly to and welcoming of men as much as anybody")
(Jean Guerrero, presented, a subtext to the film's feminist exterior, in which "a world that disregards men and their feelings is an inverted form of patriarchy and also cruel")
(Barbie, provides, portrayal of masculinity)
(Ken, turns to, patriarchal expression)
(Ken, tries to kiss her, sexual advance)
(Ken, mimics adolescence)
(Ken, embodies, idea of patriarchy)
(Ken, radicalization, resembles men's rights movement)
[]
[{'rel1': {'type': 'literal', 'value': 'was promoted with'}, 'obj1': {'type': 'literal', 'value': 'an extensive marketing campaign'}}, {'rel1': {'type': 'literal', 'value': 'entered into promotional partnerships with'}, 'obj1': {'type': 'literal', 'value': 'various brands'}}, {'rel1': {'type': 'literal', 'value': 'was coproduced by'}, 'obj1': {'type': 'literal', 'value': 'Mattel Television'}}, {'rel1': {'type': 'literal', 'value': 'was revealed during'}, 'obj1': {'type': 'literal', 'value': 'Warner Bros. presentation'}}, {'rel1': {'type': 'literal', 'value': 'was opened at'}, 'obj1': {'type': 'literal', 'value': 'CCXP event'}}, {'rel1': {'type': 'literal', 'value': 'debuted during'}, 'obj1': {'type': 'literal', 'value': 'Avatar: The Way of Water'}}, {'rel1': {'type': 'literal', 'value': 'had world premiere at'}, 'obj1': {'type': 'literal', 'value': 'Shrine Auditorium'}}, {'rel1': {'type': 'literal', 'value': 'had European premiere at'}, 'obj1': {'type': 'literal', 'value': 'Cineworld Leicester Square'}}, {'rel1': {'type': 'literal', 'value': 'was released theatrically in'}, 'obj1': {'type': 'literal', 'value': 'United States'}}, {'rel1': {'type': 'literal', 'value': 'was released theatrically in'}, 'obj1': {'type': 'literal', 'value': 'United Kingdom'}}, {'rel1': {'type': 'literal', 'value': 'was released on same day as'}, 'obj1': {'type': 'literal', 'value': 'Oppenheimer'}}, {'rel1': {'type': 'literal', 'value': 'will be re-released in'}, 'obj1': {'type': 'literal', 'value': 'IMAX theaters'}}, {'rel1': {'type': 'literal', 'value': 'was released on digital download on'}, 'obj1': {'type': 'literal', 'value': 'September 12'}}, {'rel1': {'type': 'literal', 'value': 'will be released on Ultra HD Blu-ray on'}, 'obj1': {'type': 'literal', 'value': 'October 17'}}, {'rel1': {'type': 'literal', 'value': 'will be released on Blu-ray on'}, 'obj1': {'type': 'literal', 'value': 'October 17'}}, {'rel1': {'type': 'literal', 'value': 'will be released on DVD on'}, 'obj1': {'type': 'literal', 'value': 'October 17'}}, {'rel1': {'type': 'literal', 'value': 'would be banned'}, 'obj1': {'type': 'literal', 'value': 'because it contained "the offending image of the nine-dash line."'}}, {'rel1': {'type': 'literal', 'value': 'was released in'}, 'obj1': {'type': 'literal', 'value': 'Middle East'}}, {'rel1': {'type': 'literal', 'value': 'was released in'}, 'obj1': {'type': 'literal', 'value': 'Algeria'}}, {'rel1': {'type': 'literal', 'value': 'was released in'}, 'obj1': {'type': 'literal', 'value': 'Lebanon'}}, {'rel1': {'type': 'literal', 'value': 'was released in'}, 'obj1': {'type': 'literal', 'value': 'Kuwait'}}, {'rel1': {'type': 'literal', 'value': 'promotes'}, 'obj1': {'type': 'literal', 'value': 'homosexuality'}}, {'rel1': {'type': 'literal', 'value': 'promotes'}, 'obj1': {'type': 'literal', 'value': 'Western deviances'}}, {'rel1': {'type': 'literal', 'value': 'does not comply with'}, 'obj1': {'type': 'literal', 'value': "Algeria's religious and cultural beliefs"}}, {'rel1': {'type': 'literal', 'value': 'grossed'}, 'obj1': {'type': 'literal', 'value': '$634.5 million'}}, {'rel1': {'type': 'literal', 'value': 'became'}, 'obj1': {'type': 'literal', 'value': 'highest-grossing live-action comedy film'}}, {'rel1': {'type': 'literal', 'value': 'set the record for'}, 'obj1': {'type': 'literal', 'value': 'any film that was not a sequel'}}, {'rel1': {'type': 'literal', 'value': 'smashed the domestic record'}, 'obj1': {'type': 'literal', 'value': 'formerly held by Home Alone'}}, {'rel1': {'type': 'literal', 'value': 'replaced The Super Mario Bros. Movie'}, 'obj1': {'type': 'literal', 'value': 'as the highest-grossing film of the year'}}, {'rel1': {'type': 'literal', 'value': 'scored'}, 'obj1': {'type': 'literal', 'value': 'biggest opening'}}, {'rel1': {'type': 'literal', 'value': 'surpassed'}, 'obj1': {'type': 'literal', 'value': 'Suicide Squad'}}, {'rel1': {'type': 'literal', 'value': 'dethroned'}, 'obj1': {'type': 'literal', 'value': 'The Secret Life of Pets'}}, {'rel1': {'type': 'literal', 'value': 'quickly beat'}, 'obj1': {'type': 'literal', 'value': 'La La Land'}}, {'rel1': {'type': 'literal', 'value': 'became'}, 'obj1': {'type': 'literal', 'value': 'highest-grossing film'}}, {'rel1': {'type': 'literal', 'value': 'finished in second place'}, 'obj1': {'type': 'literal', 'value': 'Gran Turismo'}}, {'rel1': {'type': 'literal', 'value': 'finished in'}, 'obj1': {'type': 'literal', 'value': 'second place'}}, {'rel1': {'type': 'literal', 'value': 'opened with'}, 'obj1': {'type': 'literal', 'value': '$24.2 million'}}, {'rel1': {'type': 'literal', 'value': 'became'}, 'obj1': {'type': 'literal', 'value': 'largest second week'}}, {'rel1': {'type': 'literal', 'value': 'grossed'}, 'obj1': {'type': 'literal', 'value': '$74 million'}}, {'rel1': {'type': 'literal', 'value': 'finished'}, 'obj1': {'type': 'literal', 'value': 'fifth place'}}, {'rel1': {'type': 'literal', 'value': 'fell behind'}, 'obj1': {'type': 'literal', 'value': 'Smugglers'}}, {'rel1': {'type': 'literal', 'value': 'suggested'}, 'obj1': {'type': 'literal', 'value': 'lack of popularity'}}, {'rel1': {'type': 'literal', 'value': 'contributed'}, 'obj1': {'type': 'literal', 'value': 'under-performance'}}, {'rel1': {'type': 'literal', 'value': 'preached'}, 'obj1': {'type': 'literal', 'value': 'sexual discrimination'}}, {'rel1': {'type': 'literal', 'value': 'criticized'}, 'obj1': {'type': 'literal', 'value': 'negligence'}}, {'rel1': {'type': 'literal', 'value': 'attained'}, 'obj1': {'type': 'literal', 'value': 'critical acclaim'}}, {'rel1': {'type': 'literal', 'value': 'praised'}, 'obj1': {'type': 'literal', 'value': 'script'}}, {'rel1': {'type': 'literal', 'value': 'is'}, 'obj1': {'type': 'literal', 'value': 'visually dazzling comedy'}}, {'rel1': {'type': 'literal', 'value': 'has'}, 'obj1': {'type': 'literal', 'value': 'meta humor'}}, {'rel1': {'type': 'literal', 'value': 'is'}, 'obj1': {'type': 'literal', 'value': 'product'}}, {'rel1': {'type': 'literal', 'value': 'is'}, 'obj1': {'type': 'literal', 'value': 'legacy'}}, {'rel1': {'type': 'literal', 'value': 'explores themes of'}, 'obj1': {'type': 'literal', 'value': 'existentialism'}}, {'rel1': {'type': 'literal', 'value': 'is a satire that'}, 'obj1': {'type': 'literal', 'value': 'pokes fun at capitalism'}}, {'rel1': {'type': 'literal', 'value': 'is a satire that'}, 'obj1': {'type': 'literal', 'value': 'cleverly uses capitalist themes'}}, {'rel1': {'type': 'literal', 'value': 'ruminates on'}, 'obj1': {'type': 'literal', 'value': 'the very idea of what makes us human'}}, {'rel1': {'type': 'literal', 'value': 'ruminates on'}, 'obj1': {'type': 'literal', 'value': "the idea of 'the other'"}}, {'rel1': {'type': 'literal', 'value': 'provides'}, 'obj1': {'type': 'literal', 'value': 'portrayal of masculinity'}}, {'rel1': {'type': 'literal', 'value': 'is'}, 'obj1': {'type': 'literal', 'value': '2023 American fantasy comedy film'}}, {'rel1': {'type': 'literal', 'value': 'directed by'}, 'obj1': {'type': 'literal', 'value': 'Greta Gerwig'}}, {'rel1': {'type': 'literal', 'value': 'stars'}, 'obj1': {'type': 'literal', 'value': 'Margot Robbie'}}, {'rel1': {'type': 'literal', 'value': 'follows'}, 'obj1': {'type': 'literal', 'value': 'the pair'}}, {'rel1': {'type': 'literal', 'value': 'on a journey of'}, 'obj1': {'type': 'literal', 'value': 'self-discovery'}}, {'rel1': {'type': 'literal', 'value': 'after'}, 'obj1': {'type': 'literal', 'value': 'multiple writer and director changes'}}, {'rel1': {'type': 'literal', 'value': 'in England and at'}, 'obj1': {'type': 'literal', 'value': 'the Venice Beach Skatepark'}}, {'rel1': {'type': 'literal', 'value': 'in Los Angeles from'}, 'obj1': {'type': 'literal', 'value': 'March to July'}}, {'rel1': {'type': 'literal', 'value': 'received'}, 'obj1': {'type': 'literal', 'value': 'critical acclaim'}}, {'rel1': {'type': 'literal', 'value': 'rebuffs'}, 'obj1': {'type': 'literal', 'value': 'Beach Ken'}}, {'rel1': {'type': 'literal', 'value': 'develops'}, 'obj1': {'type': 'literal', 'value': 'bad breath'}}, {'rel1': {'type': 'literal', 'value': 'develops'}, 'obj1': {'type': 'literal', 'value': 'cellulite'}}, {'rel1': {'type': 'literal', 'value': 'develops'}, 'obj1': {'type': 'literal', 'value': 'flat feet'}}, {'rel1': {'type': 'literal', 'value': 'punches'}, 'obj1': {'type': 'literal', 'value': 'man'}}, {'rel1': {'type': 'literal', 'value': 'and Ken'}, 'obj1': {'type': 'literal', 'value': 'arrested'}}, {'rel1': {'type': 'literal', 'value': 'tracks down'}, 'obj1': {'type': 'literal', 'value': 'her owner'}}, {'rel1': {'type': 'literal', 'value': 'criticized for'}, 'obj1': {'type': 'literal', 'value': 'encouraging unrealistic beauty standards'}}, {'rel1': {'type': 'literal', 'value': 'escapes'}, 'obj1': {'type': 'literal', 'value': "with Gloria and Sasha's help"}}, {'rel1': {'type': 'literal', 'value': 'unsuccessfully tries'}, 'obj1': {'type': 'literal', 'value': 'to convince Ken and the other Barbies to return'}}, {'rel1': {'type': 'literal', 'value': 'becomes'}, 'obj1': {'type': 'literal', 'value': 'depressed'}}, {'rel1': {'type': 'literal', 'value': 'restored'}, 'obj1': {'type': 'literal', 'value': 'self-confidence'}}, {'rel1': {'type': 'literal', 'value': 'has'}, 'obj1': {'type': 'literal', 'value': 'no set ending'}}, {'rel1': {'type': 'literal', 'value': 'meets with'}, 'obj1': {'type': 'literal', 'value': 'Ruth Handler'}}, {'rel1': {'type': 'literal', 'value': 'meets with'}, 'obj1': {'type': 'literal', 'value': 'Mattel co-founder'}}, {'rel1': {'type': 'literal', 'value': 'meets with'}, 'obj1': {'type': 'literal', 'value': 'creator of Barbie doll'}}, {'rel1': {'type': 'literal', 'value': 'decides to become'}, 'obj1': {'type': 'literal', 'value': 'human'}}, {'rel1': {'type': 'literal', 'value': 'decides to become'}, 'obj1': {'type': 'literal', 'value': 'return to the real world'}}, {'rel1': {'type': 'literal', 'value': 'desires'}, 'obj1': {'type': 'literal', 'value': 'to be more than just a plastic doll'}}, {'rel1': {'type': 'literal', 'value': 'being "constrained in multitudes"'}, 'obj1': {'type': 'literal', 'value': 'as "all of these women are Barbie and Barbie is all of these women"'}}, {'rel1': {'type': 'literal', 'value': 'living in'}, 'obj1': {'type': 'literal', 'value': 'utopia'}}, {'rel1': {'type': 'literal', 'value': 'facing'}, 'obj1': {'type': 'literal', 'value': 'the real world'}}, {'rel1': {'type': 'literal', 'value': 'learns that'}, 'obj1': {'type': 'literal', 'value': 'some women do not like her'}}, {'rel1': {'type': 'literal', 'value': 'is being stared at inappropriately'}, 'obj1': {'type': 'literal', 'value': 'Venice Beach'}}]
[]


In the movie, Barbie thinks about becoming human and living in the real world. She also thinks about the idea of "the other" and what it means to be human.
>>> response_graph_rag = kg_rag_query_engine.query("Who is Barbie")
[]
[{'rel1': {'type': 'literal', 'value': 'was promoted with'}, 'obj1': {'type': 'literal', 'value': 'an extensive marketing campaign'}}, {'rel1': {'type': 'literal', 'value': 'entered into promotional partnerships with'}, 'obj1': {'type': 'literal', 'value': 'various brands'}}, {'rel1': {'type': 'literal', 'value': 'was coproduced by'}, 'obj1': {'type': 'literal', 'value': 'Mattel Television'}}, {'rel1': {'type': 'literal', 'value': 'was revealed during'}, 'obj1': {'type': 'literal', 'value': 'Warner Bros. presentation'}}, {'rel1': {'type': 'literal', 'value': 'was opened at'}, 'obj1': {'type': 'literal', 'value': 'CCXP event'}}, {'rel1': {'type': 'literal', 'value': 'debuted during'}, 'obj1': {'type': 'literal', 'value': 'Avatar: The Way of Water'}}, {'rel1': {'type': 'literal', 'value': 'had world premiere at'}, 'obj1': {'type': 'literal', 'value': 'Shrine Auditorium'}}, {'rel1': {'type': 'literal', 'value': 'had European premiere at'}, 'obj1': {'type': 'literal', 'value': 'Cineworld Leicester Square'}}, {'rel1': {'type': 'literal', 'value': 'was released theatrically in'}, 'obj1': {'type': 'literal', 'value': 'United States'}}, {'rel1': {'type': 'literal', 'value': 'was released theatrically in'}, 'obj1': {'type': 'literal', 'value': 'United Kingdom'}}, {'rel1': {'type': 'literal', 'value': 'was released on same day as'}, 'obj1': {'type': 'literal', 'value': 'Oppenheimer'}}, {'rel1': {'type': 'literal', 'value': 'will be re-released in'}, 'obj1': {'type': 'literal', 'value': 'IMAX theaters'}}, {'rel1': {'type': 'literal', 'value': 'was released on digital download on'}, 'obj1': {'type': 'literal', 'value': 'September 12'}}, {'rel1': {'type': 'literal', 'value': 'will be released on Ultra HD Blu-ray on'}, 'obj1': {'type': 'literal', 'value': 'October 17'}}, {'rel1': {'type': 'literal', 'value': 'will be released on Blu-ray on'}, 'obj1': {'type': 'literal', 'value': 'October 17'}}, {'rel1': {'type': 'literal', 'value': 'will be released on DVD on'}, 'obj1': {'type': 'literal', 'value': 'October 17'}}, {'rel1': {'type': 'literal', 'value': 'would be banned'}, 'obj1': {'type': 'literal', 'value': 'because it contained "the offending image of the nine-dash line."'}}, {'rel1': {'type': 'literal', 'value': 'was released in'}, 'obj1': {'type': 'literal', 'value': 'Middle East'}}, {'rel1': {'type': 'literal', 'value': 'was released in'}, 'obj1': {'type': 'literal', 'value': 'Algeria'}}, {'rel1': {'type': 'literal', 'value': 'was released in'}, 'obj1': {'type': 'literal', 'value': 'Lebanon'}}, {'rel1': {'type': 'literal', 'value': 'was released in'}, 'obj1': {'type': 'literal', 'value': 'Kuwait'}}, {'rel1': {'type': 'literal', 'value': 'promotes'}, 'obj1': {'type': 'literal', 'value': 'homosexuality'}}, {'rel1': {'type': 'literal', 'value': 'promotes'}, 'obj1': {'type': 'literal', 'value': 'Western deviances'}}, {'rel1': {'type': 'literal', 'value': 'does not comply with'}, 'obj1': {'type': 'literal', 'value': "Algeria's religious and cultural beliefs"}}, {'rel1': {'type': 'literal', 'value': 'grossed'}, 'obj1': {'type': 'literal', 'value': '$634.5 million'}}, {'rel1': {'type': 'literal', 'value': 'became'}, 'obj1': {'type': 'literal', 'value': 'highest-grossing live-action comedy film'}}, {'rel1': {'type': 'literal', 'value': 'set the record for'}, 'obj1': {'type': 'literal', 'value': 'any film that was not a sequel'}}, {'rel1': {'type': 'literal', 'value': 'smashed the domestic record'}, 'obj1': {'type': 'literal', 'value': 'formerly held by Home Alone'}}, {'rel1': {'type': 'literal', 'value': 'replaced The Super Mario Bros. Movie'}, 'obj1': {'type': 'literal', 'value': 'as the highest-grossing film of the year'}}, {'rel1': {'type': 'literal', 'value': 'scored'}, 'obj1': {'type': 'literal', 'value': 'biggest opening'}}, {'rel1': {'type': 'literal', 'value': 'surpassed'}, 'obj1': {'type': 'literal', 'value': 'Suicide Squad'}}, {'rel1': {'type': 'literal', 'value': 'dethroned'}, 'obj1': {'type': 'literal', 'value': 'The Secret Life of Pets'}}, {'rel1': {'type': 'literal', 'value': 'quickly beat'}, 'obj1': {'type': 'literal', 'value': 'La La Land'}}, {'rel1': {'type': 'literal', 'value': 'became'}, 'obj1': {'type': 'literal', 'value': 'highest-grossing film'}}, {'rel1': {'type': 'literal', 'value': 'finished in second place'}, 'obj1': {'type': 'literal', 'value': 'Gran Turismo'}}, {'rel1': {'type': 'literal', 'value': 'finished in'}, 'obj1': {'type': 'literal', 'value': 'second place'}}, {'rel1': {'type': 'literal', 'value': 'opened with'}, 'obj1': {'type': 'literal', 'value': '$24.2 million'}}, {'rel1': {'type': 'literal', 'value': 'became'}, 'obj1': {'type': 'literal', 'value': 'largest second week'}}, {'rel1': {'type': 'literal', 'value': 'grossed'}, 'obj1': {'type': 'literal', 'value': '$74 million'}}, {'rel1': {'type': 'literal', 'value': 'finished'}, 'obj1': {'type': 'literal', 'value': 'fifth place'}}, {'rel1': {'type': 'literal', 'value': 'fell behind'}, 'obj1': {'type': 'literal', 'value': 'Smugglers'}}, {'rel1': {'type': 'literal', 'value': 'suggested'}, 'obj1': {'type': 'literal', 'value': 'lack of popularity'}}, {'rel1': {'type': 'literal', 'value': 'contributed'}, 'obj1': {'type': 'literal', 'value': 'under-performance'}}, {'rel1': {'type': 'literal', 'value': 'preached'}, 'obj1': {'type': 'literal', 'value': 'sexual discrimination'}}, {'rel1': {'type': 'literal', 'value': 'criticized'}, 'obj1': {'type': 'literal', 'value': 'negligence'}}, {'rel1': {'type': 'literal', 'value': 'attained'}, 'obj1': {'type': 'literal', 'value': 'critical acclaim'}}, {'rel1': {'type': 'literal', 'value': 'praised'}, 'obj1': {'type': 'literal', 'value': 'script'}}, {'rel1': {'type': 'literal', 'value': 'is'}, 'obj1': {'type': 'literal', 'value': 'visually dazzling comedy'}}, {'rel1': {'type': 'literal', 'value': 'has'}, 'obj1': {'type': 'literal', 'value': 'meta humor'}}, {'rel1': {'type': 'literal', 'value': 'is'}, 'obj1': {'type': 'literal', 'value': 'product'}}, {'rel1': {'type': 'literal', 'value': 'is'}, 'obj1': {'type': 'literal', 'value': 'legacy'}}, {'rel1': {'type': 'literal', 'value': 'explores themes of'}, 'obj1': {'type': 'literal', 'value': 'existentialism'}}, {'rel1': {'type': 'literal', 'value': 'is a satire that'}, 'obj1': {'type': 'literal', 'value': 'pokes fun at capitalism'}}, {'rel1': {'type': 'literal', 'value': 'is a satire that'}, 'obj1': {'type': 'literal', 'value': 'cleverly uses capitalist themes'}}, {'rel1': {'type': 'literal', 'value': 'ruminates on'}, 'obj1': {'type': 'literal', 'value': 'the very idea of what makes us human'}}, {'rel1': {'type': 'literal', 'value': 'ruminates on'}, 'obj1': {'type': 'literal', 'value': "the idea of 'the other'"}}, {'rel1': {'type': 'literal', 'value': 'provides'}, 'obj1': {'type': 'literal', 'value': 'portrayal of masculinity'}}, {'rel1': {'type': 'literal', 'value': 'is'}, 'obj1': {'type': 'literal', 'value': '2023 American fantasy comedy film'}}, {'rel1': {'type': 'literal', 'value': 'directed by'}, 'obj1': {'type': 'literal', 'value': 'Greta Gerwig'}}, {'rel1': {'type': 'literal', 'value': 'stars'}, 'obj1': {'type': 'literal', 'value': 'Margot Robbie'}}, {'rel1': {'type': 'literal', 'value': 'follows'}, 'obj1': {'type': 'literal', 'value': 'the pair'}}, {'rel1': {'type': 'literal', 'value': 'on a journey of'}, 'obj1': {'type': 'literal', 'value': 'self-discovery'}}, {'rel1': {'type': 'literal', 'value': 'after'}, 'obj1': {'type': 'literal', 'value': 'multiple writer and director changes'}}, {'rel1': {'type': 'literal', 'value': 'in England and at'}, 'obj1': {'type': 'literal', 'value': 'the Venice Beach Skatepark'}}, {'rel1': {'type': 'literal', 'value': 'in Los Angeles from'}, 'obj1': {'type': 'literal', 'value': 'March to July'}}, {'rel1': {'type': 'literal', 'value': 'received'}, 'obj1': {'type': 'literal', 'value': 'critical acclaim'}}, {'rel1': {'type': 'literal', 'value': 'rebuffs'}, 'obj1': {'type': 'literal', 'value': 'Beach Ken'}}, {'rel1': {'type': 'literal', 'value': 'develops'}, 'obj1': {'type': 'literal', 'value': 'bad breath'}}, {'rel1': {'type': 'literal', 'value': 'develops'}, 'obj1': {'type': 'literal', 'value': 'cellulite'}}, {'rel1': {'type': 'literal', 'value': 'develops'}, 'obj1': {'type': 'literal', 'value': 'flat feet'}}, {'rel1': {'type': 'literal', 'value': 'punches'}, 'obj1': {'type': 'literal', 'value': 'man'}}, {'rel1': {'type': 'literal', 'value': 'and Ken'}, 'obj1': {'type': 'literal', 'value': 'arrested'}}, {'rel1': {'type': 'literal', 'value': 'tracks down'}, 'obj1': {'type': 'literal', 'value': 'her owner'}}, {'rel1': {'type': 'literal', 'value': 'criticized for'}, 'obj1': {'type': 'literal', 'value': 'encouraging unrealistic beauty standards'}}, {'rel1': {'type': 'literal', 'value': 'escapes'}, 'obj1': {'type': 'literal', 'value': "with Gloria and Sasha's help"}}, {'rel1': {'type': 'literal', 'value': 'unsuccessfully tries'}, 'obj1': {'type': 'literal', 'value': 'to convince Ken and the other Barbies to return'}}, {'rel1': {'type': 'literal', 'value': 'becomes'}, 'obj1': {'type': 'literal', 'value': 'depressed'}}, {'rel1': {'type': 'literal', 'value': 'restored'}, 'obj1': {'type': 'literal', 'value': 'self-confidence'}}, {'rel1': {'type': 'literal', 'value': 'has'}, 'obj1': {'type': 'literal', 'value': 'no set ending'}}, {'rel1': {'type': 'literal', 'value': 'meets with'}, 'obj1': {'type': 'literal', 'value': 'Ruth Handler'}}, {'rel1': {'type': 'literal', 'value': 'meets with'}, 'obj1': {'type': 'literal', 'value': 'Mattel co-founder'}}, {'rel1': {'type': 'literal', 'value': 'meets with'}, 'obj1': {'type': 'literal', 'value': 'creator of Barbie doll'}}, {'rel1': {'type': 'literal', 'value': 'decides to become'}, 'obj1': {'type': 'literal', 'value': 'human'}}, {'rel1': {'type': 'literal', 'value': 'decides to become'}, 'obj1': {'type': 'literal', 'value': 'return to the real world'}}, {'rel1': {'type': 'literal', 'value': 'desires'}, 'obj1': {'type': 'literal', 'value': 'to be more than just a plastic doll'}}, {'rel1': {'type': 'literal', 'value': 'being "constrained in multitudes"'}, 'obj1': {'type': 'literal', 'value': 'as "all of these women are Barbie and Barbie is all of these women"'}}, {'rel1': {'type': 'literal', 'value': 'living in'}, 'obj1': {'type': 'literal', 'value': 'utopia'}}, {'rel1': {'type': 'literal', 'value': 'facing'}, 'obj1': {'type': 'literal', 'value': 'the real world'}}, {'rel1': {'type': 'literal', 'value': 'learns that'}, 'obj1': {'type': 'literal', 'value': 'some women do not like her'}}, {'rel1': {'type': 'literal', 'value': 'is being stared at inappropriately'}, 'obj1': {'type': 'literal', 'value': 'Venice Beach'}}]
[]
>>> print(str(response_graph_rag))


Barbie is a 2023 American fantasy comedy film directed by Greta Gerwig and starring Margot Robbie. The film follows the pair on a journey of self-discovery after multiple writer and director changes.
>>>

Here’s look at the indexing data generated by this script from the Wikipedia document import.

$ ls -l llama_storage_graph/
total 14520
-rw-r--r--  1 hwilliams  staff    98171 12 Oct 22:28 docstore.json
-rw-r--r--  1 hwilliams  staff  7331607 12 Oct 22:28 index_store.json
-rw-r--r--  1 hwilliams  staff       72 12 Oct 22:28 vector_store.json

Wikipedia Dataset Interactions using RAG

  1. Run Python to get a command prompt:
python 
  1. Execute the llama_test2.py program, which just asks question and provided response to against the loaded RAG dataset with the command:
exec(open('llama_test2.py').read())
  1. On successful load of the data a question can be asked with the python command
response_graph_rag = kg_rag_query_engine.query("[question text]")
  1. Display response/answer to the question with the command:
print(str(response_graph_rag))

Sample Session Output from running the`llama_test2.py program

$ python3
Python 3.11.5 (main, Aug 24 2023, 15:09:45) [Clang 14.0.3 (clang-1403.0.22.14.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> exec(open('llama_test2.py').read())
[{'rel1': {'type': 'literal', 'value': 'turns to'}, 'obj1': {'type': 'literal', 'value': 'patriarchal expression'}}, {'rel1': {'type': 'literal', 'value': 'tries to kiss her'}, 'obj1': {'type': 'literal', 'value': 'sexual advance'}}, {'rel1': {'type': 'literal', 'value': 'embodies'}, 'obj1': {'type': 'literal', 'value': 'idea of patriarchy'}}, {'rel1': {'type': 'literal', 'value': 'radicalization'}, 'obj1': {'type': 'literal', 'value': "resembles men's rights movement"}}, {'rel1': {'type': 'literal', 'value': 'stows away'}, 'obj1': {'type': 'literal', 'value': 'in her convertible'}}, {'rel1': {'type': 'literal', 'value': 'learns about'}, 'obj1': {'type': 'literal', 'value': 'the patriarchal system'}}, {'rel1': {'type': 'literal', 'value': 'persuades'}, 'obj1': {'type': 'literal', 'value': 'the other Kens to take over'}}]
[]
[]


In the movie, Ken thinks about the patriarchal system and how it affects him and other men. He also thinks about how he can take over and change the system to benefit men more.
>>> response_graph_rag = kg_rag_query_engine.query("How old is Barbie?")
[]
[{'rel1': {'type': 'literal', 'value': 'was promoted with'}, 'obj1': {'type': 'literal', 'value': 'an extensive marketing campaign'}}, {'rel1': {'type': 'literal', 'value': 'entered into promotional partnerships with'}, 'obj1': {'type': 'literal', 'value': 'various brands'}}, {'rel1': {'type': 'literal', 'value': 'was coproduced by'}, 'obj1': {'type': 'literal', 'value': 'Mattel Television'}}, {'rel1': {'type': 'literal', 'value': 'was revealed during'}, 'obj1': {'type': 'literal', 'value': 'Warner Bros. presentation'}}, {'rel1': {'type': 'literal', 'value': 'was opened at'}, 'obj1': {'type': 'literal', 'value': 'CCXP event'}}, {'rel1': {'type': 'literal', 'value': 'debuted during'}, 'obj1': {'type': 'literal', 'value': 'Avatar: The Way of Water'}}, {'rel1': {'type': 'literal', 'value': 'had world premiere at'}, 'obj1': {'type': 'literal', 'value': 'Shrine Auditorium'}}, {'rel1': {'type': 'literal', 'value': 'had European premiere at'}, 'obj1': {'type': 'literal', 'value': 'Cineworld Leicester Square'}}, {'rel1': {'type': 'literal', 'value': 'was released theatrically in'}, 'obj1': {'type': 'literal', 'value': 'United States'}}, {'rel1': {'type': 'literal', 'value': 'was released theatrically in'}, 'obj1': {'type': 'literal', 'value': 'United Kingdom'}}, {'rel1': {'type': 'literal', 'value': 'was released on same day as'}, 'obj1': {'type': 'literal', 'value': 'Oppenheimer'}}, {'rel1': {'type': 'literal', 'value': 'will be re-released in'}, 'obj1': {'type': 'literal', 'value': 'IMAX theaters'}}, {'rel1': {'type': 'literal', 'value': 'was released on digital download on'}, 'obj1': {'type': 'literal', 'value': 'September 12'}}, {'rel1': {'type': 'literal', 'value': 'will be released on Ultra HD Blu-ray on'}, 'obj1': {'type': 'literal', 'value': 'October 17'}}, {'rel1': {'type': 'literal', 'value': 'will be released on Blu-ray on'}, 'obj1': {'type': 'literal', 'value': 'October 17'}}, {'rel1': {'type': 'literal', 'value': 'will be released on DVD on'}, 'obj1': {'type': 'literal', 'value': 'October 17'}}, {'rel1': {'type': 'literal', 'value': 'would be banned'}, 'obj1': {'type': 'literal', 'value': 'because it contained "the offending image of the nine-dash line."'}}, {'rel1': {'type': 'literal', 'value': 'was released in'}, 'obj1': {'type': 'literal', 'value': 'Middle East'}}, {'rel1': {'type': 'literal', 'value': 'was released in'}, 'obj1': {'type': 'literal', 'value': 'Algeria'}}, {'rel1': {'type': 'literal', 'value': 'was released in'}, 'obj1': {'type': 'literal', 'value': 'Lebanon'}}, {'rel1': {'type': 'literal', 'value': 'was released in'}, 'obj1': {'type': 'literal', 'value': 'Kuwait'}}, {'rel1': {'type': 'literal', 'value': 'promotes'}, 'obj1': {'type': 'literal', 'value': 'homosexuality'}}, {'rel1': {'type': 'literal', 'value': 'promotes'}, 'obj1': {'type': 'literal', 'value': 'Western deviances'}}, {'rel1': {'type': 'literal', 'value': 'does not comply with'}, 'obj1': {'type': 'literal', 'value': "Algeria's religious and cultural beliefs"}}, {'rel1': {'type': 'literal', 'value': 'grossed'}, 'obj1': {'type': 'literal', 'value': '$634.5 million'}}, {'rel1': {'type': 'literal', 'value': 'became'}, 'obj1': {'type': 'literal', 'value': 'highest-grossing live-action comedy film'}}, {'rel1': {'type': 'literal', 'value': 'set the record for'}, 'obj1': {'type': 'literal', 'value': 'any film that was not a sequel'}}, {'rel1': {'type': 'literal', 'value': 'smashed the domestic record'}, 'obj1': {'type': 'literal', 'value': 'formerly held by Home Alone'}}, {'rel1': {'type': 'literal', 'value': 'replaced The Super Mario Bros. Movie'}, 'obj1': {'type': 'literal', 'value': 'as the highest-grossing film of the year'}}, {'rel1': {'type': 'literal', 'value': 'scored'}, 'obj1': {'type': 'literal', 'value': 'biggest opening'}}, {'rel1': {'type': 'literal', 'value': 'surpassed'}, 'obj1': {'type': 'literal', 'value': 'Suicide Squad'}}, {'rel1': {'type': 'literal', 'value': 'dethroned'}, 'obj1': {'type': 'literal', 'value': 'The Secret Life of Pets'}}, {'rel1': {'type': 'literal', 'value': 'quickly beat'}, 'obj1': {'type': 'literal', 'value': 'La La Land'}}, {'rel1': {'type': 'literal', 'value': 'became'}, 'obj1': {'type': 'literal', 'value': 'highest-grossing film'}}, {'rel1': {'type': 'literal', 'value': 'finished in second place'}, 'obj1': {'type': 'literal', 'value': 'Gran Turismo'}}, {'rel1': {'type': 'literal', 'value': 'finished in'}, 'obj1': {'type': 'literal', 'value': 'second place'}}, {'rel1': {'type': 'literal', 'value': 'opened with'}, 'obj1': {'type': 'literal', 'value': '$24.2 million'}}, {'rel1': {'type': 'literal', 'value': 'became'}, 'obj1': {'type': 'literal', 'value': 'largest second week'}}, {'rel1': {'type': 'literal', 'value': 'grossed'}, 'obj1': {'type': 'literal', 'value': '$74 million'}}, {'rel1': {'type': 'literal', 'value': 'finished'}, 'obj1': {'type': 'literal', 'value': 'fifth place'}}, {'rel1': {'type': 'literal', 'value': 'fell behind'}, 'obj1': {'type': 'literal', 'value': 'Smugglers'}}, {'rel1': {'type': 'literal', 'value': 'suggested'}, 'obj1': {'type': 'literal', 'value': 'lack of popularity'}}, {'rel1': {'type': 'literal', 'value': 'contributed'}, 'obj1': {'type': 'literal', 'value': 'under-performance'}}, {'rel1': {'type': 'literal', 'value': 'preached'}, 'obj1': {'type': 'literal', 'value': 'sexual discrimination'}}, {'rel1': {'type': 'literal', 'value': 'criticized'}, 'obj1': {'type': 'literal', 'value': 'negligence'}}, {'rel1': {'type': 'literal', 'value': 'attained'}, 'obj1': {'type': 'literal', 'value': 'critical acclaim'}}, {'rel1': {'type': 'literal', 'value': 'praised'}, 'obj1': {'type': 'literal', 'value': 'script'}}, {'rel1': {'type': 'literal', 'value': 'is'}, 'obj1': {'type': 'literal', 'value': 'visually dazzling comedy'}}, {'rel1': {'type': 'literal', 'value': 'has'}, 'obj1': {'type': 'literal', 'value': 'meta humor'}}, {'rel1': {'type': 'literal', 'value': 'is'}, 'obj1': {'type': 'literal', 'value': 'product'}}, {'rel1': {'type': 'literal', 'value': 'is'}, 'obj1': {'type': 'literal', 'value': 'legacy'}}, {'rel1': {'type': 'literal', 'value': 'explores themes of'}, 'obj1': {'type': 'literal', 'value': 'existentialism'}}, {'rel1': {'type': 'literal', 'value': 'is a satire that'}, 'obj1': {'type': 'literal', 'value': 'pokes fun at capitalism'}}, {'rel1': {'type': 'literal', 'value': 'is a satire that'}, 'obj1': {'type': 'literal', 'value': 'cleverly uses capitalist themes'}}, {'rel1': {'type': 'literal', 'value': 'ruminates on'}, 'obj1': {'type': 'literal', 'value': 'the very idea of what makes us human'}}, {'rel1': {'type': 'literal', 'value': 'ruminates on'}, 'obj1': {'type': 'literal', 'value': "the idea of 'the other'"}}, {'rel1': {'type': 'literal', 'value': 'provides'}, 'obj1': {'type': 'literal', 'value': 'portrayal of masculinity'}}, {'rel1': {'type': 'literal', 'value': 'is'}, 'obj1': {'type': 'literal', 'value': '2023 American fantasy comedy film'}}, {'rel1': {'type': 'literal', 'value': 'directed by'}, 'obj1': {'type': 'literal', 'value': 'Greta Gerwig'}}, {'rel1': {'type': 'literal', 'value': 'stars'}, 'obj1': {'type': 'literal', 'value': 'Margot Robbie'}}, {'rel1': {'type': 'literal', 'value': 'follows'}, 'obj1': {'type': 'literal', 'value': 'the pair'}}, {'rel1': {'type': 'literal', 'value': 'on a journey of'}, 'obj1': {'type': 'literal', 'value': 'self-discovery'}}, {'rel1': {'type': 'literal', 'value': 'after'}, 'obj1': {'type': 'literal', 'value': 'multiple writer and director changes'}}, {'rel1': {'type': 'literal', 'value': 'in England and at'}, 'obj1': {'type': 'literal', 'value': 'the Venice Beach Skatepark'}}, {'rel1': {'type': 'literal', 'value': 'in Los Angeles from'}, 'obj1': {'type': 'literal', 'value': 'March to July'}}, {'rel1': {'type': 'literal', 'value': 'received'}, 'obj1': {'type': 'literal', 'value': 'critical acclaim'}}, {'rel1': {'type': 'literal', 'value': 'rebuffs'}, 'obj1': {'type': 'literal', 'value': 'Beach Ken'}}, {'rel1': {'type': 'literal', 'value': 'develops'}, 'obj1': {'type': 'literal', 'value': 'bad breath'}}, {'rel1': {'type': 'literal', 'value': 'develops'}, 'obj1': {'type': 'literal', 'value': 'cellulite'}}, {'rel1': {'type': 'literal', 'value': 'develops'}, 'obj1': {'type': 'literal', 'value': 'flat feet'}}, {'rel1': {'type': 'literal', 'value': 'punches'}, 'obj1': {'type': 'literal', 'value': 'man'}}, {'rel1': {'type': 'literal', 'value': 'and Ken'}, 'obj1': {'type': 'literal', 'value': 'arrested'}}, {'rel1': {'type': 'literal', 'value': 'tracks down'}, 'obj1': {'type': 'literal', 'value': 'her owner'}}, {'rel1': {'type': 'literal', 'value': 'criticized for'}, 'obj1': {'type': 'literal', 'value': 'encouraging unrealistic beauty standards'}}, {'rel1': {'type': 'literal', 'value': 'escapes'}, 'obj1': {'type': 'literal', 'value': "with Gloria and Sasha's help"}}, {'rel1': {'type': 'literal', 'value': 'unsuccessfully tries'}, 'obj1': {'type': 'literal', 'value': 'to convince Ken and the other Barbies to return'}}, {'rel1': {'type': 'literal', 'value': 'becomes'}, 'obj1': {'type': 'literal', 'value': 'depressed'}}, {'rel1': {'type': 'literal', 'value': 'restored'}, 'obj1': {'type': 'literal', 'value': 'self-confidence'}}, {'rel1': {'type': 'literal', 'value': 'has'}, 'obj1': {'type': 'literal', 'value': 'no set ending'}}, {'rel1': {'type': 'literal', 'value': 'meets with'}, 'obj1': {'type': 'literal', 'value': 'Ruth Handler'}}, {'rel1': {'type': 'literal', 'value': 'meets with'}, 'obj1': {'type': 'literal', 'value': 'Mattel co-founder'}}, {'rel1': {'type': 'literal', 'value': 'meets with'}, 'obj1': {'type': 'literal', 'value': 'creator of Barbie doll'}}, {'rel1': {'type': 'literal', 'value': 'decides to become'}, 'obj1': {'type': 'literal', 'value': 'human'}}, {'rel1': {'type': 'literal', 'value': 'decides to become'}, 'obj1': {'type': 'literal', 'value': 'return to the real world'}}, {'rel1': {'type': 'literal', 'value': 'desires'}, 'obj1': {'type': 'literal', 'value': 'to be more than just a plastic doll'}}, {'rel1': {'type': 'literal', 'value': 'being "constrained in multitudes"'}, 'obj1': {'type': 'literal', 'value': 'as "all of these women are Barbie and Barbie is all of these women"'}}, {'rel1': {'type': 'literal', 'value': 'living in'}, 'obj1': {'type': 'literal', 'value': 'utopia'}}, {'rel1': {'type': 'literal', 'value': 'facing'}, 'obj1': {'type': 'literal', 'value': 'the real world'}}, {'rel1': {'type': 'literal', 'value': 'learns that'}, 'obj1': {'type': 'literal', 'value': 'some women do not like her'}}, {'rel1': {'type': 'literal', 'value': 'is being stared at inappropriately'}, 'obj1': {'type': 'literal', 'value': 'Venice Beach'}}]
>>> print(str(response_graph_rag))


There is no definitive answer to this question as Barbie's age is not specified in the information provided. However, we can infer that Barbie is at least 20 years old, as the film she is starring in, Barbie: The Way of Water, is set to be released in 2023.
>>> response_graph_rag = kg_rag_query_engine.query("In what countries is Barbie released?")
[]
[]
[{'rel1': {'type': 'literal', 'value': 'was promoted with'}, 'obj1': {'type': 'literal', 'value': 'an extensive marketing campaign'}}, {'rel1': {'type': 'literal', 'value': 'entered into promotional partnerships with'}, 'obj1': {'type': 'literal', 'value': 'various brands'}}, {'rel1': {'type': 'literal', 'value': 'was coproduced by'}, 'obj1': {'type': 'literal', 'value': 'Mattel Television'}}, {'rel1': {'type': 'literal', 'value': 'was revealed during'}, 'obj1': {'type': 'literal', 'value': 'Warner Bros. presentation'}}, {'rel1': {'type': 'literal', 'value': 'was opened at'}, 'obj1': {'type': 'literal', 'value': 'CCXP event'}}, {'rel1': {'type': 'literal', 'value': 'debuted during'}, 'obj1': {'type': 'literal', 'value': 'Avatar: The Way of Water'}}, {'rel1': {'type': 'literal', 'value': 'had world premiere at'}, 'obj1': {'type': 'literal', 'value': 'Shrine Auditorium'}}, {'rel1': {'type': 'literal', 'value': 'had European premiere at'}, 'obj1': {'type': 'literal', 'value': 'Cineworld Leicester Square'}}, {'rel1': {'type': 'literal', 'value': 'was released theatrically in'}, 'obj1': {'type': 'literal', 'value': 'United States'}}, {'rel1': {'type': 'literal', 'value': 'was released theatrically in'}, 'obj1': {'type': 'literal', 'value': 'United Kingdom'}}, {'rel1': {'type': 'literal', 'value': 'was released on same day as'}, 'obj1': {'type': 'literal', 'value': 'Oppenheimer'}}, {'rel1': {'type': 'literal', 'value': 'will be re-released in'}, 'obj1': {'type': 'literal', 'value': 'IMAX theaters'}}, {'rel1': {'type': 'literal', 'value': 'was released on digital download on'}, 'obj1': {'type': 'literal', 'value': 'September 12'}}, {'rel1': {'type': 'literal', 'value': 'will be released on Ultra HD Blu-ray on'}, 'obj1': {'type': 'literal', 'value': 'October 17'}}, {'rel1': {'type': 'literal', 'value': 'will be released on Blu-ray on'}, 'obj1': {'type': 'literal', 'value': 'October 17'}}, {'rel1': {'type': 'literal', 'value': 'will be released on DVD on'}, 'obj1': {'type': 'literal', 'value': 'October 17'}}, {'rel1': {'type': 'literal', 'value': 'would be banned'}, 'obj1': {'type': 'literal', 'value': 'because it contained "the offending image of the nine-dash line."'}}, {'rel1': {'type': 'literal', 'value': 'was released in'}, 'obj1': {'type': 'literal', 'value': 'Middle East'}}, {'rel1': {'type': 'literal', 'value': 'was released in'}, 'obj1': {'type': 'literal', 'value': 'Algeria'}}, {'rel1': {'type': 'literal', 'value': 'was released in'}, 'obj1': {'type': 'literal', 'value': 'Lebanon'}}, {'rel1': {'type': 'literal', 'value': 'was released in'}, 'obj1': {'type': 'literal', 'value': 'Kuwait'}}, {'rel1': {'type': 'literal', 'value': 'promotes'}, 'obj1': {'type': 'literal', 'value': 'homosexuality'}}, {'rel1': {'type': 'literal', 'value': 'promotes'}, 'obj1': {'type': 'literal', 'value': 'Western deviances'}}, {'rel1': {'type': 'literal', 'value': 'does not comply with'}, 'obj1': {'type': 'literal', 'value': "Algeria's religious and cultural beliefs"}}, {'rel1': {'type': 'literal', 'value': 'grossed'}, 'obj1': {'type': 'literal', 'value': '$634.5 million'}}, {'rel1': {'type': 'literal', 'value': 'became'}, 'obj1': {'type': 'literal', 'value': 'highest-grossing live-action comedy film'}}, {'rel1': {'type': 'literal', 'value': 'set the record for'}, 'obj1': {'type': 'literal', 'value': 'any film that was not a sequel'}}, {'rel1': {'type': 'literal', 'value': 'smashed the domestic record'}, 'obj1': {'type': 'literal', 'value': 'formerly held by Home Alone'}}, {'rel1': {'type': 'literal', 'value': 'replaced The Super Mario Bros. Movie'}, 'obj1': {'type': 'literal', 'value': 'as the highest-grossing film of the year'}}, {'rel1': {'type': 'literal', 'value': 'scored'}, 'obj1': {'type': 'literal', 'value': 'biggest opening'}}, {'rel1': {'type': 'literal', 'value': 'surpassed'}, 'obj1': {'type': 'literal', 'value': 'Suicide Squad'}}, {'rel1': {'type': 'literal', 'value': 'dethroned'}, 'obj1': {'type': 'literal', 'value': 'The Secret Life of Pets'}}, {'rel1': {'type': 'literal', 'value': 'quickly beat'}, 'obj1': {'type': 'literal', 'value': 'La La Land'}}, {'rel1': {'type': 'literal', 'value': 'became'}, 'obj1': {'type': 'literal', 'value': 'highest-grossing film'}}, {'rel1': {'type': 'literal', 'value': 'finished in second place'}, 'obj1': {'type': 'literal', 'value': 'Gran Turismo'}}, {'rel1': {'type': 'literal', 'value': 'finished in'}, 'obj1': {'type': 'literal', 'value': 'second place'}}, {'rel1': {'type': 'literal', 'value': 'opened with'}, 'obj1': {'type': 'literal', 'value': '$24.2 million'}}, {'rel1': {'type': 'literal', 'value': 'became'}, 'obj1': {'type': 'literal', 'value': 'largest second week'}}, {'rel1': {'type': 'literal', 'value': 'grossed'}, 'obj1': {'type': 'literal', 'value': '$74 million'}}, {'rel1': {'type': 'literal', 'value': 'finished'}, 'obj1': {'type': 'literal', 'value': 'fifth place'}}, {'rel1': {'type': 'literal', 'value': 'fell behind'}, 'obj1': {'type': 'literal', 'value': 'Smugglers'}}, {'rel1': {'type': 'literal', 'value': 'suggested'}, 'obj1': {'type': 'literal', 'value': 'lack of popularity'}}, {'rel1': {'type': 'literal', 'value': 'contributed'}, 'obj1': {'type': 'literal', 'value': 'under-performance'}}, {'rel1': {'type': 'literal', 'value': 'preached'}, 'obj1': {'type': 'literal', 'value': 'sexual discrimination'}}, {'rel1': {'type': 'literal', 'value': 'criticized'}, 'obj1': {'type': 'literal', 'value': 'negligence'}}, {'rel1': {'type': 'literal', 'value': 'attained'}, 'obj1': {'type': 'literal', 'value': 'critical acclaim'}}, {'rel1': {'type': 'literal', 'value': 'praised'}, 'obj1': {'type': 'literal', 'value': 'script'}}, {'rel1': {'type': 'literal', 'value': 'is'}, 'obj1': {'type': 'literal', 'value': 'visually dazzling comedy'}}, {'rel1': {'type': 'literal', 'value': 'has'}, 'obj1': {'type': 'literal', 'value': 'meta humor'}}, {'rel1': {'type': 'literal', 'value': 'is'}, 'obj1': {'type': 'literal', 'value': 'product'}}, {'rel1': {'type': 'literal', 'value': 'is'}, 'obj1': {'type': 'literal', 'value': 'legacy'}}, {'rel1': {'type': 'literal', 'value': 'explores themes of'}, 'obj1': {'type': 'literal', 'value': 'existentialism'}}, {'rel1': {'type': 'literal', 'value': 'is a satire that'}, 'obj1': {'type': 'literal', 'value': 'pokes fun at capitalism'}}, {'rel1': {'type': 'literal', 'value': 'is a satire that'}, 'obj1': {'type': 'literal', 'value': 'cleverly uses capitalist themes'}}, {'rel1': {'type': 'literal', 'value': 'ruminates on'}, 'obj1': {'type': 'literal', 'value': 'the very idea of what makes us human'}}, {'rel1': {'type': 'literal', 'value': 'ruminates on'}, 'obj1': {'type': 'literal', 'value': "the idea of 'the other'"}}, {'rel1': {'type': 'literal', 'value': 'provides'}, 'obj1': {'type': 'literal', 'value': 'portrayal of masculinity'}}, {'rel1': {'type': 'literal', 'value': 'is'}, 'obj1': {'type': 'literal', 'value': '2023 American fantasy comedy film'}}, {'rel1': {'type': 'literal', 'value': 'directed by'}, 'obj1': {'type': 'literal', 'value': 'Greta Gerwig'}}, {'rel1': {'type': 'literal', 'value': 'stars'}, 'obj1': {'type': 'literal', 'value': 'Margot Robbie'}}, {'rel1': {'type': 'literal', 'value': 'follows'}, 'obj1': {'type': 'literal', 'value': 'the pair'}}, {'rel1': {'type': 'literal', 'value': 'on a journey of'}, 'obj1': {'type': 'literal', 'value': 'self-discovery'}}, {'rel1': {'type': 'literal', 'value': 'after'}, 'obj1': {'type': 'literal', 'value': 'multiple writer and director changes'}}, {'rel1': {'type': 'literal', 'value': 'in England and at'}, 'obj1': {'type': 'literal', 'value': 'the Venice Beach Skatepark'}}, {'rel1': {'type': 'literal', 'value': 'in Los Angeles from'}, 'obj1': {'type': 'literal', 'value': 'March to July'}}, {'rel1': {'type': 'literal', 'value': 'received'}, 'obj1': {'type': 'literal', 'value': 'critical acclaim'}}, {'rel1': {'type': 'literal', 'value': 'rebuffs'}, 'obj1': {'type': 'literal', 'value': 'Beach Ken'}}, {'rel1': {'type': 'literal', 'value': 'develops'}, 'obj1': {'type': 'literal', 'value': 'bad breath'}}, {'rel1': {'type': 'literal', 'value': 'develops'}, 'obj1': {'type': 'literal', 'value': 'cellulite'}}, {'rel1': {'type': 'literal', 'value': 'develops'}, 'obj1': {'type': 'literal', 'value': 'flat feet'}}, {'rel1': {'type': 'literal', 'value': 'punches'}, 'obj1': {'type': 'literal', 'value': 'man'}}, {'rel1': {'type': 'literal', 'value': 'and Ken'}, 'obj1': {'type': 'literal', 'value': 'arrested'}}, {'rel1': {'type': 'literal', 'value': 'tracks down'}, 'obj1': {'type': 'literal', 'value': 'her owner'}}, {'rel1': {'type': 'literal', 'value': 'criticized for'}, 'obj1': {'type': 'literal', 'value': 'encouraging unrealistic beauty standards'}}, {'rel1': {'type': 'literal', 'value': 'escapes'}, 'obj1': {'type': 'literal', 'value': "with Gloria and Sasha's help"}}, {'rel1': {'type': 'literal', 'value': 'unsuccessfully tries'}, 'obj1': {'type': 'literal', 'value': 'to convince Ken and the other Barbies to return'}}, {'rel1': {'type': 'literal', 'value': 'becomes'}, 'obj1': {'type': 'literal', 'value': 'depressed'}}, {'rel1': {'type': 'literal', 'value': 'restored'}, 'obj1': {'type': 'literal', 'value': 'self-confidence'}}, {'rel1': {'type': 'literal', 'value': 'has'}, 'obj1': {'type': 'literal', 'value': 'no set ending'}}, {'rel1': {'type': 'literal', 'value': 'meets with'}, 'obj1': {'type': 'literal', 'value': 'Ruth Handler'}}, {'rel1': {'type': 'literal', 'value': 'meets with'}, 'obj1': {'type': 'literal', 'value': 'Mattel co-founder'}}, {'rel1': {'type': 'literal', 'value': 'meets with'}, 'obj1': {'type': 'literal', 'value': 'creator of Barbie doll'}}, {'rel1': {'type': 'literal', 'value': 'decides to become'}, 'obj1': {'type': 'literal', 'value': 'human'}}, {'rel1': {'type': 'literal', 'value': 'decides to become'}, 'obj1': {'type': 'literal', 'value': 'return to the real world'}}, {'rel1': {'type': 'literal', 'value': 'desires'}, 'obj1': {'type': 'literal', 'value': 'to be more than just a plastic doll'}}, {'rel1': {'type': 'literal', 'value': 'being "constrained in multitudes"'}, 'obj1': {'type': 'literal', 'value': 'as "all of these women are Barbie and Barbie is all of these women"'}}, {'rel1': {'type': 'literal', 'value': 'living in'}, 'obj1': {'type': 'literal', 'value': 'utopia'}}, {'rel1': {'type': 'literal', 'value': 'facing'}, 'obj1': {'type': 'literal', 'value': 'the real world'}}, {'rel1': {'type': 'literal', 'value': 'learns that'}, 'obj1': {'type': 'literal', 'value': 'some women do not like her'}}, {'rel1': {'type': 'literal', 'value': 'is being stared at inappropriately'}, 'obj1': {'type': 'literal', 'value': 'Venice Beach'}}]
>>> print(str(response_graph_rag))                                              

Barbie is released in the United States, United Kingdom, Middle East, Algeria, Lebanon, Kuwait, and banned in Algeria.
>>>

Additional Interactions

You can also present different questions to a Python Interpreter instance via its command-line such as:

>>> response_graph_rag = kg_rag_query_engine.query("Who is Ken?")

[{'rel1': {'type': 'literal', 'value': 'stows away'}, 'obj1': {'type': 'literal', 'value': 'in her convertible'}}, {'rel1': {'type': 'literal', 'value': 'learns about'}, 'obj1': {'type': 'literal', 'value': 'the patriarchal system'}}, {'rel1': {'type': 'literal', 'value': 'persuades'}, 'obj1': {'type': 'literal', 'value': 'the other Kens to take over'}}, {'rel1': {'type': 'literal', 'value': 'has low self-esteem'}, 'obj1': {'type': 'literal', 'value': 'seeks approval'}}, {'rel1': {'type': 'literal', 'value': 'turns to'}, 'obj1': {'type': 'literal', 'value': 'patriarchal expression'}}, {'rel1': {'type': 'literal', 'value': 'tries to kiss her'}, 'obj1': {'type': 'literal', 'value': 'sexual advance'}}, {'rel1': {'type': 'literal', 'value': 'embodies'}, 'obj1': {'type': 'literal', 'value': 'idea of patriarchy'}}, {'rel1': {'type': 'literal', 'value': 'radicalization'}, 'obj1': {'type': 'literal', 'value': "resembles men's rights movement"}}]
>>> response_graph_rag = kg_rag_query_engine.query("Who is Ken?")
[{'rel1': {'type': 'literal', 'value': 'stows away'}, 'obj1': {'type': 'literal', 'value': 'in her convertible'}}, {'rel1': {'type': 'literal', 'value': 'learns about'}, 'obj1': {'type': 'literal', 'value': 'the patriarchal system'}}, {'rel1': {'type': 'literal', 'value': 'persuades'}, 'obj1': {'type': 'literal', 'value': 'the other Kens to take over'}}, {'rel1': {'type': 'literal', 'value': 'has low self-esteem'}, 'obj1': {'type': 'literal', 'value': 'seeks approval'}}, {'rel1': {'type': 'literal', 'value': 'turns to'}, 'obj1': {'type': 'literal', 'value': 'patriarchal expression'}}, {'rel1': {'type': 'literal', 'value': 'tries to kiss her'}, 'obj1': {'type': 'literal', 'value': 'sexual advance'}}, {'rel1': {'type': 'literal', 'value': 'embodies'}, 'obj1': {'type': 'literal', 'value': 'idea of patriarchy'}}, {'rel1': {'type': 'literal', 'value': 'radicalization'}, 'obj1': {'type': 'literal', 'value': "resembles men's rights movement"}}]

and obtain a human friendly response as per:

>>> print(str(response_graph_rag))

Ken is a person who tries to kiss her and embodies the idea of patriarchy.
>>> 

Generate RAG Dataset from a different Wikipedia Article

Another Wikipedia dataset can be loaded by amending the llama_test.py and llama_test2.py programs and change:

  1. The RDF GRAPH name the dataset should be loaded into ie
GRAPH = 'http://purl.org/stuff/{new-graph-name}'
  1. Change the Wikiword to be loaded in the WikipediaReader function:
WikipediaReader = download_loader("WikipediaReader")
loader = WikipediaReader()
documents = loader.load_data(
        pages=['{Wikiword}'], auto_suggest=False)
  1. Then in the previous sections llama_test.py can be run to load the dataset and llama_test2.py can be run to ask questions and get responses.

Sample Session Output from loading and querying a new dataset

In this example the dataset or Wikword data has been loaded for is Nevis:

$ python3
Python 3.11.5 (main, Aug 24 2023, 15:09:45) [Clang 14.0.3 (clang-1403.0.22.14.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> exec(open('llama_test_nevis.py').read())
(Nevis, is island in, Caribbean Sea)
(Nevis, is part of, Leeward Islands)
(Nevis, is located near, Lesser Antilles)
(Nevis, has an area of, 93 square kilometers)
(Nevis, has a capital of, Charlestown)
.
.
.
(Alexander Hamilton, is, statesman)
(Runako Morton, is, cricket player)
(Frances Nelson, is, wife of Admiral Lord Horatio Nelson)
[]
[]


The capital of Nevis is Charlestown.
>>> ^D

$ python3
Python 3.11.5 (main, Aug 24 2023, 15:09:45) [Clang 14.0.3 (clang-1403.0.22.14.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> exec(open('llama_test2_nevis.py').read())
[]
[]
[]


The capital of Nevis is Charlestown.
>>> response_graph_rag = kg_rag_query_engine.query("Who is the Premier of Nevis?")
[]
[]
>>> print(str(response_graph_rag))


The current premier of Nevis is Mark Brantley.

Related