Errors
Every failure is a RetrievalError with a code, and the original provider error is kept in cause.
The SDK throws one error class, RetrievalError, with a code:
| Code | When |
|---|---|
InvalidArgument |
A bad value, e.g. topK: 0 or a missing API key. |
DimensionMismatch |
A vector does not have the size the store expects. |
Provider |
A model, database or search engine call failed. The original error is in cause. |
import { RetrievalError } from "retrieval-sdk";
try {
await retriever.retrieve(query, {
topK: 10,
abortSignal: AbortSignal.timeout(2_000),
});
} catch (error) {
if (error instanceof RetrievalError && error.code === "Provider") {
console.error(error.cause);
}
throw error;
}
Aborts are never wrapped: an AbortError or TimeoutError passes through unchanged.