---
title: "SurrealDB for AI Engineers | SurrealDB University"
description: "An eleven-lesson course from calling an LLM API to an agent that retrieves by meaning, remembers what it learned, writes its own queries, and can prove its…"
url: https://surrealdb.com/learn/ai
---

![Course content preview](https://surrealdb.com/assets/static/course-ai.LEsq_J_G.avif)

Course chapters

[Back to courses](https://surrealdb.com/learn) [SurrealDB for AI Engineers](https://surrealdb.com/learn/ai) [AI foundations](https://surrealdb.com/learn/ai/ai-foundations) [Vector embeddings and search](https://surrealdb.com/learn/ai/vector-embeddings) [Full-text search and BM25](https://surrealdb.com/learn/ai/fulltext-search-bm25) [Building a RAG knowledge base](https://surrealdb.com/learn/ai/rag-knowledge-base) [Hybrid search and reranking](https://surrealdb.com/learn/ai/hybrid-search-reranking) [Building an agent memory store](https://surrealdb.com/learn/ai/agent-memory-store) [Text-to-SurQL: agentic prompt engineering](https://surrealdb.com/learn/ai/text-to-surrealql) [Many sources and agents, one context layer](https://surrealdb.com/learn/ai/multi-source-context-layer) [Chunking strategies](https://surrealdb.com/learn/ai/chunking-strategies) [Evaluating retrieval quality](https://surrealdb.com/learn/ai/evaluating-retrieval) [Graph RAG beyond one hop](https://surrealdb.com/learn/ai/graph-rag-multi-hop) Certificate Pending

# SurrealDB for AI Engineers

SurrealDB for AI Engineers is an eleven-lesson course that takes you from "I've called an LLM API" to an agent that retrieves by meaning, remembers what it learned, and writes its own queries. [Lesson 08](https://surrealdb.com/learn/ai/multi-source-context-layer) weighs two architectures for the case where the answer lives across several systems and more than one agent is asking. The last three lessons turn back on the retrieval layer itself and ask whether it returns the right documents, which is the question the earlier lessons give you no way to answer.

## Who this is for

This course is for anyone who writes software, has called an LLM API, and is now looking at the retrieval layer underneath it. Prior SurrealDB experience isn't needed, since the track introduces every feature where it first comes up. An embedding model and a cloud account aren't needed either: the examples use tiny hand-written vectors so that the maths stays readable, and every lesson that uses them ends by showing what to change to swap in a real model.

The one thing you will want is the `surreal` binary, which you can download via a single command:

Bash

PowerShell

```bash
curl -sSf https://install.surrealdb.com | sh
surreal version
```

## The lessons

As one of SurrealDB University's modular courses, this one also focuses on a single topic and is just a few chapters in length. It runs over eleven pages. [Lesson 01](https://surrealdb.com/learn/ai/ai-foundations) is background reading with no SurrealDB in it, so you can skip it if you already build with LLMs. Lessons 02 and 03 are the retrieval primitives, one idea each with a small runnable example, and every later lesson builds on one or both. Lessons 04 to 07 are the applied patterns. [Lesson 08](https://surrealdb.com/learn/ai/multi-source-context-layer) is design rather than code, with nothing to install. Lessons 09 to 11 are about retrieval quality: how you split a document, how you measure whether the split helped, and what to do when the answer is a hop away from anything the question resembles.

From [lesson 02](https://surrealdb.com/learn/ai/vector-embeddings) onwards you start a local `surreal` server and load small `.surql` files. Each hands-on lesson gives you a schema, a seed, and a query file to save and run. Keep the server in one terminal and run the import and `surreal sql` commands in another.

|  | Lesson | What you get |
| --- | --- | --- |
| 01 | [**AI foundations**](https://surrealdb.com/learn/ai/ai-foundations) | How LLMs work (tokens, context windows, why they hallucinate) and the difference between prompt engineering and context engineering. |
| 02 | [**Vector embeddings and vector search**](https://surrealdb.com/learn/ai/vector-embeddings) | What an embedding is, exact search with no index, `DEFINE INDEX … HNSW` and every parameter, the KNN operator, `vector::distance::knn()`, and how to choose an embedding model. |
| 03 | [**Full-text search and BM25**](https://surrealdb.com/learn/ai/fulltext-search-bm25) | What lexical search scores, `DEFINE ANALYZER` and stemming, `DEFINE INDEX … FULLTEXT … BM25(k1, b)`, the `@@` operator, `search::score()` and `search::highlight()`. |
| 04 | [**RAG knowledge base**](https://surrealdb.com/learn/ai/rag-knowledge-base) | Semantic retrieval with typed filters and a citation graph, in one query. Relevance thresholds that keep weak matches out of the prompt, and the surviving documents rendered into it. |
| 05 | [**Hybrid search and reranking**](https://surrealdb.com/learn/ai/hybrid-search-reranking) | BM25 and vector search over the same table, fused with Reciprocal Rank Fusion. Hand-rolled first, then with the built-in `search::rrf`. |
| 06 | [**Agent memory store**](https://surrealdb.com/learn/ai/agent-memory-store) | Recall that blends similarity, recency and importance; graph-assembled context; forgetting via `expires_at`; and a write-back that makes a memory count for more each time it is recalled. |
| 07 | [**Text-to-SurrealQL**](https://surrealdb.com/learn/ai/text-to-surrealql) | A prompt generated from the database's own `DEFINE` statements, so it can't drift from the schema. Dynamic few-shot examples, the three ways generation fails, and guardrails the model can't talk past. |
| 08 | [**Many sources, many agents, one context layer**](https://surrealdb.com/learn/ai/multi-source-context-layer) | Two architectures for a multi-agent system over a data lake, a relational DB, documents and SaaS. Why the agent-as-aggregator hands people records they can't see, and what record access, `$auth` and zero-copy references change. |
| 09 | [**Chunking strategies**](https://surrealdb.com/learn/ai/chunking-strategies) | Three ways to split a document compared on the same corpus, why a chunk that covers more ground points nowhere, and the record link that lets you retrieve something small and generate from something large. |
| 10 | [**Evaluating retrieval quality**](https://surrealdb.com/learn/ai/evaluating-retrieval) | A golden set with the answers labelled, recall@k, precision@k and MRR as SurrealQL functions, and and the harness that settles which retriever is better. |
| 11 | [**Graph RAG beyond one hop**](https://surrealdb.com/learn/ai/graph-rag-multi-hop) | Multi-hop traversal for when the document that explains a problem is not the document that mentions it. Depth limits, pruning, `+shortest`, and how to tell whether the extra hops are worth their tokens. |

## How the lessons connect

```text
               01  AI foundations
                        │
           ┌────────────┴─────────────┐
 02  vector embeddings     03  full-text and BM25
           │                          │
04  RAG knowledge base                │
           └────────────┬─────────────┘
                        │
                05  hybrid search
                        │
                06  agent memory
                        │
              07  text-to-SurrealQL
                        │
                08  context layer
                        │
           ┌────────────┴─────────────┐
 09  chunking strategies   11  graph RAG, multi-hop
           │                          │
           └────────────┬─────────────┘
                        │
            10  evaluating retrieval
```

[Lesson 04](https://surrealdb.com/learn/ai/rag-knowledge-base) uses the vector search from [lesson 02](https://surrealdb.com/learn/ai/vector-embeddings), and it's first because it's the simpler of the two applied lessons. [Lesson 05](https://surrealdb.com/learn/ai/hybrid-search-reranking) is where vector search and full-text search meet. [Lesson 06](https://surrealdb.com/learn/ai/agent-memory-store) adds memory on top of retrieval, and [lesson 07](https://surrealdb.com/learn/ai/text-to-surrealql) lets the agent write its own queries. [Lesson 08](https://surrealdb.com/learn/ai/multi-source-context-layer) is about how you put the pieces together once the data lives in several systems.

Lessons 09 and 11 are the two ways of changing what gets retrieved: cut the documents up differently, or follow the links between them. [Lesson 10](https://surrealdb.com/learn/ai/evaluating-retrieval) sits under both, because a golden set - a list of questions paired with the documents that answer them, labelled by hand - is how you find out which of them helped. It is drawn last because it is easier to write once you have two retrievers to compare, though you can read it directly after [lesson 09](https://surrealdb.com/learn/ai/chunking-strategies) if you would rather measure before you add anything else.

Each lesson stands alone if you would rather jump straight in, and the cross-references will tell you what parts you are skipping when you do.

## Related links

While you're here, feel free to set up an account with us, browse the full docs or join the largest community of SurrealDB users in one place.

- [Create a free cloud instance](https://surrealdb.com/cloud)
- [Read the docs](https://surrealdb.com/docs)
- [Join our Discord server](https://discord.gg/surrealdb)

At a glance

**Chapters**

11

**Format**

Text, with queries you can run

**Runs in**

SurrealDB Studio, in the browser

**Cost**

Free

**Certificate**

On completion

[Start the course](https://surrealdb.com/learn/ai/ai-foundations)

## Continue

### [SurrealDB University](https://surrealdb.com/learn)

All courses

### [AI foundations](https://surrealdb.com/learn/ai/ai-foundations)

Get started

THE PLATFORM

## Everything an application and its agents know. Five surfaces, one engine.

Database

Document, graph, vector, time-series and relational in one engine.

![Five data models as dotted tiles: documents, graph, vector, time-series and relational](https://surrealdb.com/assets/static/platform-database.DUdumYDz.avif)

Read more

[Database](https://surrealdb.com/surrealdb)

Agent Memory

What an agent learns, with its source and its time, in the same engine.

![A timeline of remembered facts, each with its source](https://surrealdb.com/assets/static/platform-agent-memory.B4RNjvbX.avif)

Read more

[Agent Memory](https://surrealdb.com/agent-memory)

Cloud

Managed clusters in the regions you choose, scaled on demand.

![Clusters in three regions on a world map, each running or scaling](https://surrealdb.com/assets/static/platform-cloud.--QZnaVi.avif)

Read more

[Cloud](https://surrealdb.com/cloud)

Studio

Query, explore and design the schema from the browser.

![A SurrealQL query in Studio and the schema graph under it](https://surrealdb.com/assets/static/platform-studio.7ykBFNLq.avif)

Read more

[Studio](https://surrealdb.com/studio)

MCP

Every model that speaks MCP reaches the database and the memory directly.

![Three models connected through MCP to the database and Agent Memory](https://surrealdb.com/assets/static/platform-mcp.D_oH0_wm.avif)

Read more

[MCP](https://surrealdb.com/mcp)

IN PRODUCTION

## Trusted at scale. Samsung, Nvidia, Verizon, Tencent, and Walmart run on SurrealDB.

14,000+

Developers building on SurrealDB Cloud

4M+

Developers building on SurrealDB worldwide

FROM THE TEAMS

> SurrealDB gives us a foundation where we can unify semantic search, knowledge graphs, and AI-driven decision making without stitching together multiple systems. Collapsing responsibility into SurrealDB has become our default engineering posture.

*Justin Foley*

VP of Engineering, Later

```json
{"@context":"https://schema.org","@type":"Course","name":"SurrealDB for AI Engineers","description":"An eleven-lesson course from calling an LLM API to an agent that retrieves by meaning, remembers what it learned, writes its own queries, and can prove its retrieval works - all against one database.","url":"https://surrealdb.com/learn/ai","inLanguage":"en","isAccessibleForFree":false,"provider":{"@type":"Organization","name":"SurrealDB","url":"https://surrealdb.com"},"hasPart":[{"@type":"LearningResource","name":"AI foundations","url":"https://surrealdb.com/learn/ai/ai-foundations"},{"@type":"LearningResource","name":"Vector embeddings and search","url":"https://surrealdb.com/learn/ai/vector-embeddings"},{"@type":"LearningResource","name":"Full-text search and BM25","url":"https://surrealdb.com/learn/ai/fulltext-search-bm25"},{"@type":"LearningResource","name":"Building a RAG knowledge base","url":"https://surrealdb.com/learn/ai/rag-knowledge-base"},{"@type":"LearningResource","name":"Hybrid search and reranking","url":"https://surrealdb.com/learn/ai/hybrid-search-reranking"},{"@type":"LearningResource","name":"Building an agent memory store","url":"https://surrealdb.com/learn/ai/agent-memory-store"},{"@type":"LearningResource","name":"Text-to-SurQL: agentic prompt engineering","url":"https://surrealdb.com/learn/ai/text-to-surrealql"},{"@type":"LearningResource","name":"Many sources and agents, one context layer","url":"https://surrealdb.com/learn/ai/multi-source-context-layer"},{"@type":"LearningResource","name":"Chunking strategies","url":"https://surrealdb.com/learn/ai/chunking-strategies"},{"@type":"LearningResource","name":"Evaluating retrieval quality","url":"https://surrealdb.com/learn/ai/evaluating-retrieval"},{"@type":"LearningResource","name":"Graph RAG beyond one hop","url":"https://surrealdb.com/learn/ai/graph-rag-multi-hop"}]}
```

```json
{"@context":"https://schema.org","@type":"Organization","@id":"https://surrealdb.com/#organization","name":"SurrealDB","url":"https://surrealdb.com","logo":"https://surrealdb.com/assets/static/logo.BG7_TG2b.svg","description":"SurrealDB is the context and memory layer for AI agents. A multi-model database for documents, graphs, vectors, and time-series.","foundingDate":"2022","legalName":"SurrealDB Ltd","identifier":{"@type":"PropertyValue","propertyID":"GB-COH","value":"13615201"},"address":{"@type":"PostalAddress","streetAddress":"3rd Floor, 1 Ashley Road","addressLocality":"Altrincham","addressRegion":"Cheshire","postalCode":"WA14 2DT","addressCountry":"GB"},"contactPoint":[{"@type":"ContactPoint","contactType":"customer support","email":"support@surrealdb.com","url":"https://surrealdb.com/contact","availableLanguage":"English"},{"@type":"ContactPoint","contactType":"sales","email":"info@surrealdb.com","url":"https://surrealdb.com/contact","availableLanguage":"English"},{"@type":"ContactPoint","contactType":"security","email":"security@surrealdb.com","url":"https://surrealdb.com/.well-known/security.txt","availableLanguage":"English"},{"@type":"ContactPoint","contactType":"legal","email":"legal@surrealdb.com","url":"https://surrealdb.com/legal","availableLanguage":"English"}],"hasCertification":[{"@type":"Certification","name":"SOC 2 Type 2"},{"@type":"Certification","name":"GDPR"},{"@type":"Certification","name":"Cyber Essentials Plus"},{"@type":"Certification","name":"ISO 27001"}],"owns":[{"@type":"SoftwareApplication","name":"SurrealDB","url":"https://surrealdb.com/surrealdb"},{"@type":"SoftwareApplication","name":"Agent Memory","url":"https://surrealdb.com/agent-memory"}],"knowsAbout":["multi-model databases","document databases","graph databases","vector search","time-series databases","SurrealQL","Agent Memory","real-time databases","embedded databases","context layer","graph ontology","distributed database","knowledge graphs","distributed transaction protocols","highly-scalable databases"],"sameAs":["https://www.wikidata.org/wiki/Q124316308","https://github.com/surrealdb/surrealdb","https://twitter.com/surrealdb","https://www.youtube.com/@surrealdb","https://www.linkedin.com/company/surrealdb","https://discord.gg/surrealdb","https://www.reddit.com/r/surrealdb","https://www.instagram.com/surrealdb","https://medium.com/surrealdb","https://dev.to/surrealdb"]}
```

```json
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://surrealdb.com"},{"@type":"ListItem","position":2,"name":"Learn","item":"https://surrealdb.com/learn"},{"@type":"ListItem","position":3,"name":"AI","item":"https://surrealdb.com/learn/ai"}]}
```
