CoursesRetrieval methods for AI agentsQueries, knowledge bases, and what each one does best
Retrieval methods for AI agents

Queries, knowledge bases, and what each one does best

Find out which questions only a query can answer, which need a knowledge base, and which your agent should hand to another system entirely.
Log in to mark your progress for each Lesson and Task

A sales engineer asks your agent how many integrations support SCIM, and a knowledge base answers with a number. Should you trust it?

Not without checking, and the reason is structural rather than a matter of quality. A knowledge base holds entries written during a build, and an entry can state a count that was accurate the day someone wrote it. Nothing recounts when your catalog changes. Counting is arithmetic over records, and only a query performs arithmetic.

Each method holds territory the other cannot enter.

Counting, summing, averaging, aggregating, and traversing references between documents all operate over a live set of records. count(*[_type == "integration" && supportsSCIM == true]) returns a number that is correct at the moment it runs, and correct again next quarter without anyone touching it. A knowledge base has no function to complete mathematical operations over your content, so any number it reports is a number someone documented.

When your help center and your security whitepaper disagree, a build surfaces the conflict as an issue for someone to settle. The decision persists as an instruction anchored to those sources, so later builds keep it instead of working the question out again. Every entry carries a citation back to the claim's origin. A query returns what your documents say and has no concept of which document is the most correct.

Whether this account is past its usage limit, whether that order shipped, whether the item is in stock: those facts live in billing, your order management system, and your inventory service. No retrieval method over your content produces them, because your content is not where they are.

That third category gets misread more than the other two. GROQ queries your dataset at request time, so anything Sanity owns is already real-time. Publish a price change and the new price is queryable immediately. What separates Sanity from an operational system is which one owns the fact, not which one has it first.

Capability decides most routing. A few constraints decide the rest, and each one moves content somewhere else rather than ruling a method out of your project.

A knowledge base can combine three kinds of sources. One Sanity dataset selected with a GROQ query, uploaded files (like PDFs, images, text, code), and websites crawled from a starting URL.

Capability and ingestion route most of your content. What's left is a question neither one answers: which system owns a fact in the first place?

Mark lesson as complete
You have 1 uncompleted task in this lesson
0 of 1