Skip to navigation

nemoguardrails.actions.retrieve_relevant_chunks

View as MarkdownOpen in Claude

Module Contents

Functions

NameDescription
retrieve_relevant_chunksRetrieve relevant knowledge chunks and update the context.

Data

log

API

nemoguardrails.actions.retrieve_relevant_chunks.retrieve_relevant_chunks(
context: typing.Optional[dict] = None,
kb: typing.Optional[nemoguardrails.kb.kb.KnowledgeBase] = None,
is_colang_2: typing.Optional[bool] = False
)
async

Retrieve relevant knowledge chunks and update the context.

Example

result = await retrieve_relevant_chunks(context=my_context, kb=my_knowledge_base)
print(result.return_value) # Relevant chunks as a string
print(result.context_updates) # Updated context with relevant chunks

Parameters:

context
Optional[dict]Defaults to None

The context for the execution of the action. Defaults to None.

kb
Optional[KnowledgeBase]Defaults to None

Optional[ KnowledgeBase ] — The KnowledgeBase to search for relevant chunks. Defaults to None.

Returns:

An action result containing the retrieved relevant chunks with context updates:

  • “relevant_chunks” — the relevant chunks as a single string,
  • “relevant_chunks_sep” — the relevant chunks as a list of strings before concatenation,
  • “retrieved_for” — the user message that the chunks were retrieved for.

This action retrieves relevant chunks from the KnowledgeBase based on the user’s last message and updates the context with the information.

nemoguardrails.actions.retrieve_relevant_chunks.log = logging.getLogger(__name__)