A Basic Graph Pattern (BGP) is the core matching construct in the SPARQL query language. It is defined as a set of triple patterns—RDF triples where any component can be a variable—that must all find a match in the target RDF dataset for the query to yield a solution. The SPARQL processor evaluates a BGP by performing a graph pattern match, finding all possible variable bindings (solutions) that make each triple pattern a true statement in the data graph. This conjunctive matching forms the basis for more complex SPARQL query forms.
Glossary
Basic Graph Pattern

What is a Basic Graph Pattern?
A Basic Graph Pattern (BGP) is the fundamental matching unit in a SPARQL query, consisting of a set of triple patterns that must all be satisfied to produce a query solution.
BGPs are combined using SPARQL operators like UNION or OPTIONAL to build complex query patterns. Crucially, the evaluation of a BGP is defined as a single join across all its triple patterns, not as a sequence of independent lookups. This allows for sophisticated query optimization by the triplestore. Understanding BGPs is essential for writing efficient SPARQL, as they directly correspond to the fundamental subgraph isomorphism problem that graph databases solve.
Key Components of a Basic Graph Pattern
A Basic Graph Pattern (BGP) is the fundamental matching unit in a SPARQL query. It consists of a set of triple patterns that must all be satisfied (matched) against the RDF dataset for the query to produce a solution (a set of bindings for the variables).
Triple Pattern
The atomic building block of a BGP. It mirrors the structure of an RDF triple (subject-predicate-object) but allows variables (prefixed with ? or $) in any position to act as placeholders for unknown values.
- Example:
?person foaf:name "Alice" . - This pattern matches any triple where the predicate is
foaf:name, the object is the literal"Alice", and binds the subject of that triple to the variable?person. - A BGP is a conjunction of triple patterns; all patterns must match simultaneously within the same graph.
Variables
Variables are the query's unknowns, represented by a ? or $ followed by a name (e.g., ?city, ?date). They are bound to RDF terms (URIs, literals, or blank nodes) during query execution.
- Variables create the join conditions across triple patterns in a BGP. If the same variable appears in multiple patterns, it must be bound to the same value in all matches.
- Example BGP:
?article dc:creator ?author . ?author foaf:based_near ?city . - Here,
?authoris the join variable, ensuring the matched creator is also the entity with a location.
IRIs and Prefixes
IRIs (Internationalized Resource Identifiers) identify resources and predicates. To keep patterns concise, SPARQL uses prefix declarations (e.g., PREFIX foaf: <http://xmlns.com/foaf/0.1/>) to abbreviate long IRIs.
- Abbreviated IRI:
foaf:nameexpands to the full IRI. - Full IRI: Enclosed in angle brackets:
<http://example.org/person>. - Using correct IRIs is critical for precise matching against the dataset's ontology.
Literals and Datatypes
Literals are constant values (strings, numbers, dates) used in the object position of a triple pattern. They can be:
- Simple Literals: Plain strings:
"London". - Typed Literals: Include a datatype IRI:
"42"^^xsd:integer. - Language-tagged Literals: Include a language tag:
"chat"@fr.
Pattern matching is sensitive to literal type and language tag. The pattern ?s ex:value "42" will not match a triple with object "42"^^xsd:integer unless the query explicitly uses the typed literal.
Blank Nodes in Patterns
Blank nodes (written as _:a or []) in a BGP act as existential variables—they match any resource but do not bind to a variable name for output. They are useful for matching anonymous resources or specific graph structures without needing to identify the node.
- Example:
?person foaf:knows [ foaf:name "Bob" ] . - This pattern matches a person who knows some resource (the blank node) that has the name "Bob". The identity of that resource is not captured in the query results.
Graph Context (FROM / GRAPH)
A BGP is matched against a specific RDF Dataset, which is a collection of graphs. The default graph and any named graphs to be queried are specified using the FROM and FROM NAMED clauses in the SPARQL query.
- Patterns are matched against the default graph unless enclosed in a
GRAPHclause. GRAPH ?g { ...BGP... }: Matches the BGP only within the named graph bound to variable?g.GRAPH <http://ex.org/graph1> { ... }: Matches the BGP specifically within the named graph identified by that IRI.
BGP vs. Other SPARQL Graph Patterns
A comparison of the Basic Graph Pattern (BGP) with other core SPARQL graph pattern types, detailing their syntax, semantics, and typical use cases.
| Feature / Pattern Type | Basic Graph Pattern (BGP) | Optional Graph Pattern (OPTIONAL) | Alternative Graph Pattern (UNION) | Group Graph Pattern (GROUP) |
|---|---|---|---|---|
Core Matching Semantics | Conjunctive (AND). All triple patterns in the set must match. | Left-join semantics. Matches optional patterns if possible; does not fail the query if they do not match. | Disjunctive (OR). Produces solutions that match at least one of the combined graph patterns. | Logical grouping. Groups a set of patterns to control precedence, especially with FILTERs. |
SPARQL Syntax Keyword | None (implicit). A set of triple patterns within {} is a BGP. | OPTIONAL | UNION | {} (braces) |
Impact on Solution Set | Restrictive. Reduces the solution set by requiring all conditions. | Expansive. Can add variable bindings to existing solutions without filtering them out. | Expansive. Combines solution sets from multiple patterns, increasing total results. | Neutral. Alters evaluation order but does not inherently change final results. |
Cardinality of Results | Produces the Cartesian product of matches for its triple patterns. | Can increase cardinality if the optional part matches multiple times for a single solution from the mandatory part. | Produces the union of solutions from each branch, potentially increasing total cardinality. | No direct impact; depends on the patterns inside the group. |
Use of Unbound Variables | ||||
Common Primary Use Case | Core fact retrieval. Finding entities that satisfy a conjunction of properties and relationships. | Enriching results. Adding supplemental information that may not exist for all primary matches. | Querying heterogeneous data. Searching across different possible graph structures or classifications. | Scoping filters. Applying a FILTER expression to the results of a specific set of patterns. |
Interaction with FILTER | FILTERs can be applied to the entire BGP's solution set. | FILTERs inside an OPTIONAL block apply only to the optional matches. | FILTERs must be placed within each UNION branch to apply to those solutions. | Essential for applying a FILTER to a specific sub-pattern, not the entire WHERE clause. |
Performance Consideration | Typically the most efficient; triplestores optimize BGPs heavily. | Can be computationally expensive, especially with complex optional patterns on large datasets. | May require evaluating multiple sub-queries, but modern optimizers handle this efficiently. | Minimal overhead; primarily a syntactic construct for the query planner. |
Frequently Asked Questions
A Basic Graph Pattern (BGP) is the fundamental matching unit in SPARQL, the query language for RDF. It consists of a set of triple patterns that must all be satisfied for the query to return results. This FAQ addresses common questions about its structure, function, and role in semantic querying.
A Basic Graph Pattern (BGP) is the core matching construct in a SPARQL query, defined as a set of one or more triple patterns that must all be matched against the RDF dataset for the query to produce a solution. It is the atomic unit of graph pattern matching, analogous to a conjunction of conditions in a SQL WHERE clause. A BGP is evaluated by finding all possible mappings of its variables to RDF terms (URIs, literals, or blank nodes) in the dataset such that each triple pattern becomes a valid RDF triple. The result is a sequence of solution mappings (bindings for the variables) that satisfy the entire pattern. BGPs are the building blocks for more complex SPARQL patterns, which can combine them using operators like UNION, OPTIONAL, and FILTER.
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
A Basic Graph Pattern (BGP) is the foundational unit of a SPARQL query. To understand its role and power, it's essential to grasp the related constructs that build upon it or interact with it within the SPARQL language.
SPARQL Query
A SPARQL Query is a request to retrieve or manipulate data from an RDF graph database. It is composed of several key clauses, with the Basic Graph Pattern forming the core matching logic within the WHERE clause. The query's overall structure determines the form of the results, such as a set of variable bindings (SELECT), a new RDF graph (CONSTRUCT), or a boolean answer (ASK).
Triple Pattern
A Triple Pattern is the atomic matching unit within a SPARQL query, analogous to an RDF triple but with variables. It consists of a subject, predicate, and object, where any component can be a variable (prefixed with ? or $). A Basic Graph Pattern is a set of these triple patterns that must all find matches in the dataset for a solution to be generated. For example, ?person foaf:name ?name is a single triple pattern.
Solution Modifier
Solution Modifiers are SPARQL clauses that process the results after the Basic Graph Pattern has been matched. They do not affect which data is matched but control the presentation of the results. Key modifiers include:
ORDER BY: Sorts the solution sequence.LIMIT/OFFSET: Restricts the number of solutions returned, enabling pagination.DISTINCT/REDUCED: Eliminates duplicate solutions from the results. These operate on the solution set produced by evaluating the BGP.
SPARQL Property Path
A SPARQL Property Path provides a concise syntax for matching arbitrary-length paths in the graph, extending the capability of a simple triple pattern. While a BGP matches fixed, adjacent triples, a property path can match chains of relationships using operators like sequence (/), alternation (|), and Kleene star (*). For example, :Alice :knows+ ?friend finds all people reachable via one or more :knows relationships. Property paths are integrated into graph patterns.
SPARQL FILTER
A SPARQL FILTER is a constraint that removes solutions from the result set based on a boolean expression. It is applied to the solutions generated by a Basic Graph Pattern. FILTERs can test values of variables using functions for comparison, regex matching, data type checking, and more. For example, FILTER (?age > 18) would eliminate all solutions where the bound value for ?age is not greater than 18. It refines the results of pattern matching.
OPTIONAL Graph Pattern
An OPTIONAL Graph Pattern allows parts of a query to be matched without causing the entire solution to be rejected if the optional part fails. It is a key feature for dealing with incomplete data. In a query, a BGP inside an OPTIONAL { } block will extend a solution if the pattern matches, but will leave the variables from that pattern unbound if it does not, without invalidating the core solution from the mandatory BGP. This enables left-outer-join semantics.

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us