Answer from that section
The line, then the answer
The model only sees the line that search found. That is the generate step.
The first line of the result is the section. The second line is the answer, and it should say the boat is blue.
Example
from praisonai import Agent
from praisonaiagents.knowledge 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)
question = "What colour is the boat?"
section = index.query(question, top_k=1)[0]["text"]
print(section)
agent = Agent(instructions="Answer in one sentence. Use only the note you are given.")
print(agent.start(question + "\nNote: " + section))Example explained
- section — The line search found. It is handed to the agent in the question.
- Note: — The only text the agent is allowed to use.
Say unknown when the note does not help
Wrong retrieval should not produce a confident lie. The agent must say unknown when Note lacks the answer.
Example
from praisonai import Agent
from praisonaiagents.knowledge import KeywordIndex
lines = [
"Apples grow on trees in the orchard.",
"Tickets for the ferry cost four pounds.",
]
index = KeywordIndex()
index.add_documents(lines)
question = "What colour is the boat?"
section = index.query(question, top_k=1)[0]["text"]
agent = Agent(instructions="Use only the Note. If colour is missing, answer unknown.")
print(agent.start(question + "\nNote: " + section))Reference: documentation