strapi-content-embeddings 0.1.2 → 0.1.3

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.
@@ -220,8 +220,12 @@ class PluginManager {
220
220
  this.embeddings,
221
221
  this.vectorStoreConfig
222
222
  );
223
- const retriever = vectorStore.asRetriever({ k: 4 });
224
- const sourceDocuments = await retriever.invoke(query);
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}`);
@@ -219,8 +219,12 @@ class PluginManager {
219
219
  this.embeddings,
220
220
  this.vectorStoreConfig
221
221
  );
222
- const retriever = vectorStore.asRetriever({ k: 4 });
223
- const sourceDocuments = await retriever.invoke(query);
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.2",
3
+ "version": "0.1.3",
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",