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