@anvia/transformers 1.1.4 → 1.1.5

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 (2) hide show
  1. package/README.md +37 -56
  2. package/package.json +3 -3
package/README.md CHANGED
@@ -1,79 +1,60 @@
1
1
  # @anvia/transformers
2
2
 
3
- Local Transformers.js embedding model adapter for Anvia.
3
+ Generate text embeddings locally with Transformers.js. Build semantic search and retrieval
4
+ workflows without sending document text to a hosted embedding service.
4
5
 
5
- ## Installation
6
+ ## Install
6
7
 
7
8
  ```sh
8
- pnpm add @anvia/transformers @anvia/core @huggingface/transformers
9
+ pnpm add @anvia/transformers @anvia/core
9
10
  ```
10
11
 
11
- ## Usage
12
+ ## Quickstart
13
+
14
+ The first load may download model files. Subsequent loads can reuse the local cache.
12
15
 
13
16
  ```ts
14
17
  import { embedDocuments } from "@anvia/core/embeddings";
15
18
  import { InMemoryVectorStore, retrieveDocuments } from "@anvia/core/vector-store";
16
19
  import { loadTransformersEmbeddingModel } from "@anvia/transformers";
17
20
 
18
- const model = await loadTransformersEmbeddingModel({ modelId: "Xenova/all-MiniLM-L6-v2" });
19
- const { documents } = await embedDocuments({
20
- model,
21
- documents: [{ id: "password-reset", text: "Reset links expire after 30 minutes." }],
22
- id: (document) => document.id,
23
- content: (document) => document.text,
24
- });
25
-
26
- const store = InMemoryVectorStore.fromDocuments({ documents });
27
- const results = await retrieveDocuments({
28
- store,
29
- model,
30
- query: "How long does a reset link last?",
31
- topK: 3,
32
- });
33
- ```
34
-
35
- Loading is eager and may download model files. Reuse the returned handle and close it at application
36
- shutdown. The handle supports `await using` and waits for active inference before disposing its
37
- owned Transformers pipeline.
38
-
39
- ```ts
40
21
  const model = await loadTransformersEmbeddingModel({
41
22
  modelId: "Xenova/all-MiniLM-L6-v2",
42
- pooling: "mean",
43
- normalize: true,
44
- maxBatchSize: 16,
45
23
  });
46
- ```
47
24
 
48
- ```ts
49
- await using model = await loadTransformersEmbeddingModel({
50
- modelId: "Xenova/all-MiniLM-L6-v2",
51
- device: "cpu",
52
- dtype: "q8",
53
- cacheDir: "./models",
54
- });
25
+ try {
26
+ const { documents } = await embedDocuments({
27
+ model,
28
+ documents: [{ id: "password-reset", text: "Reset links expire after 30 minutes." }],
29
+ id: (document) => document.id,
30
+ content: (document) => document.text,
31
+ });
32
+ const store = InMemoryVectorStore.fromDocuments({ documents });
33
+
34
+ const results = await retrieveDocuments({
35
+ store,
36
+ model,
37
+ query: "How long does a reset link last?",
38
+ topK: 3,
39
+ });
40
+ console.log(results);
41
+ } finally {
42
+ await model.close();
43
+ }
55
44
  ```
56
45
 
57
- Adapt an existing pipeline when the application owns its lifecycle:
46
+ ## What it supports
58
47
 
59
- ```ts
60
- import { adaptTransformersEmbeddingModel } from "@anvia/transformers";
48
+ - Configurable pooling, normalization, batching, device, and dtype.
49
+ - Model caching and local-files-only loading.
50
+ - Existing Transformers pipelines through `adaptTransformersEmbeddingModel()`.
51
+ - Explicit cleanup with `close()` or `await using` for loaded models.
61
52
 
62
- const model = adaptTransformersEmbeddingModel({
63
- runtime: existingPipeline,
64
- modelId: "custom-model",
65
- pooling: "mean",
66
- normalize: true,
67
- });
68
- ```
69
-
70
- Adapted handles never dispose the caller-owned runtime. Embedding helpers use object arguments,
71
- return named results, and accept `retries` and `abortSignal`.
53
+ Reuse the model across requests. Adapted pipelines remain caller-owned; loaded models wait
54
+ for active inference before disposing their runtime.
72
55
 
73
- ## Development
56
+ ## Learn more
74
57
 
75
- ```sh
76
- pnpm --filter @anvia/transformers typecheck
77
- pnpm --filter @anvia/transformers test
78
- pnpm --filter @anvia/transformers build
79
- ```
58
+ - [Usage guide](https://github.com/anvia-hq/anvia/blob/main/docs/packages/embedding-transformers.md)
59
+ - [Anvia overview](https://github.com/anvia-hq/anvia/blob/main/README.md)
60
+ - [Contributing](https://github.com/anvia-hq/anvia/blob/main/CONTRIBUTING.md)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anvia/transformers",
3
- "version": "1.1.4",
3
+ "version": "1.1.5",
4
4
  "description": "Transformers.js embedding model adapter for Anvia.",
5
5
  "author": "anvia",
6
6
  "license": "MIT",
@@ -32,10 +32,10 @@
32
32
  "tsup": "^8.5.0",
33
33
  "typescript": "^5.9.3",
34
34
  "vitest": "^4.1.11",
35
- "@anvia/core": "1.5.0"
35
+ "@anvia/core": "1.6.1"
36
36
  },
37
37
  "peerDependencies": {
38
- "@anvia/core": "^1.5.0"
38
+ "@anvia/core": "^1.6.1"
39
39
  },
40
40
  "scripts": {
41
41
  "build": "tsup src/index.ts --format esm --dts --sourcemap --clean",