@flowrag/provider-local 0.0.1

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/README.md ADDED
@@ -0,0 +1,48 @@
1
+ # @flowrag/provider-local
2
+
3
+ Local AI provider for FlowRAG - ONNX embeddings and future local extraction.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @flowrag/provider-local
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ### Embedder
14
+
15
+ ```typescript
16
+ import { LocalEmbedder } from '@flowrag/provider-local';
17
+
18
+ const embedder = new LocalEmbedder({
19
+ model: 'Xenova/e5-small-v2', // optional, default
20
+ dtype: 'q8', // optional: 'fp32', 'q8', 'q4'
21
+ device: 'auto', // optional: 'auto', 'cpu', 'gpu'
22
+ });
23
+
24
+ // Single embedding
25
+ const embedding = await embedder.embed('Hello world');
26
+
27
+ // Batch embeddings
28
+ const embeddings = await embedder.embedBatch(['Hello', 'World']);
29
+ ```
30
+
31
+ ## Supported Models
32
+
33
+ - `Xenova/e5-small-v2` (384 dims) - Default, fast
34
+ - `Xenova/e5-base-v2` (768 dims) - Better quality
35
+ - `Xenova/e5-large-v2` (1024 dims) - Best quality
36
+ - `Xenova/all-MiniLM-L6-v2` (384 dims) - Compact
37
+ - `Xenova/all-mpnet-base-v2` (768 dims) - Good balance
38
+
39
+ ## Environment Variables
40
+
41
+ ```bash
42
+ FLOWRAG_EMBEDDING_MODEL=Xenova/e5-small-v2
43
+ FLOWRAG_EMBEDDING_DTYPE=q8
44
+ ```
45
+
46
+ ## License
47
+
48
+ MIT
@@ -0,0 +1,23 @@
1
+ import { Embedder } from "@flowrag/core";
2
+
3
+ //#region src/embedder.d.ts
4
+ interface LocalEmbedderOptions {
5
+ model?: string;
6
+ dtype?: "fp32" | "q8" | "q4";
7
+ device?: "auto" | "cpu" | "gpu";
8
+ }
9
+ declare class LocalEmbedder implements Embedder {
10
+ readonly modelName: string;
11
+ readonly dimensions: number;
12
+ private readonly dtype;
13
+ private readonly device;
14
+ private pipeline;
15
+ constructor(options?: LocalEmbedderOptions);
16
+ private getModelDimensions;
17
+ embed(text: string): Promise<number[]>;
18
+ embedBatch(texts: string[]): Promise<number[][]>;
19
+ private getPipeline;
20
+ }
21
+ //#endregion
22
+ export { LocalEmbedder, type LocalEmbedderOptions };
23
+ //# sourceMappingURL=index.d.mts.map
package/dist/index.mjs ADDED
@@ -0,0 +1,53 @@
1
+ //#region src/embedder.ts
2
+ var LocalEmbedder = class {
3
+ modelName;
4
+ dimensions;
5
+ dtype;
6
+ device;
7
+ pipeline = null;
8
+ constructor(options = {}) {
9
+ this.modelName = options.model || "Xenova/e5-small-v2";
10
+ this.dtype = options.dtype || "q8";
11
+ this.device = options.device || "auto";
12
+ this.dimensions = this.getModelDimensions(this.modelName);
13
+ }
14
+ getModelDimensions(modelName) {
15
+ return {
16
+ "Xenova/e5-small-v2": 384,
17
+ "Xenova/e5-base-v2": 768,
18
+ "Xenova/e5-large-v2": 1024,
19
+ "Xenova/all-MiniLM-L6-v2": 384,
20
+ "Xenova/all-MiniLM-L12-v2": 384,
21
+ "Xenova/all-mpnet-base-v2": 768
22
+ }[modelName] || 384;
23
+ }
24
+ async embed(text) {
25
+ const result = await (await this.getPipeline())(text, {
26
+ pooling: "mean",
27
+ normalize: true
28
+ });
29
+ return Array.from(result.data);
30
+ }
31
+ async embedBatch(texts) {
32
+ if (texts.length === 0) return [];
33
+ const pipeline = await this.getPipeline();
34
+ return (await Promise.all(texts.map((text) => pipeline(text, {
35
+ pooling: "mean",
36
+ normalize: true
37
+ })))).map((result) => Array.from(result.data));
38
+ }
39
+ async getPipeline() {
40
+ if (!this.pipeline) {
41
+ const { pipeline } = await import("@huggingface/transformers");
42
+ this.pipeline = await pipeline("feature-extraction", this.modelName, {
43
+ dtype: this.dtype,
44
+ device: this.device
45
+ });
46
+ }
47
+ return this.pipeline;
48
+ }
49
+ };
50
+
51
+ //#endregion
52
+ export { LocalEmbedder };
53
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/embedder.ts"],"sourcesContent":["import type { Embedder } from '@flowrag/core';\n\nexport interface LocalEmbedderOptions {\n model?: string;\n dtype?: 'fp32' | 'q8' | 'q4';\n device?: 'auto' | 'cpu' | 'gpu';\n}\n\nexport class LocalEmbedder implements Embedder {\n readonly modelName: string;\n readonly dimensions: number;\n private readonly dtype: string;\n private readonly device: string;\n private pipeline: unknown = null;\n\n constructor(options: LocalEmbedderOptions = {}) {\n this.modelName = options.model || 'Xenova/e5-small-v2';\n this.dtype = options.dtype || 'q8';\n this.device = options.device || 'auto';\n\n // Set dimensions based on model\n this.dimensions = this.getModelDimensions(this.modelName);\n }\n\n private getModelDimensions(modelName: string): number {\n // Common embedding model dimensions\n const dimensionMap: Record<string, number> = {\n 'Xenova/e5-small-v2': 384,\n 'Xenova/e5-base-v2': 768,\n 'Xenova/e5-large-v2': 1024,\n 'Xenova/all-MiniLM-L6-v2': 384,\n 'Xenova/all-MiniLM-L12-v2': 384,\n 'Xenova/all-mpnet-base-v2': 768,\n };\n\n return dimensionMap[modelName] || 384; // Default to 384\n }\n\n async embed(text: string): Promise<number[]> {\n const pipeline = (await this.getPipeline()) as (\n text: string,\n options: { pooling: string; normalize: boolean },\n ) => Promise<{ data: ArrayLike<number> }>;\n const result = await pipeline(text, { pooling: 'mean', normalize: true });\n return Array.from(result.data);\n }\n\n async embedBatch(texts: string[]): Promise<number[][]> {\n if (texts.length === 0) return [];\n\n const pipeline = (await this.getPipeline()) as (\n text: string,\n options: { pooling: string; normalize: boolean },\n ) => Promise<{ data: ArrayLike<number> }>;\n const results = await Promise.all(\n texts.map((text) => pipeline(text, { pooling: 'mean', normalize: true })),\n );\n return results.map((result) => Array.from(result.data));\n }\n\n private async getPipeline(): Promise<unknown> {\n if (!this.pipeline) {\n const { pipeline } = await import('@huggingface/transformers');\n this.pipeline = await pipeline('feature-extraction', this.modelName, {\n dtype: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 "version": "0.0.1",
4
+ "description": "Local AI provider for FlowRAG - ONNX embeddings and future local extraction",
5
+ "keywords": [
6
+ "flowrag",
7
+ "provider",
8
+ "local",
9
+ "onnx",
10
+ "transformers",
11
+ "embedder",
12
+ "ai",
13
+ "rag"
14
+ ],
15
+ "homepage": "https://github.com/Zweer/FlowRAG/tree/main/packages/provider-local",
16
+ "bugs": "https://github.com/Zweer/FlowRAG/issues",
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "https://github.com/Zweer/FlowRAG.git",
20
+ "directory": "packages/provider-local"
21
+ },
22
+ "license": "MIT",
23
+ "author": {
24
+ "name": "Zweer",
25
+ "email": "n.olivieriachille@gmail.com"
26
+ },
27
+ "type": "module",
28
+ "exports": {
29
+ ".": "./dist/index.mjs",
30
+ "./package.json": "./package.json"
31
+ },
32
+ "main": "./dist/index.mjs",
33
+ "module": "./dist/index.mjs",
34
+ "types": "./dist/index.d.mts",
35
+ "files": [
36
+ "dist"
37
+ ],
38
+ "dependencies": {
39
+ "@flowrag/core": "1.0.2",
40
+ "@huggingface/transformers": "^3.8.1"
41
+ },
42
+ "engines": {
43
+ "node": ">=20.3"
44
+ },
45
+ "publishConfig": {
46
+ "access": "public",
47
+ "provenance": false
48
+ }
49
+ }