learning-it by example

#269 Data modelling 7 min

Schema Design for RAG: Chunks, Versions, Sources in SQLite

Asked one question, a one-table design I built without tenant, version or access columns returned 3 chunks in its top 4 that the user should not get: an old version, another tenant's text, and a note she may not read.

1. In a SQLite schema for retrieval augmented generation (RAG), what is the order of the structure that holds the text, from the source down to the vector?
2. Ana, a support user at the company acme, asked how many days she has for a refund. How did the one-table design do against the schema design?
3. In a RAG retrieval schema, why does the search filter by version, tenant and access before it ranks?
4. In a SQLite RAG schema, when a made-up refund policy changed from 14 days to 30, how did the re-index handle the 2 chunks of the new version?
5. The deletion request for Sam Example was run with SQLite foreign keys on and then off. What was left behind with foreign keys off?

Practice only: nothing is saved and no score counts towards anything. Each answer comes with the reason.

  1. Read the three runs

    Copy the code folder first. Run python run.py search, python run.py reindex and python run.py delete. For the search run, write down which chunk comes first from the schema and which of the four one-table rows are not labelled ok. Nothing here uses a model or the network.

    A hint

    The labels old version, other tenant and no access say why a row should not reach the user.

  2. Ask a different question

    In run.py, change the QUESTION text to Is shipping free? and run python run.py search. Predict which chunk comes first from the schema. When I ran it, the first schema result was Refund policy v2 chunk 2 at 1.000, then chunk 1 at 0.535. Change the question back to the refund question afterwards, because the next tasks expect it.

    A hint

    The toy vectors count only five words, including shipping and free.

  3. Ask as another user

    In run.py, change every "ana" to "gus" in the search part and run python run.py search. Gus works in support at globex. Predict what the schema returns and which cite line appears. When I ran it, the schema returned only the globex refund chunk at 0.949, cited to the globex address. The header line still says ana, because that text is typed in. Change "gus" back to "ana" afterwards, because the next task starts from the original.

    A hint

    Members says which tenant and group each user is in.

  4. Ask as the HR user

    In run.py, change every "ana" to "hal" in the search part and run python run.py search. Hal is in the hr group at acme. Predict what the schema returns. When I ran it, the only result was the Absence note at 0.707, with a citation to it. The header line still says ana because that text is typed in.

    A hint

    Only the hr group may read the absence note, and Hal is the only acme member in that group.

These tasks are for you to try on your own machine. Nothing is checked or saved.

What this does not show

Made-up documents, companies and people; the one-table design was written without tenant, version or access columns on purpose; toy five-word vectors instead of an embedding model and no language model; the delete covers this SQLite database only, not backups or copies, and is not legal advice.

Up next in Data modelling

More in Data modelling

All Data modelling videos

Related videos