astro-content-vectors 1.0.0 → 1.1.0
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 +17 -15
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -1
- package/dist/related-posts.js +6 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -37,6 +37,8 @@ export default defineConfig({
|
|
|
37
37
|
},
|
|
38
38
|
production: {
|
|
39
39
|
provider: { model: "text-embedding-3-small" },
|
|
40
|
+
// Fail production builds when embedding providers are unavailable.
|
|
41
|
+
failOnError: true,
|
|
40
42
|
},
|
|
41
43
|
},
|
|
42
44
|
fallback: {
|
|
@@ -55,7 +57,7 @@ export default defineConfig({
|
|
|
55
57
|
|
|
56
58
|
Set `OPENAI_API_KEY` in the environment where the Astro build runs. The integration detects it automatically and never puts the key into client bundles or injected configuration. Without the key, it tries the configured LM Studio fallback. If an OpenAI request fails, it tries the fallback once. If both providers fail, it logs a warning and returns no recommendations by default; set `failOnError: true` to fail the build instead. Start LM Studio's local server and load an embedding model for the fallback to work.
|
|
57
59
|
|
|
58
|
-
Astro `dev` uses the `development` override; `astro build` uses `production`. The integration selects an override using Astro's `import.meta.env.MODE`, so custom modes such as `astro build --mode preview` work as environment keys too. Set `environment` to explicitly override the detected mode. Each environment may override the single default `provider`; any omitted settings inherit from the default. OpenAI environments use the default LM Studio fallback; configure it with the top-level `fallback` option or set `fallback: false` to disable it. An environment configured with LM Studio uses only that provider.
|
|
60
|
+
Astro `dev` uses the `development` override; `astro build` uses `production`. The integration selects an override using Astro's `import.meta.env.MODE`, so custom modes such as `astro build --mode preview` work as environment keys too. Set `environment` to explicitly override the detected mode. Each environment may override the single default `provider`; any omitted settings inherit from the default. Each environment can also set its own `failOnError`, which takes precedence over the top-level setting. OpenAI environments use the default LM Studio fallback; configure it with the top-level `fallback` option or set `fallback: false` to disable it. An environment configured with LM Studio uses only that provider.
|
|
59
61
|
|
|
60
62
|
### Provider configuration
|
|
61
63
|
|
|
@@ -72,20 +74,20 @@ The OpenAI SDK sends one request per batch, does not retry failed requests, and
|
|
|
72
74
|
|
|
73
75
|
### Integration options
|
|
74
76
|
|
|
75
|
-
| Option | Default | Description
|
|
76
|
-
| ------------------------ | ----------------------------------------------------------------- |
|
|
77
|
-
| `collections` | all collections | Optional allowlist of Astro content collections to index.
|
|
78
|
-
| `provider` | OpenAI | Default provider and its settings.
|
|
79
|
-
| `environments` | `{}` | Provider overrides keyed by environment name. |
|
|
80
|
-
| `environment` | `"development"` for `astro dev`; `"production"` for `astro build` | Explicit environment key to select an override.
|
|
81
|
-
| `fallback` | LM Studio | Fallback settings for an OpenAI provider. Set to `false` to disable fallback.
|
|
82
|
-
| `threshold` | `0.65` | Minimum cosine similarity score for a recommendation.
|
|
83
|
-
| `limit` | `3` | Maximum recommendations returned per entry.
|
|
84
|
-
| `logLevel` | `"warn"` | One of `"silent"`, `"error"`, `"warn"`, `"info"`, or `"debug"`.
|
|
85
|
-
| `failOnError` | `false` | Throw if no configured provider can generate embeddings.
|
|
86
|
-
| `cache` | `true` | Store embeddings in SQLite during Astro builds.
|
|
87
|
-
| `cachePath` | `.astro/embeddings.db` | SQLite file path, relative to the project root.
|
|
88
|
-
| `outputSimilarityScores` | `false` | Write pairwise similarity score JSON files into the build output.
|
|
77
|
+
| Option | Default | Description |
|
|
78
|
+
| ------------------------ | ----------------------------------------------------------------- | ----------------------------------------------------------------------------------------------- |
|
|
79
|
+
| `collections` | all collections | Optional allowlist of Astro content collections to index. |
|
|
80
|
+
| `provider` | OpenAI | Default provider and its settings. |
|
|
81
|
+
| `environments` | `{}` | Provider and `failOnError` overrides keyed by environment name. |
|
|
82
|
+
| `environment` | `"development"` for `astro dev`; `"production"` for `astro build` | Explicit environment key to select an override. |
|
|
83
|
+
| `fallback` | LM Studio | Fallback settings for an OpenAI provider. Set to `false` to disable fallback. |
|
|
84
|
+
| `threshold` | `0.65` | Minimum cosine similarity score for a recommendation. |
|
|
85
|
+
| `limit` | `3` | Maximum recommendations returned per entry. |
|
|
86
|
+
| `logLevel` | `"warn"` | One of `"silent"`, `"error"`, `"warn"`, `"info"`, or `"debug"`. |
|
|
87
|
+
| `failOnError` | `false` | Throw if no configured provider can generate embeddings; environment overrides take precedence. |
|
|
88
|
+
| `cache` | `true` | Store embeddings in SQLite during Astro builds. |
|
|
89
|
+
| `cachePath` | `.astro/embeddings.db` | SQLite file path, relative to the project root. |
|
|
90
|
+
| `outputSimilarityScores` | `false` | Write pairwise similarity score JSON files into the build output. |
|
|
89
91
|
|
|
90
92
|
```js
|
|
91
93
|
contentVectors({
|
package/dist/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export type AstroContentVectorsOptions = {
|
|
|
8
8
|
environment?: string;
|
|
9
9
|
environments?: Record<string, {
|
|
10
10
|
provider?: ProviderOverride;
|
|
11
|
+
failOnError?: boolean;
|
|
11
12
|
}>;
|
|
12
13
|
/** LM Studio fallback used when an OpenAI provider has no key or fails. */
|
|
13
14
|
fallback?: false | ProviderOverride;
|
package/dist/index.js
CHANGED
|
@@ -37,7 +37,9 @@ const defineEnvironment = (name, options, projectRoot) => {
|
|
|
37
37
|
threshold: options.threshold,
|
|
38
38
|
limit: options.limit,
|
|
39
39
|
logLevel: options.logLevel,
|
|
40
|
-
failOnError: options.failOnError ??
|
|
40
|
+
failOnError: options.environments?.[name]?.failOnError ??
|
|
41
|
+
options.failOnError ??
|
|
42
|
+
false,
|
|
41
43
|
collections: options.collections ?? null,
|
|
42
44
|
cache: options.cache ?? true,
|
|
43
45
|
cachePath: resolve(projectRoot, options.cachePath ?? ".astro/embeddings.db"),
|
package/dist/related-posts.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const getCosineSimilarity = (vectorA, vectorB) => {
|
|
2
2
|
// See https://stackoverflow.com/a/64816824 for dot product calculation explained.
|
|
3
|
-
const dot = vectorA.reduce((sum, val, i) => sum + val * vectorB[i], 0.0);
|
|
3
|
+
const dot = vectorA.reduce((sum, val, i) => sum + val * (vectorB[i] ?? 0), 0.0);
|
|
4
4
|
const magnitudeA = Math.sqrt(vectorA.reduce((sum, val) => sum + val * val, 0.0));
|
|
5
5
|
const magnitudeB = Math.sqrt(vectorB.reduce((sum, val) => sum + val * val, 0.0));
|
|
6
6
|
const denominator = magnitudeA * magnitudeB;
|
|
@@ -29,7 +29,11 @@ const getPairWiseSimilarityScores = (embeddings) => {
|
|
|
29
29
|
const pairs = [];
|
|
30
30
|
for (let i = 0; i < embeddings.length; i++) {
|
|
31
31
|
for (let j = i + 1; j < embeddings.length; j++) {
|
|
32
|
-
const
|
|
32
|
+
const embeddingA = embeddings[i];
|
|
33
|
+
const embeddingB = embeddings[j];
|
|
34
|
+
if (!embeddingA || !embeddingB)
|
|
35
|
+
continue;
|
|
36
|
+
const sim = getCosineSimilarity(embeddingA.vector, embeddingB.vector);
|
|
33
37
|
pairs.push(sim);
|
|
34
38
|
}
|
|
35
39
|
}
|
package/package.json
CHANGED