search
constsearch:object
Type Declaration
Section titled “Type Declaration”file: (
config) =>Middleware=searchFile
Document/knowledge base search with RAG retrieval.
Creates a search.file() middleware for document/knowledge base search.
Two modes:
"tool"(default): registerssearch_knowledgetool — model decides when to search."auto": retrieves every turn using latest user message.
Retrieved chunks are injected into the model context and tracked in
state['search:file:sources'].
Parameters
Section titled “Parameters”config
Section titled “config”Retriever function and options
Returns
Section titled “Returns”Middleware
Example
Section titled “Example”import { search } from "agent-express"import { chromaRetriever } from "@agent-express/search-llamaindex"
agent.use(search.file({ retrieve: chromaRetriever({ sources: ["./docs"], embed: openaiEmbed() }),}))web: (
config) =>Middleware=searchWeb
Web search tool — model calls when needed.
Creates a search.web() middleware that registers a web_search tool.
The model calls the tool when it needs information beyond the knowledge base.
Results are written to state['search:web:results'] for source tracking.
Parameters
Section titled “Parameters”config
Section titled “config”Search provider function
Returns
Section titled “Returns”Middleware
Example
Section titled “Example”import { search } from "agent-express"import { braveProvider } from "@agent-express/search-brave"
agent.use(search.web({ provider: braveProvider({ apiKey }) }))