GRAPH_RAG enables vector + graph retrieval in a single SELECT statement.
SELECT <columns>
FROM <table>
GRAPH_RAG '<natural language question>'
[LIMIT <n>]
[WITH SCORE > <threshold>]
[WITH CONTEXT]
[TOP_K <n>];SELECT *
FROM documents
GRAPH_RAG 'What are the risks of GDPR in AI?'
LIMIT 5
WITH SCORE > 0.85
WITH CONTEXT
TOP_K 25;GRAPH_RAGis a top-level SELECT clause parsed byEnhancedSqlParser.- Execution is delegated to an optional
IGraphRagProviderimplementation. - Core storage engine, WAL, and file format are unchanged.
WITH CONTEXTrequests additional context enrichment fields in returned rows.TOP_Kcontrols the candidate pool before finalLIMIT+ score filtering.
- Question must be a non-empty SQL string literal.
LIMITmust be positive.TOP_Kmust be positive.WITH SCORE > XrequiresXbetween0and1.
- Core parser/AST:
src/SharpCoreDB/Services - Provider contract:
src/SharpCoreDB/Interfaces/IGraphRagProvider.cs - Graph.Advanced adapter:
src/SharpCoreDB.Graph.Advanced/SqlIntegration/GraphRagSqlProvider.cs
var services = new ServiceCollection();
services.AddSharpCoreDB();
services.AddSharpCoreDBGraphRagSql(options =>
{
options.GraphTableName = "graph_edges";
options.EmbeddingTableName = "document_embeddings";
options.EmbeddingDimensions = 384;
// Optional: inject your embedding provider
options.EmbeddingProvider = question => MyEmbeddingModel.Embed(question);
});GRAPH_RAG results flow through normal SQL projection rules. You can project only required fields and alias them.
SELECT node_id AS doc_id, score AS relevance, context AS snippet
FROM documents
GRAPH_RAG 'What are the risks of GDPR in AI?'
LIMIT 5
WITH SCORE > 0.85
WITH CONTEXT;Special field mappings in GRAPH_RAG projection:
node_id(alsoid,nodeId) → result node identifierscore→ combined ranking scorecontext→ enriched context (whenWITH CONTEXTis used)