Skip to main content
Glama

Performs vector similarity search

vector_search

Find similar items by comparing a query vector against stored vectors in a database table column.

Instructions

Performs vector similarity search

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
tableYesTable name
vector_columnYesColumn containing vectors
query_vectorYesQuery vector for similarity search
limitNoMaximum number of results (optional, default 10)
databaseNoDatabase name (optional, uses context if not provided)

Implementation Reference

  • VectorSearchSchema - Zod schema defining the input parameters for vector_search tool: table, vector_column, query_vector (number array), limit (optional), and database (optional).
    const VectorSearchSchema = z.object({
    	table: z.string().describe('Table name'),
    	vector_column: z.string().describe('Column containing vectors'),
    	query_vector: z.array(z.number()).describe('Query vector for similarity search'),
    	limit: z.number().optional().describe('Maximum number of results (optional, default 10)'),
    	database: z.string().optional().describe('Database name (optional, uses context if not provided)'),
    });
  • The vector_search tool handler - constructs a SQL query using vector_distance() and vector_from_json() functions, executes it via the database client, and returns formatted results with distances.
    server.tool(
    	{
    		name: 'vector_search',
    		description: 'Performs vector similarity search',
    		schema: VectorSearchSchema,
    	},
    	async ({ table, vector_column, query_vector, limit = 10, database }) => {
    		try {
    			const database_name = resolve_database_name(database);
    			if (database) set_current_database(database);
    
    			// Construct a vector search query using SQLite's vector functions
    			const vector_string = query_vector.join(',');
    			const query = `
             SELECT *, vector_distance(${vector_column}, vector_from_json(?)) as distance
             FROM ${table}
             ORDER BY distance ASC
             LIMIT ?
           `;
    
    			const params = {
    				1: `[${vector_string}]`,
    				2: limit,
    			};
    
    			const result = await database_client.execute_query(
    				database_name,
    				query,
    				params,
    			);
    
    			const formatted_result = format_query_result(result);
    			return create_tool_response({
    				database: database_name,
    				table,
    				vector_column,
    				query_vector,
    				results: formatted_result,
    			});
    		} catch (error) {
    			return create_tool_error_response(error);
    		}
    	},
    );
  • Tool registration via server.tool() call with name 'vector_search', description 'Performs vector similarity search', and the VectorSearchSchema.
    server.tool(
    	{
    		name: 'vector_search',
    		description: 'Performs vector similarity search',
    		schema: VectorSearchSchema,
    	},
    	async ({ table, vector_column, query_vector, limit = 10, database }) => {
    		try {
    			const database_name = resolve_database_name(database);
    			if (database) set_current_database(database);
    
    			// Construct a vector search query using SQLite's vector functions
    			const vector_string = query_vector.join(',');
    			const query = `
             SELECT *, vector_distance(${vector_column}, vector_from_json(?)) as distance
             FROM ${table}
             ORDER BY distance ASC
             LIMIT ?
           `;
    
    			const params = {
    				1: `[${vector_string}]`,
    				2: limit,
    			};
    
    			const result = await database_client.execute_query(
    				database_name,
    				query,
    				params,
    			);
    
    			const formatted_result = format_query_result(result);
    			return create_tool_response({
    				database: database_name,
    				table,
    				vector_column,
    				query_vector,
    				results: formatted_result,
    			});
    		} catch (error) {
    			return create_tool_error_response(error);
    		}
    	},
    );
  • The execute_query helper function used by the vector_search handler to execute the generated SQL query against a Turso database via the libSQL client.
    export async function execute_query(
    	database_name: string,
    	query: string,
    	params: Record<string, any> = {},
    ): Promise<ResultSet> {
    	try {
    		// Determine if this is a read-only query
    		const is_read_only = query
    			.trim()
    			.toLowerCase()
    			.startsWith('select');
    		const permission = is_read_only ? 'read-only' : 'full-access';
    
    		const client = await get_database_client(
    			database_name,
    			permission,
    		);
    
    		// Execute the query
    		return await client.execute({
    			sql: query,
    			args: convert_parameters(params),
    		});
    	} catch (error) {
    		throw new TursoApiError(
    			`Failed to execute query for database ${database_name}: ${
    				(error as Error).message
    			}`,
    			500,
    		);
    	}
    }
  • The resolve_database_name helper used by the vector_search handler to determine which database to query, falling back to context or config default.
    export function resolve_database_name(
    	provided_name?: string,
    ): string {
    	const database_name = provided_name || get_current_database();
    
    	if (!database_name) {
    		throw new Error(
    			'No database specified. Please provide a database name or set a default database.',
    		);
    	}
    
    	return database_name;
    }
Behavior1/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, and the description contains no behavioral traits such as read-only nature, authentication requirements, or side effects. It completely lacks transparency.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness2/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is one short sentence, but it is under-specified. It fails to convey essential information, making it too brief to be useful.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness1/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

With 5 parameters and no output schema, the description should explain the tool's behavior and return values. It provides none of these, making it severely incomplete.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, so the baseline is 3. The description adds no additional meaning beyond what the schema already provides, so no improvement.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose1/5

Does the description clearly state what the tool does and how it differs from similar tools?

Tautological: description restates name/title.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description offers no guidance on when to use this tool versus its siblings (e.g., execute_query, list_tables). It fails to specify contexts or alternatives.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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/spences10/mcp-turso-cloud'

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