Skip to content

Commit 64d0503

Browse files
committed
feat(core): add base retriever interfaces and configuration options
1 parent 82f659d commit 64d0503

File tree

3 files changed

+449
-0
lines changed

3 files changed

+449
-0
lines changed

packages/core/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ export * from './utils/index.ts'
1212
export * from './provider/index.ts'
1313
export * from './generate/index.ts'
1414
export * from './callback/index.ts'
15+
export * from './retrievers/index.ts'
16+
export * from './vector-stores/index.ts'
1517

1618
export function apply(ctx: Context) {
1719
ctx.plugin(CortexLunaService)
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { Document } from '../documents/index.ts'
2+
3+
/**
4+
* Input configuration options for initializing a retriever that extends
5+
* the `BaseRetriever` class. This interface provides base properties
6+
* common to all retrievers, allowing customization of callback functions,
7+
* tagging, metadata, and logging verbosity.
8+
*
9+
* Fields:
10+
*
11+
* - `tags` (optional): An array of strings used to add contextual tags to
12+
* retrieval operations, allowing for easier categorization and tracking.
13+
*
14+
* - `metadata` (optional): A record of key-value pairs to store additional
15+
* contextual information for retrieval operations, which can be useful
16+
* for logging or auditing purposes.
17+
*
18+
*/
19+
export interface RetrieverInput {
20+
tags?: string[]
21+
metadata?: Record<string, unknown>
22+
}
23+
24+
/**
25+
* Interface for a base retriever that defines core functionality for
26+
* retrieving relevant documents from a source based on a query.
27+
*
28+
* The `BaseRetrieverInterface` standardizes the `getRelevantDocuments` method,
29+
* enabling retrieval of documents that match the query criteria.
30+
*
31+
* @template Metadata - The type of metadata associated with each document,
32+
* defaulting to `Record<string, any>`.
33+
*/
34+
export interface Retriever<
35+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
36+
Metadata extends Record<string, any> = Record<string, any>
37+
> {
38+
/**
39+
* Retrieves documents relevant to a given query, allowing optional
40+
* configurations for customization.
41+
*
42+
* @param query - A string representing the query to search for relevant documents.
43+
* @param config - (optional) Configuration options for the retrieval process,
44+
* which may include callbacks and additional context settings.
45+
* @returns A promise that resolves to an array of `DocumentInterface` instances,
46+
* each containing metadata specified by the `Metadata` type parameter.
47+
*/
48+
getRelevantDocuments(query: string): Promise<Document<Metadata>[]>
49+
}

0 commit comments

Comments
 (0)