Skip to main content
Glama

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
NameRequiredDescriptionDefault
page_urlYesThe page within which to search for requests
queryYesYour search request. Make this specific and detailed to get the best results

Implementation Reference

  • 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"], }, },
  • 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, }; }
  • 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); }
  • 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); }

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/jwaldor/mcp-scrape-copilot'

If you have feedback or need assistance with the MCP directory API, please join our Discord server