@agentskit/rag β Functions
API functions for @agentskit/rag.
#Function: bm25Score()
bm25Score(
query,documents,options?):RetrievedDocument[]
Defined in: packages/rag/src/rerank.ts:187
Score a set of documents against a query using classic BM25.
Returns new document objects with a finite .score field, sorted descending.
Input documents are never mutated.
#Parameters
#query
string
Search query.
#documents
RetrievedDocument[]
Candidate documents.
#options?
BM25Options = \{\}
Optional BM25 tuning parameters.
#Returns
RetrievedDocument[]
New documents with finite scores in descending order.
#Function: chunkText()
chunkText(
text,options):string[]
Defined in: packages/rag/src/chunker.ts:24
Splits text into non-empty chunks using an optional custom splitter.
#Parameters
#text
string
#options
#Returns
string[]
#Function: createHybridRetriever()
createHybridRetriever(
base,options?):Retriever
Defined in: packages/rag/src/rerank.ts:290
Combine a vector-backed base retriever with a BM25 keyword pass
over the same candidate pool. Final score is a weighted sum of the
two min-max-normalized scores using a finite relative weight pair
that sums to 1 (both zero β 0.5/0.5).
#Parameters
#base
Retriever
Retriever that supplies vector search results.
#options?
HybridRetrieverOptions = \{\}
Candidate pool and relative score weights.
#Returns
Retriever
A retriever with normalized hybrid scores.
#Throws
When candidate scores are invalid or retrieval fails.
#Function: createPartitionedRAG()
createPartitionedRAG(
config):RAG
Defined in: packages/rag/src/partitioned.ts:25
Compose createRAG with metadata isolation; stores must faithfully preserve metadata.
#Parameters
#config
#Returns
#Function: createRAG()
createRAG(
config):RAG
Defined in: packages/rag/src/rag.ts:62
Creates a retriever that chunks, embeds, stores, and searches documents.
#Parameters
#config
Store, embedding function, and optional chunking and search settings.
#Returns
A RAG retriever with an ingest method.
#Example
const rag = createRAG({ store, embed })
await rag.ingest([{ id: 'guide', content: 'Install the package.' }])
const results = await rag.retrieve({ query: 'How do I install it?' })#Function: createRerankedRetriever()
createRerankedRetriever(
base,options?):Retriever
Defined in: packages/rag/src/rerank.ts:123
Wrap any base Retriever with a reranker. Typical flow:
- Vector search returns ~20 candidates (
candidatePool) rerankre-scores them with a stronger signal (Cohere Rerank, BGE cross-encoder, or BM25 for keyword-aware hybrid search)- Top
topKare returned
#Parameters
#base
Retriever
Retriever that supplies the candidate documents.
#options?
RerankedRetrieverOptions = \{\}
Reranker and candidate limits.
#Returns
Retriever
A retriever that returns reranked documents.
#Throws
When reranking returns invalid results or fails.
#Function: jinaReranker()
jinaReranker(
options):RerankFn
Defined in: packages/rag/src/rerankers/jina.ts:38
Jina AI cross-encoder reranker. Drop-in RerankFn for
createRerankedRetriever.
#Parameters
#options
API key, model, and optional request settings.
#Returns
A reranking function for retrieved documents.
#Throws
When the request fails or the response is invalid.
#Function: loadConfluencePage()
loadConfluencePage(
pageId,options):Promise<InputDocument[]>
Defined in: packages/rag/src/loaders/documents.ts:245
Loads a Confluence page as a document.
#Parameters
#pageId
string
Confluence page identifier.
#options
Page identifier, credentials, and loader limits.
#Returns
Promise<InputDocument[]>
The page content as a document.
#Throws
When the request or response parsing fails.
#Function: loadDropbox()
loadDropbox(
options):Promise<InputDocument[]>
Defined in: packages/rag/src/loaders/cloud.ts:110
Lists and loads eligible files from Dropbox.
#Parameters
#options
Access token, path, filtering, and loader limits.
#Returns
Promise<InputDocument[]>
Successfully loaded files; fails if every eligible download fails.
#Throws
When listing fails or all eligible downloads fail.
#Function: loadGcs()
loadGcs(
options):Promise<InputDocument[]>
Defined in: packages/rag/src/loaders/cloud.ts:33
Lists and loads eligible objects from a Google Cloud Storage bucket.
#Parameters
#options
Bucket, credentials, filtering, and loader limits.
#Returns
Promise<InputDocument[]>
Successfully loaded objects; fails if every eligible download fails.
#Throws
When listing fails or all eligible downloads fail.
#Function: loadGitHubFile()
loadGitHubFile(
owner,repo,path,options?):Promise<InputDocument[]>
Defined in: packages/rag/src/loaders/documents.ts:72
Loads one GitHub file as a document.
#Parameters
#owner
string
Repository owner.
#repo
string
Repository name.
#path
string
Repository-relative file path.
#options?
GitHubLoaderOptions = \{\}
GitHub credentials and loader limits.
#Returns
Promise<InputDocument[]>
The loaded file as a document.
#Throws
When the request or response parsing fails.
#Function: loadGitHubTree()
loadGitHubTree(
owner,repo,options?):Promise<InputDocument[]>
Defined in: packages/rag/src/loaders/documents.ts:110
Loads matching files from a GitHub repository tree.
#Parameters
#owner
string
Repository owner.
#repo
string
Repository name.
#options?
GitHubTreeOptions = \{\}
Repository, filtering, credentials, and loader limits.
#Returns
Promise<InputDocument[]>
Successfully loaded documents; fails if every eligible download fails.
#Throws
When listing fails or all eligible downloads fail.
#Function: loadGoogleDriveFile()
loadGoogleDriveFile(
fileId,options):Promise<InputDocument[]>
Defined in: packages/rag/src/loaders/documents.ts:279
Loads an exported Google Drive file as a document.
#Parameters
#fileId
string
Google Drive file identifier.
#options
File identifier, credentials, and loader limits.
#Returns
Promise<InputDocument[]>
The file content as a document.
#Throws
When the request or response parsing fails.
#Function: loadNotionPage()
loadNotionPage(
pageId,options):Promise<InputDocument[]>
Defined in: packages/rag/src/loaders/documents.ts:180
Loads supported text blocks from a Notion page, following child pagination.
#Parameters
#pageId
string
Notion page identifier.
#options
Page identifier, credentials, and loader limits.
#Returns
Promise<InputDocument[]>
The page content as a document.
#Throws
When loading or pagination fails.
#Function: loadOneDrive()
loadOneDrive(
options):Promise<InputDocument[]>
Defined in: packages/rag/src/loaders/cloud.ts:197
Lists and loads eligible files from OneDrive, including nested folders.
#Parameters
#options
Access token, folder, filtering, and loader limits.
#Returns
Promise<InputDocument[]>
Successfully loaded files; fails if every eligible download fails.
#Throws
When listing fails or all eligible downloads fail.
#Function: loadPdf()
loadPdf(
url,options):Promise<InputDocument[]>
Defined in: packages/rag/src/loaders/documents.ts:305
Fetches a PDF and extracts its text into a document.
#Parameters
#url
string
URL of the PDF.
#options
Fetch and loader limits.
#Returns
Promise<InputDocument[]>
The extracted PDF document.
#Throws
When fetching or parsing fails.
#Function: loadS3()
loadS3(
options):Promise<InputDocument[]>
Defined in: packages/rag/src/loaders/s3.ts:61
Lists and loads eligible objects from S3.
#Parameters
#options
Bucket, client or commands, filtering, and loader limits.
#Returns
Promise<InputDocument[]>
Successfully loaded objects; fails if every eligible download fails.
#Throws
When listing fails or all eligible downloads fail.
#Function: loadUrl()
loadUrl(
url,options?):Promise<InputDocument[]>
Defined in: packages/rag/src/loaders/documents.ts:44
Fetches a URL and returns its supported content as one or more documents.
#Parameters
#url
string
URL to fetch.
#options?
UrlLoaderOptions = \{\}
Origin allowlist, fetch, timeout, and content-size limits.
#Returns
Promise<InputDocument[]>
Documents extracted from the response.
#Throws
When fetching, reading, or parsing the response fails.
#Example
const [document] = await loadUrl('https://example.com/guide', {
allowedOrigins: ['https://example.com'],
})#Function: voyageReranker()
voyageReranker(
options):RerankFn
Defined in: packages/rag/src/rerankers/voyage.ts:39
Voyage AI cross-encoder reranker. Drop-in RerankFn for
createRerankedRetriever.
#Parameters
#options
API key, model, and optional request settings.
#Returns
A reranking function for retrieved documents.
#Throws
When the request fails or the response is invalid.