> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cognee.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# 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`, `FROM` and `FROM 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_NODES` nodes (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



## OpenAPI

````yaml /cognee_openapi_spec.json post /api/v1/datasets/{dataset_id}/sparql
openapi: 3.1.0
info:
  title: Cognee API
  description: Cognee API with Bearer token and Cookie auth
  version: 1.0.0
servers:
  - url: https://{tenant}.aws.cognee.ai
    description: 'Cognee Cloud: your tenant pod, named in the platform.cognee.ai dashboard'
    variables:
      tenant:
        default: your-tenant
        description: Your tenant name, shown in the Cognee Cloud dashboard
  - url: http://localhost:8000
    description: 'Self-hosted: a locally running cognee server'
security:
  - BearerAuth: []
  - ApiKeyAuth: []
tags:
  - name: activity
    description: >-
      Activity endpoints for inspecting pipeline runs, traced spans, tenant
      users, agents, and dataset exports.
  - name: add
    description: Data ingestion endpoints for adding text, files, and structured data.
  - name: agent connections
    description: >-
      Endpoints for registering, unregistering, and inspecting agent connections
      to the instance.
  - name: agent management
    description: Endpoints for creating, listing, retrieving, and deleting agents.
  - name: auth
    description: >-
      Authentication endpoints for user registration, login, and token
      management.
  - name: checks
    description: >-
      Diagnostic endpoint for validating a Cognee Cloud API key supplied in the
      X-Api-Key header.
  - name: cognify
    description: >-
      Knowledge processing endpoints to transform raw data into knowledge
      graphs.
  - name: configuration
    description: >-
      Endpoints for storing, retrieving, and listing a user's saved
      configurations.
  - name: conflicts
    description: ''
  - name: datasets
    description: Dataset management endpoints for listing, creating, and deleting datasets.
  - name: delete
    description: Data deletion endpoints (deprecated — use datasets endpoints instead).
  - name: forget
    description: Endpoint for removing data from the knowledge graph.
  - name: health
    description: Liveness, readiness, and component health checks.
  - name: improve
    description: Endpoint for enriching and improving an existing knowledge graph.
  - name: integrations
    description: >-
      Endpoints for connecting, provisioning, and disconnecting OAuth providers
      and plugins.
  - name: llm
    description: >-
      LLM-backed endpoints for inferring graph schemas and generating custom
      extraction prompts.
  - name: memify
    description: >-
      Endpoint for running enrichment pipelines over existing graphs or supplied
      data.
  - name: ontologies
    description: >-
      Endpoints for uploading, listing, and deleting ontology files used during
      cognify.
  - name: permissions
    description: Permission management for multi-user access control.
  - name: recall
    description: >-
      Endpoints for querying the knowledge graph and reviewing past recall
      history.
  - name: remember
    description: >-
      Endpoints for ingesting data into the knowledge graph and storing session
      memory entries.
  - name: responses
    description: Response generation endpoints using the knowledge graph.
  - name: schema
    description: >-
      Schema inspection endpoints for a dataset's derived schema inventory and
      the caller-wide memory provenance graph.
  - name: search
    description: Search endpoints for querying the knowledge graph.
  - name: sessions
    description: >-
      Endpoints for listing sessions and reporting usage, cost, and token
      statistics.
  - name: settings
    description: Configuration endpoints for managing Cognee settings.
  - name: skills
    description: >-
      Skill management endpoints for ingesting, listing, retrieving, and
      deleting dataset skills, plus read-only retrieval of improvement
      proposals.
  - name: slack
    description: >-
      Endpoints for listing workspace channels, setting channel allowlists, and
      linking Slack accounts.
  - name: sync
    description: Endpoints for syncing local data to Cognee Cloud and checking sync status.
  - name: update
    description: Endpoint for updating existing data in a dataset.
  - name: users
    description: User management endpoints.
  - name: validate
    description: >-
      Diagnostic endpoint for checking consistency between a dataset's graph and
      vector stores.
  - name: visualize
    description: Graph visualization endpoints.
paths:
  /api/v1/datasets/{dataset_id}/sparql:
    post:
      tags:
        - datasets
      summary: Query Dataset With Sparql
      description: >-
        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`, `FROM` and `FROM 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_NODES` nodes (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
      operationId: query_dataset_with_sparql_api_v1_datasets__dataset_id__sparql_post
      parameters:
        - name: dataset_id
          in: path
          required: true
          schema:
            type: string
            format: uuid
            description: >-
              Dataset UUID, the id field from GET /api/v1/datasets (not the
              name)
            examples:
              - b8a7c3de-4f5a-4b6c-8d9e-0f1a2b3c4d5e
            title: Dataset Id
          description: Dataset UUID, the id field from GET /api/v1/datasets (not the name)
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SparqlQueryPayloadDTO'
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SparqlResultDTO'
        '400':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponseDTO'
          description: Bad Request
        '404':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponseDTO'
          description: Not Found
        '413':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponseDTO'
          description: Request Entity Too Large
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
        '504':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponseDTO'
          description: Gateway Timeout
      security:
        - BearerAuth: []
        - ApiKeyAuth: []
components:
  schemas:
    SparqlQueryPayloadDTO:
      properties:
        query:
          type: string
          minLength: 1
          title: Query
          description: 'A read-only SPARQL 1.1 query: SELECT, ASK, CONSTRUCT or DESCRIBE.'
          examples:
            - SELECT ?s ?name WHERE { ?s rdfs:label ?name } LIMIT 10
        baseIri:
          anyOf:
            - type: string
            - type: 'null'
          title: Baseiri
          description: >-
            Prefix for the IRIs minted for nodes without an ontology_uri and for
            cognee-native predicates. Defaults to https://cognee.ai/graph/.
          examples:
            - https://example.org/memory/
        limit:
          type: integer
          maximum: 10000
          minimum: 1
          title: Limit
          description: Maximum number of SELECT rows to return; sets `truncated` when hit.
          default: 1000
      type: object
      required:
        - query
      title: SparqlQueryPayloadDTO
    SparqlResultDTO:
      properties:
        variables:
          anyOf:
            - items:
                type: string
              type: array
            - type: 'null'
          title: Variables
          description: 'SELECT: projected names'
        rows:
          anyOf:
            - items:
                items:
                  anyOf:
                    - type: string
                    - type: 'null'
                type: array
              type: array
            - type: 'null'
          title: Rows
          description: >-
            SELECT: one list per solution, aligned with `variables`. IRIs and
            literal lexical forms as strings, blank nodes as `_:id`, unbound as
            null.
        row_count:
          anyOf:
            - type: integer
            - type: 'null'
          title: Row Count
          description: 'SELECT: len(rows)'
        truncated:
          anyOf:
            - type: boolean
            - type: 'null'
          title: Truncated
          description: 'SELECT: true when more rows existed than `limit`'
        boolean:
          anyOf:
            - type: boolean
            - type: 'null'
          title: Boolean
          description: 'ASK: the answer'
        turtle:
          anyOf:
            - type: string
            - type: 'null'
          title: Turtle
          description: 'CONSTRUCT / DESCRIBE: the result graph as Turtle'
      type: object
      title: SparqlResultDTO
      description: >-
        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.
    ErrorResponseDTO:
      properties:
        message:
          type: string
          title: Message
      type: object
      required:
        - message
      title: ErrorResponseDTO
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
        input:
          title: Input
        ctx:
          type: object
          title: Context
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
    ApiKeyAuth:
      type: apiKey
      in: header
      name: X-Api-Key

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.