Skip to main content
After building a graph of triples, you must be able to retrieve that information efficiently. You achieve this using SPARQL.

What is SPARQL?

SPARQL is the standard query language for graph data. It allows you to search for patterns within your triples and follow complex relationships.

Basic query structure

Consider a world with the following triples:
  • user:ethan schema:relatedTo user:gregory
  • user:gregory schema:givenName “Gregory”
To find the names of people Ethan is related to, you use a SPARQL query:
SELECT ?name WHERE {
  <http://example.com/ethan> <http://schema.org/relatedTo> ?person .
  ?person <http://schema.org/givenName> ?name .
}

Breakdown

  1. SELECT ?name: Specifies the variable you want to return.
  2. WHERE { … }: Defines the semantic pattern to match.
  3. ?person: A variable that matches any item in that position.
  4. The pattern: “Find an item that Ethan is related to, and then find that item’s given name.”
Vector search is effective for finding “similar” content based on embeddings. SPARQL is designed for exact retrieval and symbolic logic. If you ask a vector store “Who is Gregory’s manager?”, it may return a document containing Gregory’s name. If you use SPARQL, it follows the specific hasManager relationship directly to the correct item. For advanced querying strategies—including combining symbolic logic with vector retrieval—see our Semantic Search guide and Querying guide.

Practice

You can run SPARQL queries directly in the Worlds Console or via the CLI. Next, learn how to automate these processes in Neuro-symbolic agent integration.