@opensaas/stack-rag 0.1.6

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 (149) hide show
  1. package/.turbo/turbo-build.log +4 -0
  2. package/CHANGELOG.md +10 -0
  3. package/CLAUDE.md +565 -0
  4. package/LICENSE +21 -0
  5. package/README.md +406 -0
  6. package/dist/config/index.d.ts +63 -0
  7. package/dist/config/index.d.ts.map +1 -0
  8. package/dist/config/index.js +94 -0
  9. package/dist/config/index.js.map +1 -0
  10. package/dist/config/plugin.d.ts +38 -0
  11. package/dist/config/plugin.d.ts.map +1 -0
  12. package/dist/config/plugin.js +215 -0
  13. package/dist/config/plugin.js.map +1 -0
  14. package/dist/config/plugin.test.d.ts +2 -0
  15. package/dist/config/plugin.test.d.ts.map +1 -0
  16. package/dist/config/plugin.test.js +554 -0
  17. package/dist/config/plugin.test.js.map +1 -0
  18. package/dist/config/types.d.ts +249 -0
  19. package/dist/config/types.d.ts.map +1 -0
  20. package/dist/config/types.js +5 -0
  21. package/dist/config/types.js.map +1 -0
  22. package/dist/fields/embedding.d.ts +85 -0
  23. package/dist/fields/embedding.d.ts.map +1 -0
  24. package/dist/fields/embedding.js +81 -0
  25. package/dist/fields/embedding.js.map +1 -0
  26. package/dist/fields/embedding.test.d.ts +2 -0
  27. package/dist/fields/embedding.test.d.ts.map +1 -0
  28. package/dist/fields/embedding.test.js +323 -0
  29. package/dist/fields/embedding.test.js.map +1 -0
  30. package/dist/fields/index.d.ts +6 -0
  31. package/dist/fields/index.d.ts.map +1 -0
  32. package/dist/fields/index.js +5 -0
  33. package/dist/fields/index.js.map +1 -0
  34. package/dist/index.d.ts +8 -0
  35. package/dist/index.d.ts.map +1 -0
  36. package/dist/index.js +9 -0
  37. package/dist/index.js.map +1 -0
  38. package/dist/mcp/index.d.ts +19 -0
  39. package/dist/mcp/index.d.ts.map +1 -0
  40. package/dist/mcp/index.js +18 -0
  41. package/dist/mcp/index.js.map +1 -0
  42. package/dist/providers/index.d.ts +38 -0
  43. package/dist/providers/index.d.ts.map +1 -0
  44. package/dist/providers/index.js +68 -0
  45. package/dist/providers/index.js.map +1 -0
  46. package/dist/providers/ollama.d.ts +49 -0
  47. package/dist/providers/ollama.d.ts.map +1 -0
  48. package/dist/providers/ollama.js +151 -0
  49. package/dist/providers/ollama.js.map +1 -0
  50. package/dist/providers/openai.d.ts +41 -0
  51. package/dist/providers/openai.d.ts.map +1 -0
  52. package/dist/providers/openai.js +126 -0
  53. package/dist/providers/openai.js.map +1 -0
  54. package/dist/providers/providers.test.d.ts +2 -0
  55. package/dist/providers/providers.test.d.ts.map +1 -0
  56. package/dist/providers/providers.test.js +224 -0
  57. package/dist/providers/providers.test.js.map +1 -0
  58. package/dist/providers/types.d.ts +88 -0
  59. package/dist/providers/types.d.ts.map +1 -0
  60. package/dist/providers/types.js +2 -0
  61. package/dist/providers/types.js.map +1 -0
  62. package/dist/runtime/batch.d.ts +183 -0
  63. package/dist/runtime/batch.d.ts.map +1 -0
  64. package/dist/runtime/batch.js +240 -0
  65. package/dist/runtime/batch.js.map +1 -0
  66. package/dist/runtime/batch.test.d.ts +2 -0
  67. package/dist/runtime/batch.test.d.ts.map +1 -0
  68. package/dist/runtime/batch.test.js +251 -0
  69. package/dist/runtime/batch.test.js.map +1 -0
  70. package/dist/runtime/chunking.d.ts +42 -0
  71. package/dist/runtime/chunking.d.ts.map +1 -0
  72. package/dist/runtime/chunking.js +264 -0
  73. package/dist/runtime/chunking.js.map +1 -0
  74. package/dist/runtime/chunking.test.d.ts +2 -0
  75. package/dist/runtime/chunking.test.d.ts.map +1 -0
  76. package/dist/runtime/chunking.test.js +212 -0
  77. package/dist/runtime/chunking.test.js.map +1 -0
  78. package/dist/runtime/embeddings.d.ts +147 -0
  79. package/dist/runtime/embeddings.d.ts.map +1 -0
  80. package/dist/runtime/embeddings.js +201 -0
  81. package/dist/runtime/embeddings.js.map +1 -0
  82. package/dist/runtime/embeddings.test.d.ts +2 -0
  83. package/dist/runtime/embeddings.test.d.ts.map +1 -0
  84. package/dist/runtime/embeddings.test.js +366 -0
  85. package/dist/runtime/embeddings.test.js.map +1 -0
  86. package/dist/runtime/index.d.ts +14 -0
  87. package/dist/runtime/index.d.ts.map +1 -0
  88. package/dist/runtime/index.js +18 -0
  89. package/dist/runtime/index.js.map +1 -0
  90. package/dist/runtime/search.d.ts +135 -0
  91. package/dist/runtime/search.d.ts.map +1 -0
  92. package/dist/runtime/search.js +101 -0
  93. package/dist/runtime/search.js.map +1 -0
  94. package/dist/storage/index.d.ts +41 -0
  95. package/dist/storage/index.d.ts.map +1 -0
  96. package/dist/storage/index.js +73 -0
  97. package/dist/storage/index.js.map +1 -0
  98. package/dist/storage/json.d.ts +34 -0
  99. package/dist/storage/json.d.ts.map +1 -0
  100. package/dist/storage/json.js +82 -0
  101. package/dist/storage/json.js.map +1 -0
  102. package/dist/storage/pgvector.d.ts +53 -0
  103. package/dist/storage/pgvector.d.ts.map +1 -0
  104. package/dist/storage/pgvector.js +168 -0
  105. package/dist/storage/pgvector.js.map +1 -0
  106. package/dist/storage/sqlite-vss.d.ts +49 -0
  107. package/dist/storage/sqlite-vss.d.ts.map +1 -0
  108. package/dist/storage/sqlite-vss.js +148 -0
  109. package/dist/storage/sqlite-vss.js.map +1 -0
  110. package/dist/storage/storage.test.d.ts +2 -0
  111. package/dist/storage/storage.test.d.ts.map +1 -0
  112. package/dist/storage/storage.test.js +440 -0
  113. package/dist/storage/storage.test.js.map +1 -0
  114. package/dist/storage/types.d.ts +79 -0
  115. package/dist/storage/types.d.ts.map +1 -0
  116. package/dist/storage/types.js +49 -0
  117. package/dist/storage/types.js.map +1 -0
  118. package/package.json +82 -0
  119. package/src/config/index.ts +116 -0
  120. package/src/config/plugin.test.ts +664 -0
  121. package/src/config/plugin.ts +257 -0
  122. package/src/config/types.ts +283 -0
  123. package/src/fields/embedding.test.ts +408 -0
  124. package/src/fields/embedding.ts +150 -0
  125. package/src/fields/index.ts +6 -0
  126. package/src/index.ts +33 -0
  127. package/src/mcp/index.ts +21 -0
  128. package/src/providers/index.ts +81 -0
  129. package/src/providers/ollama.ts +186 -0
  130. package/src/providers/openai.ts +161 -0
  131. package/src/providers/providers.test.ts +275 -0
  132. package/src/providers/types.ts +100 -0
  133. package/src/runtime/batch.test.ts +332 -0
  134. package/src/runtime/batch.ts +424 -0
  135. package/src/runtime/chunking.test.ts +258 -0
  136. package/src/runtime/chunking.ts +334 -0
  137. package/src/runtime/embeddings.test.ts +441 -0
  138. package/src/runtime/embeddings.ts +380 -0
  139. package/src/runtime/index.ts +51 -0
  140. package/src/runtime/search.ts +243 -0
  141. package/src/storage/index.ts +86 -0
  142. package/src/storage/json.ts +106 -0
  143. package/src/storage/pgvector.ts +206 -0
  144. package/src/storage/sqlite-vss.ts +193 -0
  145. package/src/storage/storage.test.ts +521 -0
  146. package/src/storage/types.ts +126 -0
  147. package/tsconfig.json +13 -0
  148. package/tsconfig.tsbuildinfo +1 -0
  149. package/vitest.config.ts +18 -0
