KnowledgeBase plus Agent.builder().knowledgebase(...): attach the service to the agent, and VeADK automatically injects the loadKnowledgebase tool so the model can retrieve grounded material before answering.
Flow
- Choose a backend:
opensearchorviking. - Configure the index, collection, and recall size with
KnowledgeBase.builder(). - Ingest material with
addFromText(...),addFromFiles(...),addFromDirectory(...), oraddDoc(...). - Attach the service with
Agent.builder().knowledgebase(knowledgeBase). - Run the conversation with
Runner; the model can call the auto-injectedloadKnowledgebasetool when it needs external material.
OpenSearch Example
OpenSearch is useful when you want to chunk local text, files, or directories into vectors and store them in your own OpenSearch index. It uses an Ark embedding model to generate vectors, so an embedding API key is required.Viking Example
Viking Knowledgebase is useful when your documents live in a Volcengine-managed knowledge collection. UseappName(...) to select the collection. Search can use DATABASE_VIKING_API_KEY; collection management, document ingestion, and TOS-backed addDoc still require AK/SK or IAM credentials.
You can also pass the search API key directly with
vikingApiKey(...); explicit SDK parameters take precedence over matching environment variables.
Backends And Ingestion
KnowledgeBase also provides async methods such as addFromTextAsync(...), addFromFilesAsync(...), addDocAsync(...), and searchAsync(...) for RxJava-based flows.
Auto Tool Injection
Agent.builder().knowledgebase(service) accepts any service that implements BaseKnowledgebaseService. During agent construction, if the tool list does not already contain a tool named loadKnowledgebase, VeADK creates a LoadKnowledgebaseTool and adds it to the tool list. The tool converts the model’s query argument into a searchKnowledgebase(query) call and returns the retrieved chunks to the model.
If you use ADK Java’s LlmAgent.builder() directly, configure the tool manually:
Agent.builder().knowledgebase(...), you usually do not need to add this tool yourself.