Query Dataset With Sparql
Run a read-only SPARQL query over a dataset’s knowledge graph.
The dataset graph is read in full and loaded into an in-memory RDF store
for the duration of the request (the same view cognee.modules.graph.rdf
exports), then the query runs there. Nodes carrying an ontology_uri keep
that IRI; other nodes get {base_iri}node/{id} and cognee-native edges
{base_iri}prop/{relationship_name}; name becomes rdfs:label and
is_a becomes rdf:type / rdfs:subClassOf.
Path Parameters
- dataset_id (UUID): The unique identifier of the dataset
Request Body
- query (str): SELECT, ASK, CONSTRUCT or DESCRIBE. SPARQL Update
(INSERT, DELETE, LOAD, CLEAR, DROP, CREATE, ADD, MOVE, COPY) is refused, and
so are
SERVICE,FROMandFROM NAMED: the query reads this dataset’s graph only. - base_iri (str, optional): prefix for minted IRIs
- limit (int, 1-10000, default 1000): cap on SELECT rows
Response
Depends on the query form:
- SELECT:
variables,rows,row_count,truncated - ASK:
boolean - CONSTRUCT / DESCRIBE:
turtle
Limits
- Graphs with more than
SPARQL_MAX_GRAPH_NODESnodes (default 200000) are refused with 413; export the graph as RDF instead. - Queries that run longer than
SPARQL_QUERY_TIMEOUT_SECONDS(default 30) are abandoned with 504. The server stops waiting; the worker thread finishes on its own.
Error Codes
- 400 Bad Request: SPARQL Update keywords,
SERVICE/FROM/FROM NAMED, or the query does not parse - 404 Not Found: Dataset doesn’t exist or user doesn’t have access
- 413 Content Too Large: Dataset graph exceeds the node ceiling
- 504 Gateway Timeout: Query exceeded the wall-clock budget
Authorizations
Path Parameters
Body
Prefix for the IRIs minted for nodes without an ontology_uri and for cognee-native predicates. Defaults to https://cognee.ai/graph/.
"https://example.org/memory/"
Response
Successful Response
One query form's result; the fields for the other forms are omitted.
Keys are deliberately snake_case (not the API's usual camelCase): they mirror the SPARQL JSON results vocabulary callers already parse.