Skip to main content
Knowledge bases connect an agent to external material such as enterprise documents, product guides, and support policies. In VeADK Java, the recommended path is 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

  1. Choose a backend: opensearch or viking.
  2. Configure the index, collection, and recall size with KnowledgeBase.builder().
  3. Ingest material with addFromText(...), addFromFiles(...), addFromDirectory(...), or addDoc(...).
  4. Attach the service with Agent.builder().knowledgebase(knowledgeBase).
  5. Run the conversation with Runner; the model can call the auto-injected loadKnowledgebase tool 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.
Common environment variables:

Viking Example

Viking Knowledgebase is useful when your documents live in a Volcengine-managed knowledge collection. Use appName(...) 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.
Common environment variables: 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:
When you use VeADK Java’s Agent.builder().knowledgebase(...), you usually do not need to add this tool yourself.

Troubleshooting

Last modified on October 20, 2026