@trustgraph/react-state 1.5.1 → 1.5.2

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/index.cjs CHANGED
@@ -1400,9 +1400,9 @@ const useGraphSubgraph = ({ entityUri, flow, collection, }) => {
1400
1400
 
1401
1401
  /**
1402
1402
  * Custom hook for querying graph embeddings
1403
- * Finds graph entities similar to the provided embedding vectors
1403
+ * Finds graph entities similar to the provided embedding vector
1404
1404
  */
1405
- const useGraphEmbeddings = ({ flow, vecs, limit = 10, collection }) => {
1405
+ const useGraphEmbeddings = ({ flow, vec, limit = 10, collection }) => {
1406
1406
  const socket = reactProvider.useSocket();
1407
1407
  const notify = useNotification();
1408
1408
  const { settings } = useSettings();
@@ -1410,12 +1410,12 @@ const useGraphEmbeddings = ({ flow, vecs, limit = 10, collection }) => {
1410
1410
  const effectiveFlow = flow ?? sessionFlowId;
1411
1411
  const effectiveCollection = collection ?? settings.collection;
1412
1412
  const query = reactQuery.useQuery({
1413
- queryKey: ["graph-embeddings", { flow: effectiveFlow, vecs, limit, collection: effectiveCollection }],
1414
- enabled: !!vecs && vecs.length > 0 && !!effectiveFlow,
1413
+ queryKey: ["graph-embeddings", { flow: effectiveFlow, vec, limit, collection: effectiveCollection }],
1414
+ enabled: !!vec && vec.length > 0 && !!effectiveFlow,
1415
1415
  queryFn: () => {
1416
1416
  return socket
1417
1417
  .flow(effectiveFlow)
1418
- .graphEmbeddingsQuery(vecs, limit, effectiveCollection)
1418
+ .graphEmbeddingsQuery(vec, limit, effectiveCollection)
1419
1419
  .catch((err) => {
1420
1420
  const message = err instanceof Error ? err.message : String(err);
1421
1421
  notify.error(message);
@@ -1433,24 +1433,23 @@ const useGraphEmbeddings = ({ flow, vecs, limit = 10, collection }) => {
1433
1433
  };
1434
1434
  };
1435
1435
 
1436
- // Take the embeddings, and lookup entities using graph
1436
+ // Take the embedding vector, and lookup entities using graph
1437
1437
  // embeddings, add embedding to each entity row, just an easy
1438
1438
  // place to put it
1439
1439
  const getGraphEmbeddings = (socket, add, remove, limit, collection) => {
1440
- // Take the embeddings, and lookup entities using graph
1441
- // embeddings, add embedding to each entity row, just an easy
1442
- // place to put it
1443
- return (vecs) => {
1440
+ // Take the embedding, and lookup entities using graph
1441
+ // embeddings, add embedding to each entity row
1442
+ return (vec) => {
1444
1443
  const act = "Graph embedding search";
1445
1444
  add(act);
1446
1445
  return socket
1447
- .graphEmbeddingsQuery(vecs, limit , collection)
1448
- .then((ents) => {
1446
+ .graphEmbeddingsQuery(vec, limit , collection)
1447
+ .then((matches) => {
1449
1448
  remove(act);
1450
- return ents
1451
- .filter((ent) => ent.t === "i")
1452
- .map((ent) => {
1453
- return { uri: ent.i, target: vecs[0] };
1449
+ return matches
1450
+ .filter((m) => m.entity !== null && m.entity.t === "i")
1451
+ .map((m) => {
1452
+ return { uri: m.entity.i, target: vec };
1454
1453
  });
1455
1454
  })
1456
1455
  .catch((err) => {
@@ -1533,11 +1532,11 @@ const addRowEmbeddings = (socket, add, remove) => (entities) => {
1533
1532
  return socket
1534
1533
  .embeddings([text])
1535
1534
  .then((x) => {
1536
- if (x && x.length > 0 && x[0].length > 0) {
1535
+ if (x && x.length > 0) {
1537
1536
  remove(act);
1538
1537
  return {
1539
1538
  ...ent,
1540
- embeddings: x[0][0],
1539
+ embeddings: x[0],
1541
1540
  };
1542
1541
  }
1543
1542
  else {
@@ -1897,7 +1896,10 @@ const useChatSession = ({ flow } = {}) => {
1897
1896
  // Start embeddings activity
1898
1897
  addActivity(embActivity);
1899
1898
  // Get labels for each entity
1900
- const labelPromises = result.entities.map(async (entity) => {
1899
+ const labelPromises = result.entities
1900
+ .filter((match) => match.entity !== null)
1901
+ .map(async (match) => {
1902
+ const entity = match.entity;
1901
1903
  const labelActivity = "Label " + getTermValue$2(entity);
1902
1904
  addActivity(labelActivity);
1903
1905
  try {