How-to: Using the knowledge base with the chatbotΒΆ
OverviewΒΆ
The semantic_state_aggregator can be used to provide context to the chatbot and ground the dialogue to the current state of the robot and its environment.
The semantic_state_aggregator is configured with a list of predicates
and classes from the knowledge base. The
semantic_state_aggregator performs recurrent background queries to the knowledge base,
and filters the triples according to the configuration:
only the triples that have as subject and object an instance of
one of the specified classes, and as predicate one of the specified predicates, are kept.
The semantic_state_aggregator tracks changes in the filtered knowledge,
and when queried for updates, it provides the facts that have been added or removed
since the last update, transforming them into natural language sentences.
For example, assume that the following facts are added to the knowledge base:
book_123 rdf:type dbr:Book
book_123 isOn table_789
mug_456 rdf:type dbr:Mug
table_789 rdf:type dbr:Table
If the semantic_state_aggregator is configured to track the classes
dbr:Book and dbr:Mug, and the predicate isOn, it will generate the following
natural language sentences:
book_123 is a Book, isOn table_789.
mug_456 is a Mug.
table_789 is a Table.
When the knowledge base is updated to remove the facts book_123 isOn table_789 and
mug_456 rdf:type dbr:Mug, the
semantic_state_aggregator will generate the following natural language sentences:
book_123 no longer isOn table_789.
mug_456 is no longer in the environment
UsageΒΆ
Users are not expected to interact directly with the semantic_state_aggregator, although this is possible and explained in the subsection below.
The chatbot_ollama
is designed to use the semantic_state_aggregator as a source of context for the dialogues it manages.
Each time the chatbot generates a response, it first queries the semantic_state_aggregator
for updates, and includes them in the prompt sent to the LLM as updates in the robotβs knowledge.
To use the semantic_state_aggregator with the chatbot_ollama,
use the chat (see How-to: Dialogue management).
Within the role.configuration json string field of the chat, include
the following entries:
"semantic_state_aggregator": {
"filter_classes_kb": ["Robot", "dbr:Chair", "dbr:Book"],
"filter_predicates_kb": ["isOn", "sees"]}
Advanced usageΒΆ
The semantic state aggregator can also be used directly, without going through the chatbot. For example, applications may need to get updates from the knowledge base in the form of natural language sentences (e.g., for LLM-based components).
In this case, the semantic_state_aggregator must first be configured.
The configuration is performed through the service /semantic_state_aggregator/configure.
An ID and the lists of classes and predicates to track must be provided.
The service /semantic_state_aggregator/get_updates can be used to obtain the updates. The ID must be provided and the service will return a list of strings with the timestamped updates.
ParametersΒΆ
Several parameters control the behavior of the semantic_state_aggregator:
active_id_timeout: To save computation, thesemantic_state_aggregatoronly tracks the facts for a given ID if it has been recently requested (within the lastactive_id_timeoutseconds). If no request has been received for a given ID within that time, the tracking is stopped. This can be set to 0 to always track the knowledge for all configured IDs. Default: 600.0 seconds.timer_period: Thesemantic_state_aggregatorperforms a query to the knowledge base everytimer_periodseconds to check for updates. Default: 3.0 seconds.monitor_all_changes: If true, thesemantic_state_aggregatorwill monitor all the changes in the knowledge base between queries. For example, between two queries to get updates from thesemantic_state_aggregator, if an object disappears and reappears, thesemantic_state_aggregatorwill include in the provided facts that the object was removed and later added. If false, it will not report any change for that fact. Default: false.