SurrealDB tutorial: knowledge graphs for AI agents

Learn how SurrealDB combines graph and vector retrieval, with an ETL walkthrough and a SurrealQL example that retrieves five nearest chunks.

Player not loading? Watch on YouTube

Martin, a solutions engineer at SurrealDB, explains how knowledge graphs can support retrieval for an AI agent. He contrasts graphs built from explicit transactional records with graphs whose entities and relationships an LLM extracts from documents. E-commerce orders and customer support questions illustrate how the data and expected queries shape the graph.

The session examines limits of vector-only RAG. Martin argues that dense groups of similar chunks can produce conflicting context, while graph relationships can narrow retrieval to a relevant product or domain. He also acknowledges that a vector store may be sufficient and that a knowledge graph can be unnecessary for some use cases.

The practical walkthrough covers parsing, chunking, embeddings, entity extraction, deduplication, ontology alignment and loading. Martin warns that generated summaries can contain hallucinations. He describes using those summaries to navigate a graph while keeping them out of the answer context.

A Surrealist demonstration shows record inspection and graph visualization. The SurrealQL example retrieves five nearest chunks, follows links to source documents and groups the results into JSON. A retrieval tool then embeds a search query and passes the returned context to the LLM. Martin compares fixed queries with model-written queries, which may fail, and recommends supplying query examples.