@@ -0,0 +1,79 @@
1
+ import type { SearchResult } from '../config/types.js';
2
+ /**
3
+ * Vector storage backend interface
4
+ * All storage backends must implement this interface
5
+ */
6
+ export interface VectorStorage {
7
+ /**
8
+ * Storage backend type
9
+ */
10
+ readonly type: string;
11
+ /**
12
+ * Search for similar vectors
13
+ *
14
+ * @param listKey - The list name (e.g., 'Post', 'Article')
15
+ * @param fieldName - The field name containing embeddings
16
+ * @param queryVector - The query embedding vector
17
+ * @param options - Search options
18
+ * @returns Array of search results with items and scores
19
+ */
20
+ search<T = unknown>(listKey: string, fieldName: string, queryVector: number[], options: SearchOptions): Promise<SearchResult<T>[]>;
21
+ /**
22
+ * Calculate cosine similarity between two vectors
23
+ * Utility function for scoring results
24
+ *
25
+ * @param a - First vector
26
+ * @param b - Second vector
27
+ * @returns Similarity score (0-1, higher is more similar)
28
+ */
29
+ cosineSimilarity(a: number[], b: number[]): number;
30
+ }
31
+ /**
32
+ * Options for vector search
33
+ */
34
+ export type SearchOptions = {
35
+ /**
36
+ * Maximum number of results to return
37
+ * @default 10
38
+ */
39
+ limit?: number;
40
+ /**
41
+ * Minimum similarity score (0-1)
42
+ * Results below this threshold will be filtered out
43
+ * @default 0.0
44
+ */
45
+ minScore?: number;
46
+ /**
47
+ * Access context for enforcing access control
48
+ * Required to ensure users only see items they have access to
49
+ */
50
+ context: import('@opensaas/stack-core').AccessContext;
51
+ /**
52
+ * Additional Prisma where clause to filter results
53
+ * This is merged with access control filters
54
+ */
55
+ where?: Record<string, unknown>;
56
+ };
57
+ /**
58
+ * Distance functions for vector similarity
59
+ */
60
+ export type DistanceFunction = 'cosine' | 'l2' | 'inner_product';
61
+ /**
62
+ * Normalize a vector to unit length
63
+ * Required for cosine similarity
64
+ */
65
+ export declare function normalizeVector(vector: number[]): number[];
66
+ /**
67
+ * Calculate dot product of two vectors
68
+ */
69
+ export declare function dotProduct(a: number[], b: number[]): number;
70
+ /**
71
+ * Calculate L2 (Euclidean) distance between two vectors
72
+ */
73
+ export declare function l2Distance(a: number[], b: number[]): number;
74
+ /**
75
+ * Calculate cosine similarity between two vectors
76
+ * Returns a value between 0 and 1 (higher is more similar)
77
+ */
78
+ export declare function cosineSimilarity(a: number[], b: number[]): number;
79
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/storage/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAEtD;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IAErB;;;;;;;;OAQG;IACH,MAAM,CAAC,CAAC,GAAG,OAAO,EAChB,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,MAAM,EAAE,EACrB,OAAO,EAAE,aAAa,GACrB,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC,CAAA;IAE7B;;;;;;;OAOG;IACH,gBAAgB,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,CAAA;CACnD;AAED;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG;IAC1B;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;IAEd;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;IAEjB;;;OAGG;IACH,OAAO,EAAE,OAAO,sBAAsB,EAAE,aAAa,CAAA;IAErD;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAChC,CAAA;AAED;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,QAAQ,GAAG,IAAI,GAAG,eAAe,CAAA;AAEhE;;;GAGG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAI1D;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,CAK3D;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,CAS3D;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,CAajE"}
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Normalize a vector to unit length
3
+ * Required for cosine similarity
4
+ */
5
+ export function normalizeVector(vector) {
6
+ const magnitude = Math.sqrt(vector.reduce((sum, val) => sum + val * val, 0));
7
+ if (magnitude === 0)
8
+ return vector;
9
+ return vector.map((val) => val / magnitude);
10
+ }
11
+ /**
12
+ * Calculate dot product of two vectors
13
+ */
14
+ export function dotProduct(a, b) {
15
+ if (a.length !== b.length) {
16
+ throw new Error(`Vector dimension mismatch: ${a.length} vs ${b.length}`);
17
+ }
18
+ return a.reduce((sum, val, i) => sum + val * b[i], 0);
19
+ }
20
+ /**
21
+ * Calculate L2 (Euclidean) distance between two vectors
22
+ */
23
+ export function l2Distance(a, b) {
24
+ if (a.length !== b.length) {
25
+ throw new Error(`Vector dimension mismatch: ${a.length} vs ${b.length}`);
26
+ }
27
+ const sumSquaredDiff = a.reduce((sum, val, i) => {
28
+ const diff = val - b[i];
29
+ return sum + diff * diff;
30
+ }, 0);
31
+ return Math.sqrt(sumSquaredDiff);
32
+ }
33
+ /**
34
+ * Calculate cosine similarity between two vectors
35
+ * Returns a value between 0 and 1 (higher is more similar)
36
+ */
37
+ export function cosineSimilarity(a, b) {
38
+ const dotProd = dotProduct(a, b);
39
+ const magnitudeA = Math.sqrt(dotProduct(a, a));
40
+ const magnitudeB = Math.sqrt(dotProduct(b, b));
41
+ if (magnitudeA === 0 || magnitudeB === 0) {
42
+ return 0;
43
+ }
44
+ // Cosine similarity ranges from -1 to 1
45
+ // We normalize to 0-1 for consistency
46
+ const similarity = dotProd / (magnitudeA * magnitudeB);
47
+ return (similarity + 1) / 2;
48
+ }
49
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/storage/types.ts"],"names":[],"mappings":"AA0EA;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAC,MAAgB;IAC9C,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,GAAG,GAAG,GAAG,GAAG,GAAG,EAAE,CAAC,CAAC,CAAC,CAAA;IAC5E,IAAI,SAAS,KAAK,CAAC;QAAE,OAAO,MAAM,CAAA;IAClC,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,GAAG,SAAS,CAAC,CAAA;AAC7C,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,CAAW,EAAE,CAAW;IACjD,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC,MAAM,OAAO,CAAC,CAAC,MAAM,EAAE,CAAC,CAAA;IAC1E,CAAC;IACD,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;AACvD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,CAAW,EAAE,CAAW;IACjD,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC,MAAM,OAAO,CAAC,CAAC,MAAM,EAAE,CAAC,CAAA;IAC1E,CAAC;IACD,MAAM,cAAc,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,EAAE,EAAE;QAC9C,MAAM,IAAI,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,CAAA;QACvB,OAAO,GAAG,GAAG,IAAI,GAAG,IAAI,CAAA;IAC1B,CAAC,EAAE,CAAC,CAAC,CAAA;IACL,OAAO,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,CAAA;AAClC,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAAC,CAAW,EAAE,CAAW;IACvD,MAAM,OAAO,GAAG,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;IAChC,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;IAC9C,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;IAE9C,IAAI,UAAU,KAAK,CAAC,IAAI,UAAU,KAAK,CAAC,EAAE,CAAC;QACzC,OAAO,CAAC,CAAA;IACV,CAAC;IAED,wCAAwC;IACxC,sCAAsC;IACtC,MAAM,UAAU,GAAG,OAAO,GAAG,CAAC,UAAU,GAAG,UAAU,CAAC,CAAA;IACtD,OAAO,CAAC,UAAU,GAAG,CAAC,CAAC,GAAG,CAAC,CAAA;AAC7B,CAAC"}
package/package.json ADDED
@@ -0,0 +1,82 @@
1
+ {
2
+ "name": "@opensaas/stack-rag",
3
+ "version": "0.1.6",
4
+ "description": "RAG and AI embeddings integration for OpenSaas Stack",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "default": "./dist/index.js"
12
+ },
13
+ "./fields": {
14
+ "types": "./dist/fields/index.d.ts",
15
+ "default": "./dist/fields/index.js"
16
+ },
17
+ "./providers": {
18
+ "types": "./dist/providers/index.d.ts",
19
+ "default": "./dist/providers/index.js"
20
+ },
21
+ "./storage": {
22
+ "types": "./dist/storage/index.d.ts",
23
+ "default": "./dist/storage/index.js"
24
+ },
25
+ "./runtime": {
26
+ "types": "./dist/runtime/index.d.ts",
27
+ "default": "./dist/runtime/index.js"
28
+ },
29
+ "./mcp": {
30
+ "types": "./dist/mcp/index.d.ts",
31
+ "default": "./dist/mcp/index.js"
32
+ }
33
+ },
34
+ "keywords": [
35
+ "opensaas",
36
+ "rag",
37
+ "embeddings",
38
+ "vector-search",
39
+ "ai",
40
+ "semantic-search"
41
+ ],
42
+ "author": "",
43
+ "license": "MIT",
44
+ "repository": {
45
+ "type": "git",
46
+ "url": "https://github.com/OpenSaasAU/stack.git",
47
+ "directory": "packages/rag"
48
+ },
49
+ "homepage": "https://stack.opensaas.au",
50
+ "bugs": {
51
+ "url": "https://github.com/OpenSaasAU/stack/issues"
52
+ },
53
+ "peerDependencies": {
54
+ "openai": "^6.8.0",
55
+ "@opensaas/stack-core": "0.1.6"
56
+ },
57
+ "peerDependenciesMeta": {
58
+ "openai": {
59
+ "optional": true
60
+ }
61
+ },
62
+ "dependencies": {
63
+ "zod": "^4.1.12"
64
+ },
65
+ "devDependencies": {
66
+ "@types/node": "^24.7.2",
67
+ "@vitest/coverage-v8": "^4.0.4",
68
+ "@vitest/ui": "^4.0.0",
69
+ "openai": "^6.0.0",
70
+ "typescript": "^5.9.3",
71
+ "vitest": "^4.0.0",
72
+ "@opensaas/stack-core": "0.1.6"
73
+ },
74
+ "scripts": {
75
+ "build": "tsc",
76
+ "dev": "tsc --watch",
77
+ "clean": "rm -rf .turbo dist tsconfig.tsbuildinfo",
78
+ "test": "vitest run",
79
+ "test:ui": "vitest --ui",
80
+ "test:coverage": "vitest run --coverage"
81
+ }
82
+ }
@@ -0,0 +1,116 @@
1
+ import type {
2
+ RAGConfig,
3
+ NormalizedRAGConfig,
4
+ VectorStorageConfig,
5
+ OpenAIEmbeddingConfig,
6
+ OllamaEmbeddingConfig,
7
+ } from './types.js'
8
+
9
+ /**
10
+ * Normalize RAG configuration with defaults
11
+ */
12
+ export function normalizeRAGConfig(config: RAGConfig): NormalizedRAGConfig {
13
+ return {
14
+ provider: config.provider || null,
15
+ providers: config.providers || {},
16
+ storage: config.storage || { type: 'json' },
17
+ chunking: {
18
+ strategy: config.chunking?.strategy || 'recursive',
19
+ maxTokens: config.chunking?.maxTokens || 500,
20
+ overlap: config.chunking?.overlap || 50,
21
+ },
22
+ enableMcpTools: config.enableMcpTools ?? true,
23
+ batchSize: config.batchSize || 10,
24
+ rateLimit: config.rateLimit || 100,
25
+ }
26
+ }
27
+
28
+ /**
29
+ * Helper to create OpenAI embedding provider configuration
30
+ *
31
+ * @example
32
+ * ```typescript
33
+ * const provider = openaiEmbeddings({
34
+ * apiKey: process.env.OPENAI_API_KEY,
35
+ * model: 'text-embedding-3-small'
36
+ * })
37
+ * ```
38
+ */
39
+ export function openaiEmbeddings(
40
+ config: Omit<OpenAIEmbeddingConfig, 'type'>,
41
+ ): OpenAIEmbeddingConfig {
42
+ return {
43
+ type: 'openai',
44
+ ...config,
45
+ }
46
+ }
47
+
48
+ /**
49
+ * Helper to create Ollama embedding provider configuration
50
+ *
51
+ * @example
52
+ * ```typescript
53
+ * const provider = ollamaEmbeddings({
54
+ * baseURL: 'http://localhost:11434',
55
+ * model: 'nomic-embed-text'
56
+ * })
57
+ * ```
58
+ */
59
+ export function ollamaEmbeddings(
60
+ config?: Omit<OllamaEmbeddingConfig, 'type'>,
61
+ ): OllamaEmbeddingConfig {
62
+ return {
63
+ type: 'ollama',
64
+ baseURL: config?.baseURL || 'http://localhost:11434',
65
+ model: config?.model || 'nomic-embed-text',
66
+ }
67
+ }
68
+
69
+ /**
70
+ * Helper to create pgvector storage configuration
71
+ *
72
+ * @example
73
+ * ```typescript
74
+ * const storage = pgvectorStorage({ distanceFunction: 'cosine' })
75
+ * ```
76
+ */
77
+ export function pgvectorStorage(config?: {
78
+ distanceFunction?: 'cosine' | 'l2' | 'inner_product'
79
+ }): VectorStorageConfig {
80
+ return {
81
+ type: 'pgvector',
82
+ distanceFunction: config?.distanceFunction || 'cosine',
83
+ }
84
+ }
85
+
86
+ /**
87
+ * Helper to create SQLite VSS storage configuration
88
+ *
89
+ * @example
90
+ * ```typescript
91
+ * const storage = sqliteVssStorage({ distanceFunction: 'cosine' })
92
+ * ```
93
+ */
94
+ export function sqliteVssStorage(config?: {
95
+ distanceFunction?: 'cosine' | 'l2'
96
+ }): VectorStorageConfig {
97
+ return {
98
+ type: 'sqlite-vss',
99
+ distanceFunction: config?.distanceFunction || 'cosine',
100
+ }
101
+ }
102
+
103
+ /**
104
+ * Helper to create JSON-based storage configuration
105
+ *
106
+ * @example
107
+ * ```typescript
108
+ * const storage = jsonStorage()
109
+ * ```
110
+ */
111
+ export function jsonStorage(): VectorStorageConfig {
112
+ return { type: 'json' }
113
+ }
114
+
115
+ export type { RAGConfig, NormalizedRAGConfig }
116
+ export * from './types.js'