semantic_search_requests
Search for specific requests within a page URL using semantic querying to retrieve the top 10 relevant results. Ideal for analyzing and extracting targeted browser interactions.
Instructions
Semantically search for requests that occurred within a page URL. Returns the top 10 results.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| page_url | Yes | The page within which to search for requests | |
| query | Yes | Your search request. Make this specific and detailed to get the best results |
Implementation Reference
- utilities.ts:79-98 (handler)The main handler function that performs semantic search on requests using embeddings and cosine similarity, returning top 10 matches.export async function semanticSearchRequestsSentTransformer( query: string, requests: Array<RequestRecord>, pipeline: FeatureExtractionPipeline ): Promise<Array<RequestRecord & { similarity: number }>> { // Get embedding for the query const queryEmbedding = await getEmbeddingSentTransformer(query, pipeline); // Calculate cosine similarity scores for all requests const scoredRequests = requests.map((request) => { // Compute cosine similarity between query and request embeddings const similarity = cosineSimilarity(queryEmbedding, request.embedding); return { ...request, similarity }; }); // Sort by similarity score (highest first) and take top 10 return scoredRequests .sort((a, b) => b.similarity - a.similarity) .slice(0, 10); }
- index.ts:70-88 (registration)Registration of the 'semantic_search_requests' tool in the TOOLS array, including name, description, and input schema.name: "semantic_search_requests", description: "Semantically search for requests that occurred within a page URL. Returns the top 10 results.", inputSchema: { type: "object", properties: { query: { type: "string", description: "Your search request. Make this specific and detailed to get the best results", }, page_url: { type: "string", description: "The page within which to search for requests", }, }, required: ["query", "page_url"], }, },
- index.ts:229-250 (handler)Tool dispatch handler in the main switch that calls the semantic search transformer function.case "semantic_search_requests": { if (!pipeline) { return { content: [{ type: "text", text: "Model not defined" }], isError: true, }; } const searchResults = await semanticSearchRequestsSentTransformer( args.query, requests.get(args.page_url), pipeline ); const withoutEmbedding = searchResults.map( ({ embedding, similarity, ...rest }) => rest ); return { content: [ { type: "text", text: JSON.stringify(withoutEmbedding, null, 2) }, ], isError: false, }; }
- utilities.ts:101-106 (helper)Helper function to compute cosine similarity used in semantic search.function cosineSimilarity(a: number[], b: number[]): number { const dotProduct = a.reduce((sum, val, i) => sum + val * b[i], 0); const magnitudeA = Math.sqrt(a.reduce((sum, val) => sum + val * val, 0)); const magnitudeB = Math.sqrt(b.reduce((sum, val) => sum + val * val, 0)); return dotProduct / (magnitudeA * magnitudeB); }
- utilities.ts:59-65 (helper)Helper function to get embeddings using the transformer pipeline.export async function getEmbeddingSentTransformer( text: string, pipeline: FeatureExtractionPipeline ): Promise<number[]> { const embedding = await pipeline(text); return Array.from(embedding.data); }