@trustgraph/react-state 1.4.0 → 1.4.1
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 +69 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +69 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/state/row-embeddings-query.d.ts +29 -0
- package/dist/state/row-embeddings-query.d.ts.map +1 -0
- package/package.json +5 -5
package/dist/index.cjs
CHANGED
|
@@ -2159,6 +2159,74 @@ const useStructuredQuery = () => {
|
|
|
2159
2159
|
};
|
|
2160
2160
|
};
|
|
2161
2161
|
|
|
2162
|
+
// @ts-nocheck
|
|
2163
|
+
// React Query hooks for data fetching and mutation management
|
|
2164
|
+
/**
|
|
2165
|
+
* Custom hook for managing row embeddings query operations
|
|
2166
|
+
* Provides functionality for executing semantic searches on structured data indexes
|
|
2167
|
+
* First converts query text to embeddings, then searches for similar records
|
|
2168
|
+
*/
|
|
2169
|
+
const useRowEmbeddingsQuery = () => {
|
|
2170
|
+
// Socket connection for API calls
|
|
2171
|
+
const socket = reactProvider.useSocket();
|
|
2172
|
+
const connectionState = reactProvider.useConnectionState();
|
|
2173
|
+
// Notification system for user feedback
|
|
2174
|
+
const notify = useNotification();
|
|
2175
|
+
// Session state for current flow ID
|
|
2176
|
+
const flowId = useSessionStore((state) => state.flowId);
|
|
2177
|
+
// Settings for default collection
|
|
2178
|
+
const { settings } = useSettings();
|
|
2179
|
+
// Only enable operations when socket is connected and ready
|
|
2180
|
+
const isSocketReady = connectionState?.status === "authenticated" ||
|
|
2181
|
+
connectionState?.status === "unauthenticated";
|
|
2182
|
+
// Mutation for executing row embeddings queries
|
|
2183
|
+
const rowEmbeddingsQueryMutation = reactQuery.useMutation({
|
|
2184
|
+
mutationFn: async ({ query, schemaName, collection, indexName, limit, }) => {
|
|
2185
|
+
if (!isSocketReady) {
|
|
2186
|
+
throw new Error("Socket connection not ready");
|
|
2187
|
+
}
|
|
2188
|
+
const flow = socket.flow(flowId);
|
|
2189
|
+
// First, get embeddings for the query text
|
|
2190
|
+
const vectors = await flow.embeddings(query);
|
|
2191
|
+
// Then query row embeddings with those vectors
|
|
2192
|
+
return flow.rowEmbeddingsQuery(vectors, schemaName, collection || settings.collection, indexName, limit || 10);
|
|
2193
|
+
},
|
|
2194
|
+
onError: (err) => {
|
|
2195
|
+
console.log("Row embeddings query error:", err);
|
|
2196
|
+
const errorMessage = err instanceof Error
|
|
2197
|
+
? err.message
|
|
2198
|
+
: err?.toString() || "Unknown error";
|
|
2199
|
+
notify.error(`Row embeddings query failed: ${errorMessage}`);
|
|
2200
|
+
},
|
|
2201
|
+
onSuccess: (data) => {
|
|
2202
|
+
if (data && data.length > 0) {
|
|
2203
|
+
notify.success(`Found ${data.length} matching record${data.length !== 1 ? 's' : ''}`);
|
|
2204
|
+
}
|
|
2205
|
+
else {
|
|
2206
|
+
notify.info("No matching records found");
|
|
2207
|
+
}
|
|
2208
|
+
},
|
|
2209
|
+
});
|
|
2210
|
+
// Show loading indicator for row embeddings query operations
|
|
2211
|
+
useActivity(rowEmbeddingsQueryMutation.isPending, "Executing row embeddings query");
|
|
2212
|
+
// Return the public API for the hook
|
|
2213
|
+
return {
|
|
2214
|
+
// Query execution
|
|
2215
|
+
executeQuery: rowEmbeddingsQueryMutation.mutate,
|
|
2216
|
+
executeQueryAsync: rowEmbeddingsQueryMutation.mutateAsync,
|
|
2217
|
+
// Query state
|
|
2218
|
+
isExecuting: rowEmbeddingsQueryMutation.isPending,
|
|
2219
|
+
error: rowEmbeddingsQueryMutation.error,
|
|
2220
|
+
// Results
|
|
2221
|
+
matches: rowEmbeddingsQueryMutation.data || [],
|
|
2222
|
+
hasResults: (rowEmbeddingsQueryMutation.data?.length || 0) > 0,
|
|
2223
|
+
// Reset function to clear previous results
|
|
2224
|
+
reset: rowEmbeddingsQueryMutation.reset,
|
|
2225
|
+
// Socket readiness
|
|
2226
|
+
isReady: isSocketReady,
|
|
2227
|
+
};
|
|
2228
|
+
};
|
|
2229
|
+
|
|
2162
2230
|
// React Query hooks for data fetching and mutation management
|
|
2163
2231
|
/**
|
|
2164
2232
|
* Custom hook for managing GraphQL rows queries
|
|
@@ -4622,6 +4690,7 @@ exports.useParameterValidation = useParameterValidation;
|
|
|
4622
4690
|
exports.useProcessing = useProcessing;
|
|
4623
4691
|
exports.useProgressStateStore = useProgressStateStore;
|
|
4624
4692
|
exports.usePrompts = usePrompts;
|
|
4693
|
+
exports.useRowEmbeddingsQuery = useRowEmbeddingsQuery;
|
|
4625
4694
|
exports.useRowsQuery = useRowsQuery;
|
|
4626
4695
|
exports.useSchemas = useSchemas;
|
|
4627
4696
|
exports.useSearchStateStore = useSearchStateStore;
|