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