Magic Property | AllegroGraph 9.0.1
Author: Franz Incorporated

Copyright (c) 2005 - 2026 Franz, Incorporated
Last updated 27 May 2026 at 10:35

# SPARQL Magic Property

- Documentation Index
  - Release Notes
  - Quick Start
  - SSL/TLS Quick Start
  - Introduction
  - Setup and Configuration
    - Download
    - Server Installation
    - Server Configuration and Control
    - WebView
    - Database Upgrading
    - Managing Users
  - Server Management
    - Performance Tuning
    - Deleting Duplicate Triples
    - Purging Deleted Triples
    - Auditing
    - Managing Users
    - Replication
    - Point-in-Time Recovery
    - Transaction Log Archiving
    - Security Overview
    - Security Implementation
  - Tools
    - agtool
    - Data Loading
    - Data Export
    - Backup and Restore
    - Querying
    - RDFS++
    - Materializer
    - Event Scheduler
    - SHACL
  - Details
    - Triple Indices
    - Freetext Indices
    - Encoded IDs
    - Connection Pooling
    - N-dimensional Geospatial Overview
    - 2-D Geospatial
    - Temporal
    - Social Network
    - JavaScript
    - Datatypes
    - Data Conversion (Rapper)
    - Stored Procedures
    - Triple Attributes
    - Lineparse Format
  - Querying
    - SPARQL documentation summary
    - SPARQL Reference
    - SPIN
    - SPARQL Magic Properties
    - Prolog
  - 3rd-party tools
    - Solr text Indices
    - MongoDB integration
    - TopBraid Composer Plugin
    - Cloudera
  - Client APIs
    - Gruff
    - GraphTalker
    - REST/HTTP interface
    - HTTP reference
    - Javadocs (Sesame and Jena)
    - Python API
    - Lisp Reference
    - JavaScript
  - Tutorials
    - N-dimensional Geospatial
    - SPARQL Tutorial
    - Java Sesame
    - Java Jena
    - Python Sesame
    - Lisp
    - Prolog
    - More...
  - Other
    - Conferences and Seminars
    - Source Code on Github
    - Amazon EC2
    - Copyrights
  - Franz, Inc.

## http://franz.com/ns/allegrograph/8.0.0/llm/askMyDocuments

Collect background information from a vector database to build a prompt and return the response to that prompt, along with matching URI citationIds and matching scores.

Namespace:

    PREFIX llm: <http://franz.com/ns/allegrograph/8.0.0/llm/>

General forms:

The general form of askMyDocuments is:

    (?response ?score ?citationId ?citedText)
    llm:askMyDocuments
    (?text ?vectorRepoSpec ?topN ?minScore ?selector ?useClustering)

Only `?response`, `?text` and `?vectorRepoSpec` are required. The remaining variables are optional. This predicate uses keyword syntax, so you can include any subset of the optional variables in any order when they are tagged with keywords.

For example

    (?response :citedText ?citedText)
    llm:askMyDocuments
    (?text ?vectorRepoSpec :minScore 0.5 :useClustering "true"^^xsd:boolearn))

This predicate implements Retrieval Augmented Generation (RAG) by collecting background information through embedding based matching. Beginning with a search of `?vectorRepoSpec` for the `?topN` best matches to `?text`, above a minimum matching score of `?minScore`. It then combines this question, the matching citationIds and background info into a big prompt for the LLM. This helps ensure that the LLM has a source of truth to answer the question, and reduces the chance of hallucination.

The big prompt combines various bits like the following sketch:

     Here is a list of citation IDs and content related to the query <query>
     with these <citations>. Respond to the query as though you wrote the
     content. Be brief. You only have 20 seconds to reply.
     Place your response to the query in the response field.
     Insert the list of citations whose content informed the
     response into the citation_ids array.

Processing the big prompt text also causes the LLM to return only those citationIds whose content contributed to the final response.

The optional object parameter `?topN`, if not specified, has a default value of 5,

The optional object parameter `?minScore`, if not specified, has a default value of 0.8,

The predicate returns a response as well as the matching score, citationId URI, and source content from the vector database.

Note that llm:askMyDocuments may utilize keyword syntax.

You can use agtool to build a vector database from text literals stored in an Allegrograph repository (see the documentation on using agtool for LLM embedding).

There is a fully worked out example in the LLM Examples using data about Noam Chomsky.

### Notes

The following namespace abbreviations are used:

- fti - <http://franz.com/ns/allegrograph/2.2/textindex/>
- geo - <http://franz.com/ns/allegrograph/3.0/geospatial/>
- geofn - <http://franz.com/ns/allegrograph/3.0/geospatial/fn/>
- nd - <http://franz.com/ns/allegrograph/5.0/geo/nd#>
- ndfn - <http://franz.com/ns/allegrograph/5.0/geo/nd/fn#>
- sna - <http://franz.com/ns/allegrograph/4.11/sna/>

The SPARQL magic properties reference has additional information on using AllegroGraph magic properties and functions.