Find the matching section
One question, one line
Search should return the section that shares words with the question, and leave the others unread.
The question mentions the ferry, so the ticket line is the one that prints. The apple line and the boat line stay out.
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("How much is the ferry?", top_k=1)[0]["text"])Example explained
- top_k — How many lines to keep. One is enough here.
Reference: documentation