strapi-content-embeddings 0.1.2 → 0.1.4
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/dist/_chunks/{App-BlCKKuQN.mjs → App-4UwemHRe.mjs} +7 -23
- package/dist/_chunks/{App-Swmo_WMf.js → App-CnXhqiao.js} +7 -23
- package/dist/_chunks/{index-CXVoFiJp.mjs → index-BWSiu_nE.mjs} +1 -1
- package/dist/_chunks/{index-BpKkUIJY.js → index-BaPVw3mi.js} +1 -1
- package/dist/admin/index.js +1 -1
- package/dist/admin/index.mjs +1 -1
- package/dist/server/index.js +8 -3
- package/dist/server/index.mjs +8 -3
- package/package.json +1 -1
|
@@ -4,11 +4,11 @@ import { Link, useNavigate, NavLink, useParams, Routes, Route } from "react-rout
|
|
|
4
4
|
import { useRef, useState, useEffect, useCallback, useMemo } from "react";
|
|
5
5
|
import { EmptyStateLayout, Button, Tr, Box, Table, Thead, Th, Typography, VisuallyHidden, Tbody, Td, Flex, IconButton, Modal, TextInput, Link as Link$1, Accordion, Main, Loader, Field, Textarea, Grid, Dialog } from "@strapi/design-system";
|
|
6
6
|
import { Plus, ArrowRight, Search, ArrowLeft, Cross, Check, Pencil, Trash } from "@strapi/icons";
|
|
7
|
-
import { useIntl } from "react-intl";
|
|
8
7
|
import qs from "qs";
|
|
9
|
-
import { P as PLUGIN_ID, R as RobotIcon, M as MarkdownEditor } from "./index-
|
|
8
|
+
import { P as PLUGIN_ID, R as RobotIcon, M as MarkdownEditor } from "./index-BWSiu_nE.mjs";
|
|
10
9
|
import styled from "styled-components";
|
|
11
10
|
import ReactMarkdown from "react-markdown";
|
|
11
|
+
import { useIntl } from "react-intl";
|
|
12
12
|
const Illo = () => /* @__PURE__ */ jsxs("svg", { width: "159", height: "88", viewBox: "0 0 159 88", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: [
|
|
13
13
|
/* @__PURE__ */ jsx(
|
|
14
14
|
"path",
|
|
@@ -470,7 +470,6 @@ function debounce(func, wait) {
|
|
|
470
470
|
};
|
|
471
471
|
}
|
|
472
472
|
function HomePage() {
|
|
473
|
-
const { formatMessage } = useIntl();
|
|
474
473
|
const { get } = useFetchClient();
|
|
475
474
|
const navigate = useNavigate();
|
|
476
475
|
const [embeddings, setEmbeddings] = useState(null);
|
|
@@ -519,14 +518,8 @@ function HomePage() {
|
|
|
519
518
|
/* @__PURE__ */ jsx(
|
|
520
519
|
Layouts.Header,
|
|
521
520
|
{
|
|
522
|
-
title:
|
|
523
|
-
|
|
524
|
-
defaultMessage: "Content Embeddings"
|
|
525
|
-
}),
|
|
526
|
-
subtitle: formatMessage({
|
|
527
|
-
id: "HomePage.header.subtitle",
|
|
528
|
-
defaultMessage: "Manage your content embeddings"
|
|
529
|
-
})
|
|
521
|
+
title: "Content Embeddings",
|
|
522
|
+
subtitle: "Manage your content embeddings"
|
|
530
523
|
}
|
|
531
524
|
),
|
|
532
525
|
/* @__PURE__ */ jsx(Layouts.Content, { children: /* @__PURE__ */ jsx(Flex, { justifyContent: "center", padding: 8, children: /* @__PURE__ */ jsx(Loader, { children: "Loading..." }) }) }),
|
|
@@ -538,14 +531,8 @@ function HomePage() {
|
|
|
538
531
|
/* @__PURE__ */ jsx(
|
|
539
532
|
Layouts.Header,
|
|
540
533
|
{
|
|
541
|
-
title:
|
|
542
|
-
|
|
543
|
-
defaultMessage: "Content Embeddings"
|
|
544
|
-
}),
|
|
545
|
-
subtitle: formatMessage({
|
|
546
|
-
id: "HomePage.header.subtitle",
|
|
547
|
-
defaultMessage: "Manage your content embeddings"
|
|
548
|
-
})
|
|
534
|
+
title: "Content Embeddings",
|
|
535
|
+
subtitle: "Manage your content embeddings"
|
|
549
536
|
}
|
|
550
537
|
),
|
|
551
538
|
/* @__PURE__ */ jsx(Layouts.Content, { children: /* @__PURE__ */ jsx(EmptyState, {}) }),
|
|
@@ -556,10 +543,7 @@ function HomePage() {
|
|
|
556
543
|
/* @__PURE__ */ jsx(
|
|
557
544
|
Layouts.Header,
|
|
558
545
|
{
|
|
559
|
-
title:
|
|
560
|
-
id: "HomePage.header.title",
|
|
561
|
-
defaultMessage: "Content Embeddings"
|
|
562
|
-
}),
|
|
546
|
+
title: "Content Embeddings",
|
|
563
547
|
subtitle: `${embeddings?.count || 0} results found`,
|
|
564
548
|
primaryAction: /* @__PURE__ */ jsx(Button, { startIcon: /* @__PURE__ */ jsx(Plus, {}), onClick: handleCreateNew, children: "Create new embedding" })
|
|
565
549
|
}
|
|
@@ -6,11 +6,11 @@ const reactRouterDom = require("react-router-dom");
|
|
|
6
6
|
const react = require("react");
|
|
7
7
|
const designSystem = require("@strapi/design-system");
|
|
8
8
|
const icons = require("@strapi/icons");
|
|
9
|
-
const reactIntl = require("react-intl");
|
|
10
9
|
const qs = require("qs");
|
|
11
|
-
const index = require("./index-
|
|
10
|
+
const index = require("./index-BaPVw3mi.js");
|
|
12
11
|
const styled = require("styled-components");
|
|
13
12
|
const ReactMarkdown = require("react-markdown");
|
|
13
|
+
const reactIntl = require("react-intl");
|
|
14
14
|
const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
|
|
15
15
|
const qs__default = /* @__PURE__ */ _interopDefault(qs);
|
|
16
16
|
const styled__default = /* @__PURE__ */ _interopDefault(styled);
|
|
@@ -476,7 +476,6 @@ function debounce(func, wait) {
|
|
|
476
476
|
};
|
|
477
477
|
}
|
|
478
478
|
function HomePage() {
|
|
479
|
-
const { formatMessage } = reactIntl.useIntl();
|
|
480
479
|
const { get } = admin.useFetchClient();
|
|
481
480
|
const navigate = reactRouterDom.useNavigate();
|
|
482
481
|
const [embeddings, setEmbeddings] = react.useState(null);
|
|
@@ -525,14 +524,8 @@ function HomePage() {
|
|
|
525
524
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
526
525
|
admin.Layouts.Header,
|
|
527
526
|
{
|
|
528
|
-
title:
|
|
529
|
-
|
|
530
|
-
defaultMessage: "Content Embeddings"
|
|
531
|
-
}),
|
|
532
|
-
subtitle: formatMessage({
|
|
533
|
-
id: "HomePage.header.subtitle",
|
|
534
|
-
defaultMessage: "Manage your content embeddings"
|
|
535
|
-
})
|
|
527
|
+
title: "Content Embeddings",
|
|
528
|
+
subtitle: "Manage your content embeddings"
|
|
536
529
|
}
|
|
537
530
|
),
|
|
538
531
|
/* @__PURE__ */ jsxRuntime.jsx(admin.Layouts.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { justifyContent: "center", padding: 8, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Loader, { children: "Loading..." }) }) }),
|
|
@@ -544,14 +537,8 @@ function HomePage() {
|
|
|
544
537
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
545
538
|
admin.Layouts.Header,
|
|
546
539
|
{
|
|
547
|
-
title:
|
|
548
|
-
|
|
549
|
-
defaultMessage: "Content Embeddings"
|
|
550
|
-
}),
|
|
551
|
-
subtitle: formatMessage({
|
|
552
|
-
id: "HomePage.header.subtitle",
|
|
553
|
-
defaultMessage: "Manage your content embeddings"
|
|
554
|
-
})
|
|
540
|
+
title: "Content Embeddings",
|
|
541
|
+
subtitle: "Manage your content embeddings"
|
|
555
542
|
}
|
|
556
543
|
),
|
|
557
544
|
/* @__PURE__ */ jsxRuntime.jsx(admin.Layouts.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(EmptyState, {}) }),
|
|
@@ -562,10 +549,7 @@ function HomePage() {
|
|
|
562
549
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
563
550
|
admin.Layouts.Header,
|
|
564
551
|
{
|
|
565
|
-
title:
|
|
566
|
-
id: "HomePage.header.title",
|
|
567
|
-
defaultMessage: "Content Embeddings"
|
|
568
|
-
}),
|
|
552
|
+
title: "Content Embeddings",
|
|
569
553
|
subtitle: `${embeddings?.count || 0} results found`,
|
|
570
554
|
primaryAction: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { startIcon: /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}), onClick: handleCreateNew, children: "Create new embedding" })
|
|
571
555
|
}
|
|
@@ -655,7 +655,7 @@ const index = {
|
|
|
655
655
|
defaultMessage: PLUGIN_ID
|
|
656
656
|
},
|
|
657
657
|
Component: async () => {
|
|
658
|
-
const { App } = await Promise.resolve().then(() => require("./App-
|
|
658
|
+
const { App } = await Promise.resolve().then(() => require("./App-CnXhqiao.js"));
|
|
659
659
|
return App;
|
|
660
660
|
}
|
|
661
661
|
});
|
package/dist/admin/index.js
CHANGED
package/dist/admin/index.mjs
CHANGED
package/dist/server/index.js
CHANGED
|
@@ -220,8 +220,12 @@ class PluginManager {
|
|
|
220
220
|
this.embeddings,
|
|
221
221
|
this.vectorStoreConfig
|
|
222
222
|
);
|
|
223
|
-
const
|
|
224
|
-
const
|
|
223
|
+
const resultsWithScores = await vectorStore.similaritySearchWithScore(query, 6);
|
|
224
|
+
const SIMILARITY_THRESHOLD = 0.5;
|
|
225
|
+
const relevantResults = resultsWithScores.filter(([_, score]) => score < SIMILARITY_THRESHOLD);
|
|
226
|
+
const topResults = relevantResults.slice(0, 3);
|
|
227
|
+
const sourceDocuments = topResults.map(([doc]) => doc);
|
|
228
|
+
const bestMatchForDisplay = topResults.length > 0 ? [topResults[0][0]] : [];
|
|
225
229
|
const formatDocs = (docs) => {
|
|
226
230
|
return docs.map((doc) => {
|
|
227
231
|
const title = doc.metadata?.title ? `Title: ${doc.metadata.title}
|
|
@@ -252,7 +256,8 @@ Context:
|
|
|
252
256
|
const text = await ragChain.invoke(query);
|
|
253
257
|
return {
|
|
254
258
|
text,
|
|
255
|
-
sourceDocuments
|
|
259
|
+
sourceDocuments: bestMatchForDisplay
|
|
260
|
+
// Only return best match to display
|
|
256
261
|
};
|
|
257
262
|
} catch (error) {
|
|
258
263
|
console.error(`Failed to query embeddings: ${error}`);
|
package/dist/server/index.mjs
CHANGED
|
@@ -219,8 +219,12 @@ class PluginManager {
|
|
|
219
219
|
this.embeddings,
|
|
220
220
|
this.vectorStoreConfig
|
|
221
221
|
);
|
|
222
|
-
const
|
|
223
|
-
const
|
|
222
|
+
const resultsWithScores = await vectorStore.similaritySearchWithScore(query, 6);
|
|
223
|
+
const SIMILARITY_THRESHOLD = 0.5;
|
|
224
|
+
const relevantResults = resultsWithScores.filter(([_, score]) => score < SIMILARITY_THRESHOLD);
|
|
225
|
+
const topResults = relevantResults.slice(0, 3);
|
|
226
|
+
const sourceDocuments = topResults.map(([doc]) => doc);
|
|
227
|
+
const bestMatchForDisplay = topResults.length > 0 ? [topResults[0][0]] : [];
|
|
224
228
|
const formatDocs = (docs) => {
|
|
225
229
|
return docs.map((doc) => {
|
|
226
230
|
const title = doc.metadata?.title ? `Title: ${doc.metadata.title}
|
|
@@ -251,7 +255,8 @@ Context:
|
|
|
251
255
|
const text = await ragChain.invoke(query);
|
|
252
256
|
return {
|
|
253
257
|
text,
|
|
254
|
-
sourceDocuments
|
|
258
|
+
sourceDocuments: bestMatchForDisplay
|
|
259
|
+
// Only return best match to display
|
|
255
260
|
};
|
|
256
261
|
} catch (error) {
|
|
257
262
|
console.error(`Failed to query embeddings: ${error}`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "strapi-content-embeddings",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "Strapi v5 plugin for vector embeddings with OpenAI and Neon PostgreSQL. Enables semantic search, RAG chat, and MCP (Model Context Protocol) integration.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"strapi",
|