@trustgraph/react-state 1.4.6 → 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) => {
@@ -1531,7 +1530,7 @@ const addRowEmbeddings = (socket, add, remove) => (entities) => {
1531
1530
  const act = "Embeddings " + text.substring(0, 20);
1532
1531
  add(act);
1533
1532
  return socket
1534
- .embeddings(text)
1533
+ .embeddings([text])
1535
1534
  .then((x) => {
1536
1535
  if (x && x.length > 0) {
1537
1536
  remove(act);
@@ -1575,7 +1574,8 @@ const vectorSearch = (socket, flowId, addActivity, removeActivity, term, collect
1575
1574
  const searchAct = "Search: " + term;
1576
1575
  addActivity(searchAct);
1577
1576
  return api
1578
- .embeddings(term)
1577
+ .embeddings([term])
1578
+ .then((vecs) => vecs[0])
1579
1579
  .then(getGraphEmbeddings(api, addActivity, removeActivity, limit || 10, collection))
1580
1580
  .then(addRowLabels(api, addActivity, removeActivity, collection))
1581
1581
  .then(addRowDefinitions(api, addActivity, removeActivity, collection))
@@ -1756,7 +1756,8 @@ const useInference = ({ flow } = {}) => {
1756
1756
  })
1757
1757
  : await socket.flow(effectiveFlow).graphRag(input, options || {}, collection);
1758
1758
  // Get embeddings for entity discovery
1759
- const embeddings = await socket.flow(effectiveFlow).embeddings(input);
1759
+ const allEmbeddings = await socket.flow(effectiveFlow).embeddings([input]);
1760
+ const embeddings = allEmbeddings[0];
1760
1761
  // Query graph embeddings to find entities
1761
1762
  const entities = await socket
1762
1763
  .flow(effectiveFlow)
@@ -1895,7 +1896,10 @@ const useChatSession = ({ flow } = {}) => {
1895
1896
  // Start embeddings activity
1896
1897
  addActivity(embActivity);
1897
1898
  // Get labels for each entity
1898
- 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;
1899
1903
  const labelActivity = "Label " + getTermValue$2(entity);
1900
1904
  addActivity(labelActivity);
1901
1905
  try {
@@ -2314,7 +2318,7 @@ const useEmbeddings = ({ flow, term }) => {
2314
2318
  queryFn: () => {
2315
2319
  return socket
2316
2320
  .flow(effectiveFlow)
2317
- .embeddings(term)
2321
+ .embeddings([term])
2318
2322
  .then((x) => {
2319
2323
  if (x["error"]) {
2320
2324
  console.log("Error:", x);