Knowledge Base QA and Search
How to use knowledge base QA and search in the Platform
Introduction
qa.search
and qa.answer
functions access the knowledge base to answer user questions. Additionally, we provide information about the KBDocument
class, which is essential for understanding the data structure used by qa.search
.
Table of Contents
Using
qa.search
Using
qa.answer
Understanding the
KBDocument
Class
1. Using qa.search
qa.search
The qa.search
function is used to search for information within the knowledge base. It allows you to retrieve relevant documents that contain potential answers to your questions.
How to Use qa.search
qa.search
question
(String): Your question or query.numberOfResults
(Optional, default=3): The number of relevant documents to retrieve.
Returns
results
(List ofKBDocument
objects): A list of relevant documents containing information related to the query.
Example
Suppose you want to find information about "climate change". You can use qa.search
like this:
This will return a list of relevant documents that may contain answers to your question.
2. Using qa.answer
qa.answer
The qa.answer
function is used to generate answers to specific questions based on the retrieved documents from the knowledge base via a large language model.
How to Use qa.answer
qa.answer
question
(String): Your question or query.prompt
(String): Additional context or information to assist in generating an answer.
Returns
answer
(String): The generated answer to the question based on the retrieved documents and provided prompt.
Example
Suppose you want to generate an answer to the question "What are the causes of climate change?". You can use qa.answer
like this:
In the first step, qa.answer
utilizes the qa.search
function to retrieve relevant documents from the database, in the second step, it feeds the documents together with your question and prompt to a large language model in order to provide an answer. This will generate an answer based on the retrieved documents and the generic prompt provided. The full prompt and logic can be seen below.
Source Code for qa.answer
Function:
3. Understanding the KBDocument
Class
KBDocument
ClassThe KBDocument
class is a data structure used within the Platform to represent information retrieved from the knowledge base. It contains the following properties:
answer
(String): This field is empty in the current knowledge base configuration, as the answer generation is handled by an LLM.score
(Double): A numerical value representing the relevance or confidence level of the document.context
(String): The full retrieved document in string form.documentIds
(List of Strings): Unique identifiers for the document.
Example
Here is an example of a KBDocument
object:
In this example, the KBDocument
represents information about the causes of climate change. You can access different fields of the KBDocument
class in Kotlin as follows:
These variables will contain the respective values from the KBDocument
object.
Last updated