@teammates/recall 0.6.1 → 0.6.3

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.
package/src/embeddings.ts CHANGED
@@ -1,56 +1,56 @@
1
- import type { EmbeddingsModel, EmbeddingsResponse } from "vectra";
2
-
3
- const DEFAULT_MODEL = "Xenova/all-MiniLM-L6-v2";
4
- const MAX_TOKENS = 256;
5
-
6
- /**
7
- * Local embeddings using transformers.js. No API keys, no network after first model download.
8
- */
9
- export class LocalEmbeddings implements EmbeddingsModel {
10
- readonly maxTokens = MAX_TOKENS;
11
-
12
- private _model: string;
13
- private _extractor: any | null = null;
14
-
15
- constructor(model?: string) {
16
- this._model = model ?? DEFAULT_MODEL;
17
- }
18
-
19
- async createEmbeddings(
20
- inputs: string | string[],
21
- ): Promise<EmbeddingsResponse> {
22
- try {
23
- const extractor = await this._getExtractor();
24
- const texts = (Array.isArray(inputs) ? inputs : [inputs]).filter(
25
- (t) => t.trim().length > 0,
26
- );
27
- if (texts.length === 0) {
28
- return { status: "success", output: [] };
29
- }
30
- const output = await extractor(texts, {
31
- pooling: "mean",
32
- normalize: true,
33
- });
34
- const embeddings: number[][] = output.tolist();
35
- return { status: "success", output: embeddings };
36
- } catch (err: any) {
37
- return { status: "error", message: err.message };
38
- }
39
- }
40
-
41
- private async _getExtractor(): Promise<any> {
42
- if (!this._extractor) {
43
- const { pipeline } = await import("@huggingface/transformers");
44
- const origWarn = console.warn;
45
- console.warn = () => {};
46
- try {
47
- this._extractor = await pipeline("feature-extraction", this._model, {
48
- dtype: "fp32",
49
- });
50
- } finally {
51
- console.warn = origWarn;
52
- }
53
- }
54
- return this._extractor;
55
- }
56
- }
1
+ import type { EmbeddingsModel, EmbeddingsResponse } from "vectra";
2
+
3
+ const DEFAULT_MODEL = "Xenova/all-MiniLM-L6-v2";
4
+ const MAX_TOKENS = 256;
5
+
6
+ /**
7
+ * Local embeddings using transformers.js. No API keys, no network after first model download.
8
+ */
9
+ export class LocalEmbeddings implements EmbeddingsModel {
10
+ readonly maxTokens = MAX_TOKENS;
11
+
12
+ private _model: string;
13
+ private _extractor: any | null = null;
14
+
15
+ constructor(model?: string) {
16
+ this._model = model ?? DEFAULT_MODEL;
17
+ }
18
+
19
+ async createEmbeddings(
20
+ inputs: string | string[],
21
+ ): Promise<EmbeddingsResponse> {
22
+ try {
23
+ const extractor = await this._getExtractor();
24
+ const texts = (Array.isArray(inputs) ? inputs : [inputs]).filter(
25
+ (t) => t.trim().length > 0,
26
+ );
27
+ if (texts.length === 0) {
28
+ return { status: "success", output: [] };
29
+ }
30
+ const output = await extractor(texts, {
31
+ pooling: "mean",
32
+ normalize: true,
33
+ });
34
+ const embeddings: number[][] = output.tolist();
35
+ return { status: "success", output: embeddings };
36
+ } catch (err: any) {
37
+ return { status: "error", message: err.message };
38
+ }
39
+ }
40
+
41
+ private async _getExtractor(): Promise<any> {
42
+ if (!this._extractor) {
43
+ const { pipeline } = await import("@huggingface/transformers");
44
+ const origWarn = console.warn;
45
+ console.warn = () => {};
46
+ try {
47
+ this._extractor = await pipeline("feature-extraction", this._model, {
48
+ dtype: "fp32",
49
+ });
50
+ } finally {
51
+ console.warn = origWarn;
52
+ }
53
+ }
54
+ return this._extractor;
55
+ }
56
+ }
package/src/index.ts CHANGED
@@ -1,11 +1,11 @@
1
- export { LocalEmbeddings } from "./embeddings.js";
2
- export { Indexer, type IndexerConfig } from "./indexer.js";
3
- export { matchMemoryCatalog, scanMemoryCatalog } from "./memory-index.js";
4
- export { buildQueryVariations, extractKeywords } from "./query-expansion.js";
5
- export {
6
- type MultiSearchOptions,
7
- type SearchOptions,
8
- type SearchResult,
9
- multiSearch,
10
- search,
11
- } from "./search.js";
1
+ export { LocalEmbeddings } from "./embeddings.js";
2
+ export { Indexer, type IndexerConfig } from "./indexer.js";
3
+ export { matchMemoryCatalog, scanMemoryCatalog } from "./memory-index.js";
4
+ export { buildQueryVariations, extractKeywords } from "./query-expansion.js";
5
+ export {
6
+ type MultiSearchOptions,
7
+ multiSearch,
8
+ type SearchOptions,
9
+ type SearchResult,
10
+ search,
11
+ } from "./search.js";