You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
*`delete(id: string): Promise<void>`: Deletes a document.
325
-
*`similaritySearch(query: string, k?: number): Promise<{ id: string; content: string; ... }[]>`: Searches for `k` similar documents.
327
+
*`similaritySearch(query: string, k?: number, predicate?: (value: SearchResult) => boolean): Promise<SearchResult[]>`: Searches for `k` similar documents. Which can be filtered with an optional `predicate` function.
326
328
327
329
#### `TextSplitter`
328
330
@@ -345,6 +347,24 @@ The library provides wrappers around common `langchain` text splitters. All spli
345
347
*`dotProduct(a: number[], b: number[]): number`: Calculates the dot product of two vectors.
346
348
*`magnitude(a: number[]): number`: Calculates the Euclidean magnitude of a vector.
347
349
350
+
### Types
351
+
352
+
```typescript
353
+
interfaceMessage {
354
+
role:'user'|'assistant'|'system';
355
+
content:string;
356
+
}
357
+
358
+
typeResourceSource=string|number|object;
359
+
360
+
interfaceSearchResult {
361
+
id:string;
362
+
content:string;
363
+
metadata?:Record<string, any>;
364
+
similarity:number;
365
+
}
366
+
```
367
+
348
368
## :jigsaw: Using Custom Components
349
369
350
370
Bring your own components by creating classes that implement the `LLM`, `Embeddings`, `VectorStore` and `TextSplitter` interfaces. This allows you to use any model or service that fits your needs.
Finds the most relevant documents in the store based on a query string. It generates an embedding for the query and returns the top `k` documents that are most similar.
100
100
101
101
*`query`: The text to search for.
102
102
*`k`: The number of similar documents to return. Defaults to `3`.
103
+
*`predicate`: An optional function to filter the search results. It receives each result object and should return `true` to include the result or `false` to exclude it. If not provided, all results are included.
103
104
***Returns**: A `Promise` that resolves with an array of result objects, each containing `{ id, content, metadata, similarity }`. The `similarity` score ranges from 0 to 1, where 1 means a perfect match.
0 commit comments