@convex-dev/rag 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +371 -0
  3. package/dist/client/_generated/_ignore.d.ts +1 -0
  4. package/dist/client/_generated/_ignore.d.ts.map +1 -0
  5. package/dist/client/_generated/_ignore.js +3 -0
  6. package/dist/client/_generated/_ignore.js.map +1 -0
  7. package/dist/client/defaultChunker.d.ts +15 -0
  8. package/dist/client/defaultChunker.d.ts.map +1 -0
  9. package/dist/client/defaultChunker.js +148 -0
  10. package/dist/client/defaultChunker.js.map +1 -0
  11. package/dist/client/fileUtils.d.ts +24 -0
  12. package/dist/client/fileUtils.d.ts.map +1 -0
  13. package/dist/client/fileUtils.js +179 -0
  14. package/dist/client/fileUtils.js.map +1 -0
  15. package/dist/client/index.d.ts +442 -0
  16. package/dist/client/index.d.ts.map +1 -0
  17. package/dist/client/index.js +597 -0
  18. package/dist/client/index.js.map +1 -0
  19. package/dist/client/types.d.ts +29 -0
  20. package/dist/client/types.d.ts.map +1 -0
  21. package/dist/client/types.js +2 -0
  22. package/dist/client/types.js.map +1 -0
  23. package/dist/component/_generated/api.d.ts +439 -0
  24. package/dist/component/_generated/api.d.ts.map +1 -0
  25. package/dist/component/_generated/api.js +22 -0
  26. package/dist/component/_generated/api.js.map +1 -0
  27. package/dist/component/_generated/dataModel.d.ts +60 -0
  28. package/dist/component/_generated/server.d.ts +149 -0
  29. package/dist/component/_generated/server.d.ts.map +1 -0
  30. package/dist/component/_generated/server.js +74 -0
  31. package/dist/component/_generated/server.js.map +1 -0
  32. package/dist/component/chunks.d.ts +139 -0
  33. package/dist/component/chunks.d.ts.map +1 -0
  34. package/dist/component/chunks.js +413 -0
  35. package/dist/component/chunks.js.map +1 -0
  36. package/dist/component/convex.config.d.ts +3 -0
  37. package/dist/component/convex.config.d.ts.map +1 -0
  38. package/dist/component/convex.config.js +6 -0
  39. package/dist/component/convex.config.js.map +1 -0
  40. package/dist/component/embeddings/importance.d.ts +21 -0
  41. package/dist/component/embeddings/importance.d.ts.map +1 -0
  42. package/dist/component/embeddings/importance.js +67 -0
  43. package/dist/component/embeddings/importance.js.map +1 -0
  44. package/dist/component/embeddings/index.d.ts +23 -0
  45. package/dist/component/embeddings/index.d.ts.map +1 -0
  46. package/dist/component/embeddings/index.js +54 -0
  47. package/dist/component/embeddings/index.js.map +1 -0
  48. package/dist/component/embeddings/tables.d.ts +39 -0
  49. package/dist/component/embeddings/tables.d.ts.map +1 -0
  50. package/dist/component/embeddings/tables.js +53 -0
  51. package/dist/component/embeddings/tables.js.map +1 -0
  52. package/dist/component/entries.d.ts +167 -0
  53. package/dist/component/entries.d.ts.map +1 -0
  54. package/dist/component/entries.js +409 -0
  55. package/dist/component/entries.js.map +1 -0
  56. package/dist/component/filters.d.ts +46 -0
  57. package/dist/component/filters.d.ts.map +1 -0
  58. package/dist/component/filters.js +72 -0
  59. package/dist/component/filters.js.map +1 -0
  60. package/dist/component/namespaces.d.ts +131 -0
  61. package/dist/component/namespaces.d.ts.map +1 -0
  62. package/dist/component/namespaces.js +222 -0
  63. package/dist/component/namespaces.js.map +1 -0
  64. package/dist/component/schema.d.ts +1697 -0
  65. package/dist/component/schema.d.ts.map +1 -0
  66. package/dist/component/schema.js +88 -0
  67. package/dist/component/schema.js.map +1 -0
  68. package/dist/component/search.d.ts +20 -0
  69. package/dist/component/search.d.ts.map +1 -0
  70. package/dist/component/search.js +69 -0
  71. package/dist/component/search.js.map +1 -0
  72. package/dist/package.json +3 -0
  73. package/dist/react/index.d.ts +2 -0
  74. package/dist/react/index.d.ts.map +1 -0
  75. package/dist/react/index.js +6 -0
  76. package/dist/react/index.js.map +1 -0
  77. package/dist/shared.d.ts +479 -0
  78. package/dist/shared.d.ts.map +1 -0
  79. package/dist/shared.js +98 -0
  80. package/dist/shared.js.map +1 -0
  81. package/package.json +97 -0
  82. package/src/client/_generated/_ignore.ts +1 -0
  83. package/src/client/defaultChunker.test.ts +243 -0
  84. package/src/client/defaultChunker.ts +183 -0
  85. package/src/client/fileUtils.ts +179 -0
  86. package/src/client/index.test.ts +475 -0
  87. package/src/client/index.ts +1125 -0
  88. package/src/client/setup.test.ts +28 -0
  89. package/src/client/types.ts +69 -0
  90. package/src/component/_generated/api.d.ts +439 -0
  91. package/src/component/_generated/api.js +23 -0
  92. package/src/component/_generated/dataModel.d.ts +60 -0
  93. package/src/component/_generated/server.d.ts +149 -0
  94. package/src/component/_generated/server.js +90 -0
  95. package/src/component/chunks.test.ts +915 -0
  96. package/src/component/chunks.ts +555 -0
  97. package/src/component/convex.config.ts +7 -0
  98. package/src/component/embeddings/importance.test.ts +249 -0
  99. package/src/component/embeddings/importance.ts +75 -0
  100. package/src/component/embeddings/index.test.ts +482 -0
  101. package/src/component/embeddings/index.ts +99 -0
  102. package/src/component/embeddings/tables.ts +114 -0
  103. package/src/component/entries.test.ts +341 -0
  104. package/src/component/entries.ts +546 -0
  105. package/src/component/filters.ts +119 -0
  106. package/src/component/namespaces.ts +299 -0
  107. package/src/component/schema.ts +106 -0
  108. package/src/component/search.test.ts +445 -0
  109. package/src/component/search.ts +97 -0
  110. package/src/component/setup.test.ts +5 -0
  111. package/src/react/index.ts +7 -0
  112. package/src/shared.ts +247 -0
  113. package/src/vitest.config.ts +7 -0
