import { OpenAssistantTool } from '@openassistant/utils'; import { z } from 'zod'; import { WeightsMeta, CreateWeightsProps } from '@geoda/core'; import { WeightsProps, GetGeometries } from '../types'; /** * @internal */ export declare const globalWeightsData: Record; export type SpatialWeightsFunctionArgs = z.ZodObject<{ datasetName: z.ZodString; type: z.ZodEnum<['knn', 'queen', 'rook', 'threshold']>; k: z.ZodOptional; orderOfContiguity: z.ZodOptional; includeLowerOrder: z.ZodOptional; precisionThreshold: z.ZodOptional; distanceThreshold: z.ZodOptional; isMile: z.ZodOptional; useCentroids: z.ZodOptional; mapBounds: z.ZodOptional>; }>; export type SpatialWeightsLlmResult = { success: boolean; weightsId?: string; weightsMeta?: WeightsMeta; result?: string; error?: string; instruction?: string; }; export type SpatialWeightsAdditionalData = { weightsId: string; [id: string]: string | { type: 'weights'; content: { weights: number[][]; weightsMeta: WeightsMeta; }; }; }; /** * ## spatialWeights Tool * * This tool creates spatial weights matrices for spatial analysis. * Spatial weights define the spatial relationships between observations and are essential for spatial autocorrelation analysis. * * ### Spatial Weights Methods * * The tool supports various spatial weights methods: * - **queen**: Queen contiguity (shares edge or vertex) * - **rook**: Rook contiguity (shares edge only) * - **knn**: K-nearest neighbors * - **threshold**: Distance-based weights * * ### Parameters * - `datasetName`: Name of the dataset containing the geometries * - `type`: Spatial weights method to use (see above) * - `k`: Number of neighbors for knn method (optional) * - `orderOfContiguity`: Order of contiguity for queen/rook (optional) * - `includeLowerOrder`: Include lower order contiguity (optional) * - `precisionThreshold`: Precision threshold for geometry operations (optional) * - `distanceThreshold`: Distance threshold for threshold method (optional) * - `isMile`: Use miles instead of kilometers for distance (optional) * - `useCentroids`: Use centroids instead of full geometries (optional) * - `mapBounds`: Map bounds for visualization (optional) * * **Example user prompts:** * - "Create spatial weights using queen contiguity" * - "Generate k-nearest neighbors weights with k=5" * - "Make distance-based weights with 10km threshold" * * ### Example * ```typescript * import { spatialWeights } from "@openassistant/geoda"; * import { convertToVercelAiTool } from "@openassistant/utils"; * * const weightsTool = { * ...spatialWeights, * context: { * getGeometries: async (datasetName: string) => { * // Implementation to retrieve geometries from your data source * return geometries; * }, * }, * }; * * const result = await generateText({ * model: openai('gpt-4.1', { apiKey: key }), * prompt: 'Create spatial weights using queen contiguity', * tools: { spatialWeights: convertToVercelAiTool(weightsTool) }, * }); * ``` * * :::note * The spatialWeights tool should always be used with other spatial analysis tools like globalMoran, lisa, etc. * ::: */ export declare const spatialWeights: OpenAssistantTool; export type SpatialWeightsTool = typeof spatialWeights; export type SpatialWeightsFunctionContext = { getGeometries: GetGeometries; }; export type GetWeights = (datasetName: string, type: 'knn' | 'queen' | 'rook' | 'threshold', options: { k?: number; orderOfContiguity?: number; includeLowerOrder?: boolean; precisionThreshold?: number; distanceThreshold?: number; isMile?: boolean; useCentroids?: boolean; }) => Promise<{ weights: number[][]; weightsMeta: WeightsMeta; }>; export type ExecuteSpatialWeightsResult = { llmResult: { success: boolean; weightsId?: string; weightsMeta?: WeightsMeta; result?: string; error?: string; instruction?: string; }; additionalData?: { [id: string]: unknown; weightsId: string; }; }; export declare function getWeightsId(datasetId: string, weightsProps: CreateWeightsProps, mapBounds?: number[]): string; export declare function getCachedWeights(datasetId: string, createWeightsProps: CreateWeightsProps): { weightsMeta: WeightsMeta; weights: number[][]; } | null; export declare function getCachedWeightsById(weightsId: string): WeightsProps | null; export declare function isWeightsAdditionalData(data: unknown): data is SpatialWeightsAdditionalData;