-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathapi.ts
More file actions
84 lines (78 loc) · 2.35 KB
/
Copy pathapi.ts
File metadata and controls
84 lines (78 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import {
retrieve as _retrieve,
getDocById as _getDocById,
getDocInfo,
availableLibraries,
listDocs as _listDocs
} from './core/retriever';
import type {
Doc,
DocInfo,
RetrieveOptions,
ListOptions
} from './core/types';
export type { Doc, DocInfo, RetrieveOptions, ListOptions };
/**
* Retrieve docs based on a query. Returns doc content by default.
*
* @example retrieve('bar chart', { library: 'g2', topK: 5 })
* @example retrieve('bar chart', { library: 'g2', content: false }) // metadata only
*
* Legacy positional signature still supported for backwards compatibility.
* @example retrieve('bar chart', 'g2', 5, true)
*/
export function retrieve(query: string, options?: RetrieveOptions): Promise<Doc[]>;
/** @deprecated Use the options-object overload instead. */
export function retrieve(
query: string,
library?: string,
topk?: number,
content?: boolean
): Promise<Doc[]>;
export async function retrieve(
query: string,
libraryOrOpts?: string | RetrieveOptions,
topk = 7,
content = true
): Promise<Doc[]> {
if (typeof libraryOrOpts === 'string' || libraryOrOpts === undefined) {
return await _retrieve(query, { library: libraryOrOpts, topK: topk, content });
}
return await _retrieve(query, libraryOrOpts);
}
/**
* Get a single doc by its exact ID.
*
* @param id The doc ID (e.g. 'g2-mark-bar').
* @param library Optional: restrict the search to a specific library.
* @returns The doc with full content, or undefined if not found.
* @example getDocById('g2-mark-bar')
*/
export function getDocById(id: string, library?: string): Doc | undefined {
return _getDocById(id, library);
}
/**
* Get doc info embedded in the library index.
*
* @param library The library to get info for (default: 'g2').
* @example info('g2')
* @returns The doc info, or undefined if not available.
*/
export function info(library = 'g2'): DocInfo | undefined {
return getDocInfo(library);
}
/**
* Return the list of libraries that have a built index on disk.
* @example libraries() // ['g2', 'g6']
*/
export function libraries(): string[] {
return availableLibraries();
}
/**
* List available docs, optionally filtered by library, category or tags.
* @param options Filter options.
* @example listDocs({ library: 'g2', tags: ['bar'] })
*/
export function listDocs(options: ListOptions = {}): Doc[] {
return _listDocs(options);
}