@@ -0,0 +1,442 @@
1
+ import type { EmbeddingModelV1 } from "@ai-sdk/provider";
2
+ import { generateText, type CoreMessage } from "ai";
3
+ import { type FunctionArgs, type FunctionReturnType, type GenericActionCtx, type GenericDataModel, type GenericMutationCtx, type PaginationOptions, type PaginationResult, type RegisteredAction, type RegisteredMutation } from "convex/server";
4
+ import { type Value } from "convex/values";
5
+ import { vEntryId, vNamespaceId, type Chunk, type Entry, type EntryFilterValues, type EntryId, type Namespace, type NamespaceId, type SearchEntry, type SearchResult, type Status } from "../shared.js";
6
+ import { type RAGComponent, type RunActionCtx, type RunMutationCtx, type RunQueryCtx } from "./types.js";
7
+ import { type ChunkerAction, type OnComplete, type OnCompleteNamespace } from "../shared.js";
8
+ import { defaultChunker } from "./defaultChunker.js";
9
+ export { defaultChunker, vEntryId, vNamespaceId };
10
+ export type { ChunkerAction, Entry, EntryId, RAGComponent, NamespaceId, OnComplete, OnCompleteNamespace, SearchEntry, SearchResult, Status, };
11
+ export { type VEntry, type VSearchEntry, vEntry, vSearchEntry, vSearchResult, vOnCompleteArgs, } from "../shared.js";
12
+ export { contentHashFromArrayBuffer, guessMimeTypeFromExtension, guessMimeTypeFromContents, } from "./fileUtils.js";
13
+ type Importance = number;
14
+ export declare class RAG<FitlerSchemas extends Record<string, Value> = Record<string, Value>, EntryMetadata extends Record<string, Value> = Record<string, Value>> {
15
+ component: RAGComponent;
16
+ options: {
17
+ embeddingDimension: number;
18
+ textEmbeddingModel: EmbeddingModelV1<string>;
19
+ filterNames?: FilterNames<FitlerSchemas>;
20
+ };
21
+ /**
22
+ * A component to use for Retrieval-Augmented Generation.
23
+ * Create one for each model and embedding dimension you want to use.
24
+ * When migrating between models / embedding lengths, create multiple
25
+ * instances and do your `add`s with the appropriate instance, and searches
26
+ * against the appropriate instance to get results with those parameters.
27
+ *
28
+ * The filterNames need to match the names of the filters you provide when
29
+ * adding and when searching. Use the type parameter to make this type safe.
30
+ *
31
+ * The second type parameter makes the entry metadata type safe. E.g. you can
32
+ * do rag.add(ctx, {
33
+ * namespace: "my-namespace",
34
+ * metadata: {
35
+ * source: "website" as const,
36
+ * },
37
+ * })
38
+ * and then entry results will have the metadata type `{ source: "website" }`.
39
+ */
40
+ constructor(component: RAGComponent, options: {
41
+ embeddingDimension: number;
42
+ textEmbeddingModel: EmbeddingModelV1<string>;
43
+ filterNames?: FilterNames<FitlerSchemas>;
44
+ });
45
+ /**
46
+ * Add an entry to the store. It will chunk the text with the `defaultChunker`
47
+ * if you don't provide chunks, and embed the chunks with the default model
48
+ * if you don't provide chunk embeddings.
49
+ *
50
+ * If you provide a key, it will replace an existing entry with the same key.
51
+ * If you don't provide a key, it will always create a new entry.
52
+ * If you provide a contentHash, it will deduplicate the entry if it already exists.
53
+ * The filterValues you provide can be used later to search for it.
54
+ */
55
+ add(ctx: RunMutationCtx, args: NamespaceSelection & EntryArgs<FitlerSchemas, EntryMetadata> & ({
56
+ /**
57
+ * You can provide your own chunks to finely control the splitting.
58
+ * These can also include your own provided embeddings, so you can
59
+ * control what content is embedded, which can differ from the content
60
+ * in the chunks.
61
+ */
62
+ chunks: Iterable<InputChunk> | AsyncIterable<InputChunk>;
63
+ /** @deprecated You cannot specify both chunks and text currently. */
64
+ text?: undefined;
65
+ } | {
66
+ /**
67
+ * If you don't provide chunks, we will split the text into chunks
68
+ * using the default chunker and embed them with the default model.
69
+ */
70
+ text: string;
71
+ /** @deprecated You cannot specify both chunks and text currently. */
72
+ chunks?: undefined;
73
+ })): Promise<{
74
+ entryId: EntryId;
75
+ status: Status;
76
+ created: boolean;
77
+ replacedVersion: Entry<FitlerSchemas, EntryMetadata> | null;
78
+ }>;
79
+ /**
80
+ * Add an entry to the store asynchronously.
81
+ *
82
+ * This is useful if you want to chunk the entry in a separate process,
83
+ * or if you want to chunk the entry in a separate process.
84
+ *
85
+ * The chunkerAction is a function that splits the entry into chunks and
86
+ * embeds them. It should be passed as internal.foo.myChunkerAction
87
+ * e.g.
88
+ * ```ts
89
+ * export const myChunkerAction = rag.defineChunkerAction(async (ctx, args) => {
90
+ * // ...
91
+ * return { chunks: [chunk1, chunk2, chunk3] };
92
+ * });
93
+ *
94
+ * // in your mutation
95
+ * const entryId = await rag.addAsync(ctx, {
96
+ * key: "myfile.txt",
97
+ * namespace: "my-namespace",
98
+ * chunkerAction: internal.foo.myChunkerAction,
99
+ * });
100
+ * ```
101
+ */
102
+ addAsync(ctx: RunMutationCtx, args: NamespaceSelection & EntryArgs<FitlerSchemas, EntryMetadata> & {
103
+ /**
104
+ * A function that splits the entry into chunks and embeds them.
105
+ * This should be passed as internal.foo.myChunkerAction
106
+ * e.g.
107
+ * ```ts
108
+ * export const myChunkerAction = rag.defineChunkerAction();
109
+ *
110
+ * // in your mutation
111
+ * const entryId = await rag.addAsync(ctx, {
112
+ * key: "myfile.txt",
113
+ * namespace: "my-namespace",
114
+ * chunker: internal.foo.myChunkerAction,
115
+ * });
116
+ */
117
+ chunkerAction: ChunkerAction;
118
+ }): Promise<{
119
+ entryId: EntryId;
120
+ status: "ready" | "pending";
121
+ }>;
122
+ /**
123
+ * Search for entries in a namespace with configurable filters.
124
+ * You can provide a query string or target embedding, as well as search
125
+ * parameters to filter and constrain the results.
126
+ */
127
+ search(ctx: RunActionCtx, args: {
128
+ /**
129
+ * The namespace to search in. e.g. a userId if entries are per-user.
130
+ * Note: it will only match entries in the namespace that match the
131
+ * modelId, embedding dimension, and filterNames of the RAG instance.
132
+ */
133
+ namespace: string;
134
+ /**
135
+ * The query to search for. Optional if embedding is provided.
136
+ */
137
+ query?: string;
138
+ } & SearchOptions<FitlerSchemas>): Promise<{
139
+ results: SearchResult[];
140
+ text: string;
141
+ entries: SearchEntry<FitlerSchemas, EntryMetadata>[];
142
+ }>;
143
+ /**
144
+ * Generate text based on Retrieval-Augmented Generation.
145
+ *
146
+ * This will search for entries in the namespace based on the prompt and use
147
+ * the results as context to generate text, using the search options args.
148
+ * You can override the default "system" message to provide instructions on
149
+ * using the context and answering in the appropriate style.
150
+ * You can provide "messages" in addition to the prompt to provide
151
+ * extra context / conversation history.
152
+ */
153
+ generateText(ctx: RunActionCtx, args: {
154
+ /**
155
+ * The search options to use for context search, including the namespace.
156
+ */
157
+ search: SearchOptions<FitlerSchemas> & {
158
+ /**
159
+ * The namespace to search in. e.g. a userId if entries are per-user.
160
+ */
161
+ namespace: string;
162
+ };
163
+ /**
164
+ * Required. The prompt to use for context search, as well as the final
165
+ * message to the LLM when generating text.
166
+ * Can be used along with "messages"
167
+ */
168
+ prompt: string;
169
+ /**
170
+ * Additional messages to add to the context. Can be provided in addition
171
+ * to the prompt, in which case it will precede the prompt.
172
+ */
173
+ messages?: CoreMessage[];
174
+ } & Parameters<typeof generateText>[0]): Promise<Awaited<ReturnType<typeof generateText>> & {
175
+ context: {
176
+ results: SearchResult[];
177
+ text: string;
178
+ entries: SearchEntry<FitlerSchemas, EntryMetadata>[];
179
+ };
180
+ }>;
181
+ /**
182
+ * List all entries in a namespace.
183
+ */
184
+ list(ctx: RunQueryCtx, args: {
185
+ namespaceId: NamespaceId;
186
+ paginationOpts: PaginationOptions;
187
+ order?: "desc" | "asc";
188
+ status?: Status;
189
+ }): Promise<PaginationResult<Entry<FitlerSchemas, EntryMetadata>>>;
190
+ /**
191
+ * Get entry metadata by its id.
192
+ */
193
+ getEntry(ctx: RunQueryCtx, args: {
194
+ entryId: EntryId;
195
+ }): Promise<Entry<FitlerSchemas, EntryMetadata> | null>;
196
+ /**
197
+ * Find an existing entry by its content hash, which you can use to copy
198
+ * new results into a new entry when migrating, or avoiding duplicating work
199
+ * when updating content.
200
+ */
201
+ findExistingEntryByContentHash(ctx: RunQueryCtx, args: {
202
+ namespace: string;
203
+ key: string;
204
+ /** The hash of the entry contents to try to match. */
205
+ contentHash: string;
206
+ }): Promise<Entry<FitlerSchemas, EntryMetadata> | null>;
207
+ /**
208
+ * Get a namespace that matches the modelId, embedding dimension, and
209
+ * filterNames of the RAG instance. If it doesn't exist, it will be created.
210
+ */
211
+ getOrCreateNamespace(ctx: RunMutationCtx, args: {
212
+ /**
213
+ * The namespace to get or create. e.g. a userId if entries are per-user.
214
+ */
215
+ namespace: string;
216
+ /**
217
+ * If it isn't in existence, what the new namespace status should be.
218
+ */
219
+ status?: "pending" | "ready";
220
+ /**
221
+ * This will be called when then namespace leaves the "pending" state.
222
+ * Either if the namespace is created or if the namespace is replaced
223
+ * along the way.
224
+ */
225
+ onComplete?: OnCompleteNamespace;
226
+ }): Promise<{
227
+ namespaceId: NamespaceId;
228
+ status: "pending" | "ready";
229
+ }>;
230
+ /**
231
+ * Get a namespace that matches the modelId, embedding dimension, and
232
+ * filterNames of the RAG instance. If it doesn't exist, it will return null.
233
+ */
234
+ getNamespace(ctx: RunQueryCtx, args: {
235
+ namespace: string;
236
+ }): Promise<Namespace | null>;
237
+ /**
238
+ * List all chunks for an entry, paginated.
239
+ */
240
+ listChunks(ctx: RunQueryCtx, args: {
241
+ paginationOpts: PaginationOptions;
242
+ entryId: EntryId;
243
+ }): Promise<PaginationResult<Chunk>>;
244
+ /**
245
+ * Delete an entry and all its chunks.
246
+ */
247
+ delete(ctx: RunMutationCtx, args: {
248
+ entryId: EntryId;
249
+ }): Promise<void>;
250
+ /**
251
+ * Define a function that can be provided to the `onComplete` parameter of
252
+ * `add` or `addAsync` like:
253
+ * ```ts
254
+ * const onComplete = rag.defineOnComplete(async (ctx, args) => {
255
+ * // ...
256
+ * });
257
+ *
258
+ * // in your mutation
259
+ * await rag.add(ctx, {
260
+ * namespace: "my-namespace",
261
+ * onComplete: internal.foo.onComplete,
262
+ * });
263
+ * ```
264
+ * It will be called when the entry is no longer "pending".
265
+ * This is usually when it's "ready" but it can be "replaced" if a newer
266
+ * entry is ready before this one.
267
+ */
268
+ defineOnComplete<DataModel extends GenericDataModel>(fn: (ctx: GenericMutationCtx<DataModel>, args: FunctionArgs<OnComplete<FitlerSchemas, EntryMetadata>>) => Promise<void>): RegisteredMutation<"internal", FunctionArgs<OnComplete<FitlerSchemas, EntryMetadata>>, null>;
269
+ /**
270
+ * Define a function that can be provided to the `chunkerAction` parameter of
271
+ * `addAsync` like:
272
+ * ```ts
273
+ * const chunkerAction = rag.defineChunkerAction(async (ctx, args) => {
274
+ * // ...
275
+ * });
276
+ *
277
+ * // in your mutation
278
+ * const entryId = await rag.addAsync(ctx, {
279
+ * key: "myfile.txt",
280
+ * namespace: "my-namespace",
281
+ * chunkerAction: internal.foo.myChunkerAction,
282
+ * });
283
+ * ```
284
+ * It will be called when the entry is added, or when the entry is replaced
285
+ * along the way.
286
+ */
287
+ defineChunkerAction<DataModel extends GenericDataModel>(fn: (ctx: GenericActionCtx<DataModel>, args: {
288
+ namespace: Namespace;
289
+ entry: Entry<FitlerSchemas, EntryMetadata>;
290
+ }) => AsyncIterable<InputChunk> | Promise<{
291
+ chunks: InputChunk[];
292
+ }>): RegisteredAction<"internal", FunctionArgs<ChunkerAction>, FunctionReturnType<ChunkerAction>>;
293
+ }
294
+ /**
295
+ * Rank results from multiple results, e.g. from vector search and text search.
296
+ * Uses the "Recriprocal Rank Fusion" algorithm.
297
+ * @param sortedResults The results arrays ordered by most important first.
298
+ */
299
+ export declare function hybridRank<T extends string>(sortedResults: T[][], opts?: {
300
+ /**
301
+ * A constant used to change the bias of the top results in each list vs.
302
+ * results in the middle of multiple lists.
303
+ * A higher k means less of a bias toward the top few results.
304
+ */
305
+ k: number;
306
+ /**
307
+ * The weights of each sortedResults array.
308
+ * Used to prefer results from one sortedResults array over another.
309
+ */
310
+ weights: number[];
311
+ /**
312
+ * The cutoff score for a result to be returned.
313
+ */
314
+ cutoffScore?: number;
315
+ }): T[];
316
+ type MastraChunk = {
317
+ text: string;
318
+ metadata: Record<string, Value>;
319
+ embedding?: Array<number>;
320
+ };
321
+ type LangChainChunk = {
322
+ id?: string;
323
+ pageContent: string;
324
+ metadata: Record<string, Value>;
325
+ embedding?: Array<number>;
326
+ };
327
+ export type InputChunk = string | ((MastraChunk | LangChainChunk) & {
328
+ keywords?: string;
329
+ });
330
+ type FilterNames<FiltersSchemas extends Record<string, Value>> = (keyof FiltersSchemas & string)[];
331
+ type NamespaceSelection = {
332
+ /**
333
+ * A namespace is an isolated search space - no search can access entities
334
+ * in other namespaces. Often this is used to segment user documents from
335
+ * each other, but can be an arbitrary delineation. All filters apply
336
+ * within a namespace.
337
+ */
338
+ namespace: string;
339
+ } | {
340
+ /**
341
+ * The namespaceId, which is returned when creating a namespace
342
+ * or looking it up.
343
+ * There can be multiple namespaceIds for the same namespace, e.g.
344
+ * one for each modelId, embedding dimension, and filterNames.
345
+ * Each of them have a separate "status" and only one is ever "ready" for
346
+ * any given "namespace" (e.g. a userId).
347
+ */
348
+ namespaceId: NamespaceId;
349
+ };
350
+ type EntryArgs<FitlerSchemas extends Record<string, Value>, EntryMetadata extends Record<string, Value>> = {
351
+ /**
352
+ * This key allows replacing an existing entry by key.
353
+ * Within a namespace, there will only be one "ready" entry per key.
354
+ * When adding a new one, it will start as "pending" and after all
355
+ * chunks are added, it will be promoted to "ready".
356
+ */
357
+ key?: string | undefined;
358
+ /**
359
+ * The title of the entry. Used for default prompting to contextualize
360
+ * the entry results. Also may be used for keyword search in the future.
361
+ */
362
+ title?: string;
363
+ /**
364
+ * Metadata about the entry that is not indexed or filtered or searched.
365
+ * Provided as a convenience to store associated information, such as
366
+ * the storageId or url to the source material.
367
+ */
368
+ metadata?: EntryMetadata;
369
+ /**
370
+ * Filters to apply to the entry. These can be OR'd together in search.
371
+ * To represent AND logic, your filter can be an object or array with
372
+ * multiple values. e.g. saving the result with:
373
+ * `{ name: "categoryAndPriority", value: ["articles", "high"] }`
374
+ * and searching with the same value will return entries that match that
375
+ * value exactly.
376
+ */
377
+ filterValues?: EntryFilterValues<FitlerSchemas>[];
378
+ /**
379
+ * The importance of the entry. This is used to scale the vector search
380
+ * score of each chunk.
381
+ */
382
+ importance?: Importance;
383
+ /**
384
+ * The hash of the entry contents. This is used to deduplicate entries.
385
+ * You can look up existing entries by content hash within a namespace.
386
+ * It will also return an existing entry if you add an entry with the
387
+ * same content hash.
388
+ */
389
+ contentHash?: string;
390
+ /**
391
+ * A function that is called when the entry is added.
392
+ */
393
+ onComplete?: OnComplete;
394
+ };
395
+ type SearchOptions<FitlerSchemas extends Record<string, Value>> = {
396
+ /**
397
+ * The embedding to search for. If provided, it will be used instead
398
+ * of the query for vector search.
399
+ */
400
+ embedding?: Array<number>;
401
+ /**
402
+ * Filters to apply to the search. These are OR'd together. To represent
403
+ * AND logic, your filter can be an object or array with multiple values.
404
+ * e.g. `[{ category: "articles" }, { priority: "high" }]` will return
405
+ * entries that have "articles" category OR "high" priority.
406
+ * `[{ category_priority: ["articles", "high"] }]` will return
407
+ * entries that have "articles" category AND "high" priority.
408
+ * This requires inserting the entries with these filter values exactly.
409
+ * e.g. if you insert a entry with
410
+ * `{ team_user: { team: "team1", user: "user1" } }`, it will not match
411
+ * `{ team_user: { team: "team1" } }` but it will match
412
+ */
413
+ filters?: EntryFilterValues<FitlerSchemas>[];
414
+ /**
415
+ * The maximum number of messages to fetch. Default is 10.
416
+ * This is the number *before* the chunkContext is applied.
417
+ * e.g. { before: 2, after: 1 } means 4x the limit is returned.
418
+ */
419
+ limit?: number;
420
+ /**
421
+ * What chunks around the search results to include.
422
+ * Default: { before: 0, after: 0 }
423
+ * e.g. { before: 2, after: 1 } means 2 chunks before + 1 chunk after.
424
+ * If `chunk4` was the only result, the results returned would be:
425
+ * `[{ content: [chunk2, chunk3, chunk4, chunk5], score, ... }]`
426
+ * The results don't overlap, and bias toward giving "before" context.
427
+ * So if `chunk7` was also a result, the results returned would be:
428
+ * `[
429
+ * { content: [chunk2, chunk3, chunk4], score, ... }
430
+ * { content: [chunk5, chunk6, chunk7, chunk8], score, ... },
431
+ * ]`
432
+ */
433
+ chunkContext?: {
434
+ before: number;
435
+ after: number;
436
+ };
437
+ /**
438
+ * The minimum score to return a result.
439
+ */
440
+ vectorScoreThreshold?: number;
441
+ };
442
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAoB,YAAY,EAAE,KAAK,WAAW,EAAE,MAAM,IAAI,CAAC;AAEtE,OAAO,EAIL,KAAK,YAAY,EAEjB,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,EACxB,MAAM,eAA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