What RAG is

Three steps

A question should be answered from your note, not from what the model happens to remember.

Keep the lines. Search picks the line that shares words with the question. The next pages ask the model to use only that line.

Example

from praisonai import KeywordIndex

lines = [
    "Apples grow on trees in the orchard.",
    "The secret colour of the boat is blue.",
    "Tickets for the ferry cost four pounds.",
]
index = KeywordIndex()
index.add_documents(lines)
print(index.query("What colour is the boat?", top_k=1)[0]["text"])

Try it Yourself

Example explained

  • KeywordIndex — A search that matches words. It does not call the model.
  • query — The question. The first result is the closest line.

Reference: documentation