@@ -65,7 +65,8 @@ type AddVectorRequest struct {
6565type SearchRequest struct {
6666 Vector []float32 `json:"vector"`
6767 Limit int `json:"limit,omitempty"`
68- CollectionName string `json:"collection_name,omitempty"` // Empty = search all (or use exclude)
68+ CollectionName string `json:"collection_name,omitempty"` // Deprecated: use collection_names instead
69+ CollectionNames []string `json:"collection_names,omitempty"` // Search in specific collections (empty = search all)
6970 ExcludeCollections []string `json:"exclude_collections,omitempty"` // Collections to exclude from search
7071}
7172
@@ -133,7 +134,7 @@ func main() {
133134 // Create transport with logging
134135 transport := & mcp.LoggingTransport {
135136 Transport : & mcp.StdioTransport {},
136- Writer : os .Stderr ,
137+ Writer : os .Stderr ,
137138 }
138139
139140 // Run server
@@ -303,7 +304,14 @@ func (vs *VectorServer) registerTools(server *mcp.Server) {
303304 },
304305 "collection_name" : {
305306 Type : "string" ,
306- Description : "Optional: search only within this collection" ,
307+ Description : "Optional: search only within this single collection (deprecated, use collection_names instead)" ,
308+ },
309+ "collection_names" : {
310+ Type : "array" ,
311+ Description : "Optional: search only within these collections. If empty, searches all collections." ,
312+ Items : & jsonschema.Schema {
313+ Type : "string" ,
314+ },
307315 },
308316 "exclude_collections" : {
309317 Type : "array" ,
@@ -527,24 +535,38 @@ func (vs *VectorServer) handleSearch(ctx context.Context, req *mcp.CallToolReque
527535 params .Limit = 10
528536 }
529537
538+ // Support backward compatibility: if collection_name is set, add it to collection_names
539+ if params .CollectionName != "" && len (params .CollectionNames ) == 0 {
540+ params .CollectionNames = []string {params .CollectionName }
541+ }
542+
530543 vectorJSON , _ := json .Marshal (params .Vector )
531544
532545 var rows * sql.Rows
533546 var err error
534547
535- if params .CollectionName != "" {
536- // Search within a specific collection
537- rows , err = vs .db .Query (`
548+ if len (params .CollectionNames ) > 0 {
549+ // Search within specific collections using IN clause
550+ placeholders := make ([]string , len (params .CollectionNames ))
551+ args := []any {string (vectorJSON )}
552+ for i , name := range params .CollectionNames {
553+ placeholders [i ] = "?"
554+ args = append (args , name )
555+ }
556+ args = append (args , params .Limit )
557+
558+ query := fmt .Sprintf (`
538559 SELECT v.id, c.name, v.metadata, vec_distance_cosine(v.vector_blob, vec_f32(?)) as distance
539560 FROM vectors v
540561 JOIN collections c ON v.collection_id = c.id
541- WHERE c.name = ?
562+ WHERE c.name IN (%s)
542563 ORDER BY distance
543564 LIMIT ?
544- ` , string (vectorJSON ), params .CollectionName , params .Limit )
565+ ` , strings .Join (placeholders , "," ))
566+
567+ rows , err = vs .db .Query (query , args ... )
545568 } else if len (params .ExcludeCollections ) > 0 {
546569 // Search across all collections EXCEPT the excluded ones
547- // Build placeholders for the IN clause
548570 placeholders := make ([]string , len (params .ExcludeCollections ))
549571 args := []any {string (vectorJSON )}
550572 for i , name := range params .ExcludeCollections {
0 commit comments