A recent study compared the performance of AI agents using SQL and SPARQL to retrieve information from a knowledge base. The test involved a GraphRAG system where data was stored in both PostgreSQL tables and an RDF graph, with 10,154 quads across 37 graphs generated from a single article.

The experiment utilized three open-weights models: DeepSeek V4.1 Flash, Gemma 4 31B, and Qwen 3.8 27B. Agents were tasked with answering 15 specific questions using either SQL, SPARQL, or both. The setup included a Java-based LangChain4j program with an MCP server for memory access, limiting LLM calls to 16 and memory queries to 12 per cycle.

Results showed that SQL was preferred by models in 131 out of 135 runs when both tools were available. While SPARQL proved more expensive and prone to syntax errors, it was utilized by agents when the schema did not clearly indicate the location of information. DeepSeek achieved a 100% success rate across 270 test runs.

The total cost for 1,389 test runs via OpenRouter was $12.80. Gemma accounted for 70% of the costs at $7.46, while DeepSeek cost $0.28. The study noted that agents successfully corrected 129 out of 134 initial database errors by reading error messages and rewriting their queries.