diff --git a/localization/v2.5.x/site/en/userGuide/search-query-get/filtered-search.json b/localization/v2.5.x/site/en/userGuide/search-query-get/filtered-search.json index 49765be15..375a173aa 100644 --- a/localization/v2.5.x/site/en/userGuide/search-query-get/filtered-search.json +++ b/localization/v2.5.x/site/en/userGuide/search-query-get/filtered-search.json @@ -1 +1 @@ -{"codeList":["[​\n {\"id\": 0, \"vector\": [0.3580376395471989, -0.6023495712049978, 0.18414012509913835, -0.26286205330961354, 0.9029438446296592], \"color\": \"pink_8682\", \"likes\": 165},​\n {\"id\": 1, \"vector\": [0.19886812562848388, 0.06023560599112088, 0.6976963061752597, 0.2614474506242501, 0.838729485096104], \"color\": \"red_7025\", \"likes\": 25},​\n {\"id\": 2, \"vector\": [0.43742130801983836, -0.5597502546264526, 0.6457887650909682, 0.7894058910881185, 0.20785793220625592], \"color\": \"orange_6781\", \"likes\": 764},​\n {\"id\": 3, \"vector\": [0.3172005263489739, 0.9719044792798428, -0.36981146090600725, -0.4860894583077995, 0.95791889146345], \"color\": \"pink_9298\", \"likes\": 234},​\n {\"id\": 4, \"vector\": [0.4452349528804562, -0.8757026943054742, 0.8220779437047674, 0.46406290649483184, 0.30337481143159106], \"color\": \"red_4794\", \"likes\": 122},​\n {\"id\": 5, \"vector\": [0.985825131989184, -0.8144651566660419, 0.6299267002202009, 0.1206906911183383, -0.1446277761879955], \"color\": \"yellow_4222\", \"likes\": 12},​\n {\"id\": 6, \"vector\": [0.8371977790571115, -0.015764369584852833, -0.31062937026679327, -0.562666951622192, -0.8984947637863987], \"color\": \"red_9392\", \"likes\": 58},​\n {\"id\": 7, \"vector\": [-0.33445148015177995, -0.2567135004164067, 0.8987539745369246, 0.9402995886420709, 0.5378064918413052], \"color\": \"grey_8510\", \"likes\": 775},​\n {\"id\": 8, \"vector\": [0.39524717779832685, 0.4000257286739164, -0.5890507376891594, -0.8650502298996872, -0.6140360785406336], \"color\": \"white_9381\", \"likes\": 876},​\n {\"id\": 9, \"vector\": [0.5718280481994695, 0.24070317428066512, -0.3737913482606834, -0.06726932177492717, -0.6980531615588608], \"color\": \"purple_4976\", \"likes\": 765}​\n]​\n\n","from pymilvus import MilvusClient​\n​\nclient = MilvusClient(​\n uri=\"http://localhost:19530\",​\n token=\"root:Milvus\"​\n)​\n​\nquery_vector = [0.3580376395471989, -0.6023495712049978, 0.18414012509913835, -0.26286205330961354, 0.9029438446296592]​\n​\nres = client.search(​\n collection_name=\"my_collection\",​\n data=[query_vector],​\n limit=5,​\n # highlight-start​\n filter='color like \"red%\" and likes > 50',​\n output_fields=[\"color\", \"likes\"]​\n # highlight-end​\n)​\n​\nfor hits in res:​\n print(\"TopK results:\")​\n for hit in hits:​\n print(hit)​\n\n","import io.milvus.v2.client.ConnectConfig;​\nimport io.milvus.v2.client.MilvusClientV2;​\nimport io.milvus.v2.service.vector.request.SearchReq​\nimport io.milvus.v2.service.vector.request.data.FloatVec;​\nimport io.milvus.v2.service.vector.response.SearchResp​\n​\nMilvusClientV2 client = new MilvusClientV2(ConnectConfig.builder()​\n .uri(\"http://localhost:19530\")​\n .token(\"root:Milvus\")​\n .build());​\n​\nFloatVec queryVector = new FloatVec(new float[]{0.3580376395471989f, -0.6023495712049978f, 0.18414012509913835f, -0.26286205330961354f, 0.9029438446296592f});​\nSearchReq searchReq = SearchReq.builder()​\n .collectionName(\"filtered_search_collection\")​\n .data(Collections.singletonList(queryVector))​\n .topK(5)​\n .filter(\"color like \\\"red%\\\" and likes > 50\")​\n .outputFields(Arrays.asList(\"color\", \"likes\"))​\n .build();​\n​\nSearchResp searchResp = client.search(searchReq);​\n​\nList> searchResults = searchResp.getSearchResults();​\nfor (List results : searchResults) {​\n System.out.println(\"TopK results:\");​\n for (SearchResp.SearchResult result : results) {​\n System.out.println(result);​\n }​\n}​\n​\n// Output​\n// TopK results:​\n// SearchResp.SearchResult(entity={color=red_4794, likes=122}, score=0.5975797, id=4)​\n// SearchResp.SearchResult(entity={color=red_9392, likes=58}, score=-0.24996188, id=6)​\n\n","import (​\n \"context\"​\n \"log\"​\n​\n \"github.com/milvus-io/milvus/client/v2\"​\n \"github.com/milvus-io/milvus/client/v2/entity\"​\n)​\n​\nfunc ExampleClient_Search_filter() {​\n ctx, cancel := context.WithCancel(context.Background())​\n defer cancel()​\n​\n milvusAddr := \"127.0.0.1:19530\"​\n token := \"root:Milvus\"​\n​\n cli, err := client.New(ctx, &client.ClientConfig{​\n Address: milvusAddr,​\n APIKey: token,​\n })​\n if err != nil {​\n log.Fatal(\"failed to connect to milvus server: \", err.Error())​\n }​\n​\n defer cli.Close(ctx)​\n​\n queryVector := []float32{0.3580376395471989, -0.6023495712049978, 0.18414012509913835, -0.26286205330961354, 0.9029438446296592}​\n​\n resultSets, err := cli.Search(ctx, client.NewSearchOption(​\n \"filtered_search_collection\", // collectionName​\n 3, // limit​\n []entity.Vector{entity.FloatVector(queryVector)},​\n ).WithFilter(`color like \"red%\" and likes > 50`).WithOutputFields(\"color\", \"likes\"))​\n if err != nil {​\n log.Fatal(\"failed to perform basic ANN search collection: \", err.Error())​\n }​\n​\n for _, resultSet := range resultSets {​\n log.Println(\"IDs: \", resultSet.IDs)​\n log.Println(\"Scores: \", resultSet.Scores)​\n }​\n // Output:​\n // IDs:​\n // Scores:​\n}​\n​\n\n","import { MilvusClient, DataType } from \"@zilliz/milvus2-sdk-node\";​\n​\nconst address = \"http://localhost:19530\";​\nconst token = \"root:Milvus\";​\nconst client = new MilvusClient({address, token});​\n​\nconst query_vector = [0.3580376395471989, -0.6023495712049978, 0.18414012509913835, -0.26286205330961354, 0.9029438446296592]​\n​\nconst res = await client.search({​\n collection_name: \"filtered_search_collection\",​\n data: [query_vector],​\n limit: 5,​\n // highlight-start​\n filters: 'color like \"red%\" and likes > 50',​\n output_fields: [\"color\", \"likes\"]​\n // highlight-end​\n})​\n\n","export CLUSTER_ENDPOINT=\"http://localhost:19530\"​\nexport TOKEN=\"root:Milvus\"​\n​\ncurl --request POST \\​\n--url \"${CLUSTER_ENDPOINT}/v2/vectordb/entities/search\" \\​\n--header \"Authorization: Bearer ${TOKEN}\" \\​\n--header \"Content-Type: application/json\" \\​\n-d '{​\n \"collectionName\": \"quick_setup\",​\n \"data\": [​\n [0.3580376395471989, -0.6023495712049978, 0.18414012509913835, -0.26286205330961354, 0.9029438446296592]​\n ],​\n \"annsField\": \"vector\",​\n \"filter\": \"color like \\\"red%\\\" and likes > 50\",​\n \"limit\": 3,​\n \"outputFields\": [\"color\", \"likes\"]​\n}'​\n# {\"code\":0,\"cost\":0,\"data\":[]}​\n\n","[​\n {​\n \"id\": 4, ​\n \"distance\": 0.3345786594834839,​\n \"entity\": {​\n \"vector\": [0.4452349528804562, -0.8757026943054742, 0.8220779437047674, 0.46406290649483184, 0.30337481143159106], ​\n \"color\": \"red_4794\", ​\n \"likes\": 122​\n }​\n },​\n {​\n \"id\": 6, ​\n \"distance\": 0.6638239834383389,​\n \"entity\": {​\n \"vector\": [0.8371977790571115, -0.015764369584852833, -0.31062937026679327, -0.562666951622192, -0.8984947637863987], ​\n \"color\": \"red_9392\", ​\n \"likes\": 58​\n }​\n },​\n]​\n\n"],"headingContent":"Filtered Search​","anchorList":[{"label":"Filtered Search​","href":"Filtered-Search​","type":1,"isActive":false},{"label":"Overview","href":"Overview","type":2,"isActive":false},{"label":"Examples","href":"Examples","type":2,"isActive":false}]} \ No newline at end of file +{"codeList":["[​\n {\"id\": 0, \"vector\": [0.3580376395471989, -0.6023495712049978, 0.18414012509913835, -0.26286205330961354, 0.9029438446296592], \"color\": \"pink_8682\", \"likes\": 165},​\n {\"id\": 1, \"vector\": [0.19886812562848388, 0.06023560599112088, 0.6976963061752597, 0.2614474506242501, 0.838729485096104], \"color\": \"red_7025\", \"likes\": 25},​\n {\"id\": 2, \"vector\": [0.43742130801983836, -0.5597502546264526, 0.6457887650909682, 0.7894058910881185, 0.20785793220625592], \"color\": \"orange_6781\", \"likes\": 764},​\n {\"id\": 3, \"vector\": [0.3172005263489739, 0.9719044792798428, -0.36981146090600725, -0.4860894583077995, 0.95791889146345], \"color\": \"pink_9298\", \"likes\": 234},​\n {\"id\": 4, \"vector\": [0.4452349528804562, -0.8757026943054742, 0.8220779437047674, 0.46406290649483184, 0.30337481143159106], \"color\": \"red_4794\", \"likes\": 122},​\n {\"id\": 5, \"vector\": [0.985825131989184, -0.8144651566660419, 0.6299267002202009, 0.1206906911183383, -0.1446277761879955], \"color\": \"yellow_4222\", \"likes\": 12},​\n {\"id\": 6, \"vector\": [0.8371977790571115, -0.015764369584852833, -0.31062937026679327, -0.562666951622192, -0.8984947637863987], \"color\": \"red_9392\", \"likes\": 58},​\n {\"id\": 7, \"vector\": [-0.33445148015177995, -0.2567135004164067, 0.8987539745369246, 0.9402995886420709, 0.5378064918413052], \"color\": \"grey_8510\", \"likes\": 775},​\n {\"id\": 8, \"vector\": [0.39524717779832685, 0.4000257286739164, -0.5890507376891594, -0.8650502298996872, -0.6140360785406336], \"color\": \"white_9381\", \"likes\": 876},​\n {\"id\": 9, \"vector\": [0.5718280481994695, 0.24070317428066512, -0.3737913482606834, -0.06726932177492717, -0.6980531615588608], \"color\": \"purple_4976\", \"likes\": 765}​\n]​\n\n","from pymilvus import MilvusClient​\n​\nclient = MilvusClient(​\n uri=\"http://localhost:19530\",​\n token=\"root:Milvus\"​\n)​\n​\nquery_vector = [0.3580376395471989, -0.6023495712049978, 0.18414012509913835, -0.26286205330961354, 0.9029438446296592]​\n​\nres = client.search(​\n collection_name=\"my_collection\",​\n data=[query_vector],​\n limit=5,​\n # highlight-start​\n filter='color like \"red%\" and likes > 50',​\n output_fields=[\"color\", \"likes\"]​\n # highlight-end​\n)​\n​\nfor hits in res:​\n print(\"TopK results:\")​\n for hit in hits:​\n print(hit)​\n\n","import io.milvus.v2.client.ConnectConfig;​\nimport io.milvus.v2.client.MilvusClientV2;​\nimport io.milvus.v2.service.vector.request.SearchReq​\nimport io.milvus.v2.service.vector.request.data.FloatVec;​\nimport io.milvus.v2.service.vector.response.SearchResp​\n​\nMilvusClientV2 client = new MilvusClientV2(ConnectConfig.builder()​\n .uri(\"http://localhost:19530\")​\n .token(\"root:Milvus\")​\n .build());​\n​\nFloatVec queryVector = new FloatVec(new float[]{0.3580376395471989f, -0.6023495712049978f, 0.18414012509913835f, -0.26286205330961354f, 0.9029438446296592f});​\nSearchReq searchReq = SearchReq.builder()​\n .collectionName(\"filtered_search_collection\")​\n .data(Collections.singletonList(queryVector))​\n .topK(5)​\n .filter(\"color like \\\"red%\\\" and likes > 50\")​\n .outputFields(Arrays.asList(\"color\", \"likes\"))​\n .build();​\n​\nSearchResp searchResp = client.search(searchReq);​\n​\nList> searchResults = searchResp.getSearchResults();​\nfor (List results : searchResults) {​\n System.out.println(\"TopK results:\");​\n for (SearchResp.SearchResult result : results) {​\n System.out.println(result);​\n }​\n}​\n​\n// Output​\n// TopK results:​\n// SearchResp.SearchResult(entity={color=red_4794, likes=122}, score=0.5975797, id=4)​\n// SearchResp.SearchResult(entity={color=red_9392, likes=58}, score=-0.24996188, id=6)​\n\n","import (​\n \"context\"​\n \"log\"​\n​\n \"github.com/milvus-io/milvus/client/v2\"​\n \"github.com/milvus-io/milvus/client/v2/entity\"​\n)​\n​\nfunc ExampleClient_Search_filter() {​\n ctx, cancel := context.WithCancel(context.Background())​\n defer cancel()​\n​\n milvusAddr := \"127.0.0.1:19530\"​\n token := \"root:Milvus\"​\n​\n cli, err := client.New(ctx, &client.ClientConfig{​\n Address: milvusAddr,​\n APIKey: token,​\n })​\n if err != nil {​\n log.Fatal(\"failed to connect to milvus server: \", err.Error())​\n }​\n​\n defer cli.Close(ctx)​\n​\n queryVector := []float32{0.3580376395471989, -0.6023495712049978, 0.18414012509913835, -0.26286205330961354, 0.9029438446296592}​\n​\n resultSets, err := cli.Search(ctx, client.NewSearchOption(​\n \"filtered_search_collection\", // collectionName​\n 3, // limit​\n []entity.Vector{entity.FloatVector(queryVector)},​\n ).WithFilter(`color like \"red%\" and likes > 50`).WithOutputFields(\"color\", \"likes\"))​\n if err != nil {​\n log.Fatal(\"failed to perform basic ANN search collection: \", err.Error())​\n }​\n​\n for _, resultSet := range resultSets {​\n log.Println(\"IDs: \", resultSet.IDs)​\n log.Println(\"Scores: \", resultSet.Scores)​\n }​\n // Output:​\n // IDs:​\n // Scores:​\n}​\n​\n\n","import { MilvusClient, DataType } from \"@zilliz/milvus2-sdk-node\";​\n​\nconst address = \"http://localhost:19530\";​\nconst token = \"root:Milvus\";​\nconst client = new MilvusClient({address, token});​\n​\nconst query_vector = [0.3580376395471989, -0.6023495712049978, 0.18414012509913835, -0.26286205330961354, 0.9029438446296592]​\n​\nconst res = await client.search({​\n collection_name: \"filtered_search_collection\",​\n data: [query_vector],​\n limit: 5,​\n // highlight-start​\n filters: 'color like \"red%\" and likes > 50',​\n output_fields: [\"color\", \"likes\"]​\n // highlight-end​\n})​\n\n","export CLUSTER_ENDPOINT=\"http://localhost:19530\"​\nexport TOKEN=\"root:Milvus\"​\n​\ncurl --request POST \\​\n--url \"${CLUSTER_ENDPOINT}/v2/vectordb/entities/search\" \\​\n--header \"Authorization: Bearer ${TOKEN}\" \\​\n--header \"Content-Type: application/json\" \\​\n-d '{​\n \"collectionName\": \"quick_setup\",​\n \"data\": [​\n [0.3580376395471989, -0.6023495712049978, 0.18414012509913835, -0.26286205330961354, 0.9029438446296592]​\n ],​\n \"annsField\": \"vector\",​\n \"filter\": \"color like \\\"red%\\\" and likes > 50\",​\n \"limit\": 3,​\n \"outputFields\": [\"color\", \"likes\"]​\n}'​\n# {\"code\":0,\"cost\":0,\"data\":[]}​\n\n","[​\n {​\n \"id\": 4, ​\n \"distance\": 0.3345786594834839,​\n \"entity\": {​\n \"vector\": [0.4452349528804562, -0.8757026943054742, 0.8220779437047674, 0.46406290649483184, 0.30337481143159106], ​\n \"color\": \"red_4794\", ​\n \"likes\": 122​\n }​\n },​\n {​\n \"id\": 6, ​\n \"distance\": 0.6638239834383389,​\n \"entity\": {​\n \"vector\": [0.8371977790571115, -0.015764369584852833, -0.31062937026679327, -0.562666951622192, -0.8984947637863987], ​\n \"color\": \"red_9392\", ​\n \"likes\": 58​\n }​\n },​\n]​\n\n","from pymilvus import MilvusClient​\n​\nclient = MilvusClient(​\n uri=\"http://localhost:19530\",​\n token=\"root:Milvus\"​\n)​\n​\nquery_vector = [0.3580376395471989, -0.6023495712049978, 0.18414012509913835, -0.26286205330961354, 0.9029438446296592]​\n​\nres = client.search(​\n collection_name=\"my_collection\",​\n data=[query_vector],​\n limit=5,​\n # highlight-start​\n filter='color like \"red%\" and likes > 50',​\n output_fields=[\"color\", \"likes\"]​,\n search_params={\n \"hints\": \"iterative_filter\"\n } \n # highlight-end​\n)​\n​\nfor hits in res:​\n print(\"TopK results:\")​\n for hit in hits:​\n print(hit)​\n\n","import io.milvus.v2.client.ConnectConfig;​\nimport io.milvus.v2.client.MilvusClientV2;​\nimport io.milvus.v2.service.vector.request.SearchReq​;\nimport io.milvus.v2.service.vector.request.data.FloatVec;​\nimport io.milvus.v2.service.vector.response.SearchResp​;\n​\nMilvusClientV2 client = new MilvusClientV2(ConnectConfig.builder()​\n .uri(\"http://localhost:19530\")​\n .token(\"root:Milvus\")​\n .build());​\n​\nFloatVec queryVector = new FloatVec(new float[]{0.3580376395471989f, -0.6023495712049978f, 0.18414012509913835f, -0.26286205330961354f, 0.9029438446296592f});​\nSearchReq searchReq = SearchReq.builder()​\n .collectionName(\"filtered_search_collection\")​\n .data(Collections.singletonList(queryVector))​\n .topK(5)​\n .filter(\"color like \\\"red%\\\" and likes > 50\")​\n .outputFields(Arrays.asList(\"color\", \"likes\"))​\n .searchParams(new HashMap<>(\"hints\", \"iterative_filter\"))\n .build();​\n​\nSearchResp searchResp = client.search(searchReq);​\n​\nList> searchResults = searchResp.getSearchResults();​\nfor (List results : searchResults) {​\n System.out.println(\"TopK results:\");​\n for (SearchResp.SearchResult result : results) {​\n System.out.println(result);​\n }​\n}​\n​\n// Output​\n// TopK results:​\n// SearchResp.SearchResult(entity={color=red_4794, likes=122}, score=0.5975797, id=4)​\n// SearchResp.SearchResult(entity={color=red_9392, likes=58}, score=-0.24996188, id=6)​\n\n","import (​\n \"context\"​\n \"log\"​\n​\n \"github.com/milvus-io/milvus/client/v2\"​\n \"github.com/milvus-io/milvus/client/v2/entity\"​\n)​\n​\nfunc ExampleClient_Search_filter() {​\n ctx, cancel := context.WithCancel(context.Background())​\n defer cancel()​\n​\n milvusAddr := \"127.0.0.1:19530\"​\n token := \"root:Milvus\"​\n​\n cli, err := client.New(ctx, &client.ClientConfig{​\n Address: milvusAddr,​\n APIKey: token,​\n })​\n if err != nil {​\n log.Fatal(\"failed to connect to milvus server: \", err.Error())​\n }​\n​\n defer cli.Close(ctx)​\n​\n queryVector := []float32{0.3580376395471989, -0.6023495712049978, 0.18414012509913835, -0.26286205330961354, 0.9029438446296592}​\n​\n resultSets, err := cli.Search(ctx, client.NewSearchOption(​\n \"filtered_search_collection\", // collectionName​\n 3, // limit​\n []entity.Vector{entity.FloatVector(queryVector)},​\n ).WithFilter(`color like \"red%\" and likes > 50`).WithHints(\"iterative_filter\").WithOutputFields(\"color\", \"likes\"))​\n if err != nil {​\n log.Fatal(\"failed to perform basic ANN search collection: \", err.Error())​\n }​\n​\n for _, resultSet := range resultSets {​\n log.Println(\"IDs: \", resultSet.IDs)​\n log.Println(\"Scores: \", resultSet.Scores)​\n }​\n // Output:​\n // IDs:​\n // Scores:​\n}​\n​\n\n","import { MilvusClient, DataType } from \"@zilliz/milvus2-sdk-node\";​\n​\nconst address = \"http://localhost:19530\";​\nconst token = \"root:Milvus\";​\nconst client = new MilvusClient({address, token});​\n​\nconst query_vector = [0.3580376395471989, -0.6023495712049978, 0.18414012509913835, -0.26286205330961354, 0.9029438446296592]​\n​\nconst res = await client.search({​\n collection_name: \"filtered_search_collection\",​\n data: [query_vector],​\n limit: 5,​\n // highlight-start​\n filters: 'color like \"red%\" and likes > 50',​\n hints: \"iterative_filter\",\n output_fields: [\"color\", \"likes\"]​\n // highlight-end​\n})​\n\n","export CLUSTER_ENDPOINT=\"http://localhost:19530\"​\nexport TOKEN=\"root:Milvus\"​\n​\ncurl --request POST \\​\n--url \"${CLUSTER_ENDPOINT}/v2/vectordb/entities/search\" \\​\n--header \"Authorization: Bearer ${TOKEN}\" \\​\n--header \"Content-Type: application/json\" \\​\n-d '{​\n \"collectionName\": \"quick_setup\",​\n \"data\": [​\n [0.3580376395471989, -0.6023495712049978, 0.18414012509913835, -0.26286205330961354, 0.9029438446296592]​\n ],​\n \"annsField\": \"vector\",​\n \"filter\": \"color like \\\"red%\\\" and likes > 50\",​\n \"searchParams\": {\"hints\": \"iterative_filter\"},\n \"limit\": 3,​\n \"outputFields\": [\"color\", \"likes\"]​\n}'​\n# {\"code\":0,\"cost\":0,\"data\":[]}​\n\n"],"headingContent":"Filtered Search​","anchorList":[{"label":"Filtered Search​","href":"Filtered-Search​","type":1,"isActive":false},{"label":"Overview","href":"Overview","type":2,"isActive":false},{"label":"Standard Filtering","href":"Standard-Filtering","type":2,"isActive":false},{"label":"Iterative Filtering","href":"Iterative-Filtering","type":2,"isActive":false},{"label":"Examples","href":"Examples","type":2,"isActive":false}]} \ No newline at end of file diff --git a/localization/v2.5.x/site/en/userGuide/search-query-get/filtered-search.md b/localization/v2.5.x/site/en/userGuide/search-query-get/filtered-search.md index 12c169318..5c9f89301 100644 --- a/localization/v2.5.x/site/en/userGuide/search-query-get/filtered-search.md +++ b/localization/v2.5.x/site/en/userGuide/search-query-get/filtered-search.md @@ -41,6 +41,22 @@ summary: >- d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z" > +

In Milvus, filtered searches are categorized into two types — standard filtering and iterative filtering — depending on the stage at which the filtering is applied.

+

Standard Filtering

If a collection contains both vector embeddings and their metadata, you can filter metadata before ANN search to improve the relevancy of the search result. Once Milvus receives a search request carrying a filtering condition, it restricts the search scope within the entities matching the specified filtering condition.​

@@ -54,6 +70,31 @@ summary: >-

  • Conduct the ANN search within the filtered entities.​

  • Returns top-K entities.​

  • +

    Iterative Filtering

    The standard filtering process effectively narrows the search scope to a small range. However, overly complex filtering expressions may result in very high search latency. In such cases, iterative filtering can serve as an alternative, helping to reduce the workload of scalar filtering.

    +

    + + Iterative filtering + Iterative filtering + +

    +

    As illustrated in the diagram above, a search with iterative filtering performs the vector search in iterations. Each entity returned by the iterator undergoes scalar filtering, and this process continues until the specified topK results are achieved.

    +

    This method significantly reduces the number of entities subjected to scalar filtering, making it especially beneficial for handling highly complex filtering expressions.

    +

    However, it’s important to note that the iterator processes entities one at a time. This sequential approach can lead to longer processing times or potential performance issues, especially when a large number of entities are subjected to scalar filtering.

    Examples

    For more information on the operators that you can use in metadata filtering, refer to ​Metadata Filtering.​

    +

    Search with iteraive filtering

    To conduct a filtered search with iterative filtering, you can do as follows:

    + +
    from pymilvus import MilvusClient​
    +​
    +client = MilvusClient(​
    +    uri="http://localhost:19530",​
    +    token="root:Milvus"​
    +)​
    +​
    +query_vector = [0.3580376395471989, -0.6023495712049978, 0.18414012509913835, -0.26286205330961354, 0.9029438446296592]​
    +​
    +res = client.search(​
    +    collection_name="my_collection",​
    +    data=[query_vector],​
    +    limit=5,​
    +    # highlight-start​
    +    filter='color like "red%" and likes > 50',​
    +    output_fields=["color", "likes"]​,
    +    search_params={
    +        "hints": "iterative_filter"
    +    }    
    +    # highlight-end​
    +)​
    +​
    +for hits in res:​
    +    print("TopK results:")​
    +    for hit in hits:​
    +        print(hit)​
    +
    +
    +
    import io.milvus.v2.client.ConnectConfig;​
    +import io.milvus.v2.client.MilvusClientV2;​
    +import io.milvus.v2.service.vector.request.SearchReq​;
    +import io.milvus.v2.service.vector.request.data.FloatVec;​
    +import io.milvus.v2.service.vector.response.SearchResp​;
    +​
    +MilvusClientV2 client = new MilvusClientV2(ConnectConfig.builder()​
    +        .uri("http://localhost:19530")​
    +        .token("root:Milvus")​
    +        .build());​
    +​
    +FloatVec queryVector = new FloatVec(new float[]{0.3580376395471989f, -0.6023495712049978f, 0.18414012509913835f, -0.26286205330961354f, 0.9029438446296592f});​
    +SearchReq searchReq = SearchReq.builder()​
    +        .collectionName("filtered_search_collection")​
    +        .data(Collections.singletonList(queryVector))​
    +        .topK(5)​
    +        .filter("color like \"red%\" and likes > 50")​
    +        .outputFields(Arrays.asList("color", "likes"))​
    +        .searchParams(new HashMap<>("hints", "iterative_filter"))
    +        .build();​
    +​
    +SearchResp searchResp = client.search(searchReq);​
    +​
    +List<List<SearchResp.SearchResult>> searchResults = searchResp.getSearchResults();​
    +for (List<SearchResp.SearchResult> results : searchResults) {​
    +    System.out.println("TopK results:");​
    +    for (SearchResp.SearchResult result : results) {​
    +        System.out.println(result);​
    +    }​
    +}​
    +​
    +// Output​
    +// TopK results:​
    +// SearchResp.SearchResult(entity={color=red_4794, likes=122}, score=0.5975797, id=4)​
    +// SearchResp.SearchResult(entity={color=red_9392, likes=58}, score=-0.24996188, id=6)​
    +
    +
    +
    import (​
    +    "context"​
    +    "log"​
    +​
    +    "github.com/milvus-io/milvus/client/v2"​
    +    "github.com/milvus-io/milvus/client/v2/entity"​
    +)​
    +​
    +func ExampleClient_Search_filter() {​
    +        ctx, cancel := context.WithCancel(context.Background())​
    +        defer cancel()​
    +​
    +        milvusAddr := "127.0.0.1:19530"​
    +        token := "root:Milvus"​
    +​
    +        cli, err := client.New(ctx, &client.ClientConfig{​
    +                Address: milvusAddr,​
    +                APIKey:  token,​
    +        })​
    +        if err != nil {​
    +                log.Fatal("failed to connect to milvus server: ", err.Error())​
    +        }​
    +​
    +        defer cli.Close(ctx)​
    +​
    +        queryVector := []float32{0.3580376395471989, -0.6023495712049978, 0.18414012509913835, -0.26286205330961354, 0.9029438446296592}​
    +​
    +        resultSets, err := cli.Search(ctx, client.NewSearchOption(​
    +                "filtered_search_collection", // collectionName​
    +                3,             // limit​
    +                []entity.Vector{entity.FloatVector(queryVector)},​
    +        ).WithFilter(`color like "red%" and likes > 50`).WithHints("iterative_filter").WithOutputFields("color", "likes"))​
    +        if err != nil {​
    +                log.Fatal("failed to perform basic ANN search collection: ", err.Error())​
    +        }​
    +​
    +        for _, resultSet := range resultSets {​
    +                log.Println("IDs: ", resultSet.IDs)​
    +                log.Println("Scores: ", resultSet.Scores)​
    +        }​
    +        // Output:​
    +        // IDs:​
    +        // Scores:​
    +}​
    +​
    +
    +
    +
    import { MilvusClient, DataType } from "@zilliz/milvus2-sdk-node";​
    +​
    +const address = "http://localhost:19530";​
    +const token = "root:Milvus";​
    +const client = new MilvusClient({address, token});​
    +​
    +const query_vector = [0.3580376395471989, -0.6023495712049978, 0.18414012509913835, -0.26286205330961354, 0.9029438446296592]​
    +​
    +const res = await client.search({​
    +    collection_name: "filtered_search_collection",​
    +    data: [query_vector],​
    +    limit: 5,​
    +    // highlight-start​
    +    filters: 'color like "red%" and likes > 50',​
    +    hints: "iterative_filter",
    +    output_fields: ["color", "likes"]​
    +    // highlight-end​
    +})​
    +
    +
    +
    export CLUSTER_ENDPOINT="http://localhost:19530"​
    +export TOKEN="root:Milvus"​
    +​
    +curl --request POST \​
    +--url "${CLUSTER_ENDPOINT}/v2/vectordb/entities/search" \​
    +--header "Authorization: Bearer ${TOKEN}" \​
    +--header "Content-Type: application/json" \​
    +-d '{​
    +    "collectionName": "quick_setup",​
    +    "data": [​
    +        [0.3580376395471989, -0.6023495712049978, 0.18414012509913835, -0.26286205330961354, 0.9029438446296592]​
    +    ],​
    +    "annsField": "vector",​
    +    "filter": "color like \"red%\" and likes > 50",​
    +    "searchParams": {"hints": "iterative_filter"},
    +    "limit": 3,​
    +    "outputFields": ["color", "likes"]​
    +}'​
    +# {"code":0,"cost":0,"data":[]}​
    +
    +
    diff --git a/localization/v2.5.x/site/en/userGuide/search-query-get/use-partition-key.json b/localization/v2.5.x/site/en/userGuide/search-query-get/use-partition-key.json index 633d03b0c..e2b0d4a45 100644 --- a/localization/v2.5.x/site/en/userGuide/search-query-get/use-partition-key.json +++ b/localization/v2.5.x/site/en/userGuide/search-query-get/use-partition-key.json @@ -1 +1 @@ -{"codeList":["from pymilvus import (​\n MilvusClient, DataType​\n)​\n​\nclient = MilvusClient(​\n uri=\"http://localhost:19530\",​\n token=\"root:Milvus\"​\n)​\n​\nschema = client.create_schema()​\n​\n# Add the partition key​\nschema.add_field(​\n field_name=\"my_varchar\", ​\n datatype=DataType.VARCHAR, ​\n max_length=512,​\n # highlight-next-line​\n is_partition_key=True,​\n)​\n\n","import io.milvus.v2.client.ConnectConfig;​\nimport io.milvus.v2.client.MilvusClientV2;​\nimport io.milvus.v2.common.DataType;​\nimport io.milvus.v2.service.collection.request.AddFieldReq;​\nimport io.milvus.v2.service.collection.request.CreateCollectionReq;​\n​\nMilvusClientV2 client = new MilvusClientV2(ConnectConfig.builder()​\n .uri(\"http://localhost:19530\")​\n .token(\"root:Milvus\")​\n .build());​\n​\n// Create schema​\nCreateCollectionReq.CollectionSchema schema = client.createSchema();​\n​\n// Add the partition key​\nschema.addField(AddFieldReq.builder()​\n .fieldName(\"my_varchar\")​\n .dataType(DataType.VarChar)​\n .maxLength(512)​\n // highlight-next-line​\n .isPartitionKey(true)​\n .build());​\n\n","import { MilvusClient, DataType } from \"@zilliz/milvus2-sdk-node\";​\n​\nconst address = \"http://localhost:19530\";​\nconst token = \"root:Milvus\";​\nconst client = new MilvusClient({address, token});​\n​\n// 3. Create a collection in customized setup mode​\n// 3.1 Define fields​\nconst fields = [​\n {​\n name: \"my_varchar\",​\n data_type: DataType.VarChar,​\n max_length: 512,​\n // highlight-next-line​\n is_partition_key: true​\n }​\n]​\n\n","export schema='{​\n \"autoId\": true,​\n \"enabledDynamicField\": false,​\n \"fields\": [​\n {​\n \"fieldName\": \"my_id\",​\n \"dataType\": \"Int64\",​\n \"isPrimary\": true​\n },​\n {​\n \"fieldName\": \"my_vector\",​\n \"dataType\": \"FloatVector\",​\n \"elementTypeParams\": {​\n \"dim\": \"5\"​\n }​\n },​\n {​\n \"fieldName\": \"my_varchar\",​\n \"dataType\": \"VarChar\",​\n \"isPartitionKey\": true,​\n \"elementTypeParams\": {​\n \"max_length\": 512​\n }​\n }​\n ]​\n }'​\n\n","client.create_collection(​\n collection_name=\"my_collection\",​\n schema=schema,​\n # highlight-next-line​\n num_partitions=1024​\n)​\n\n","import io.milvus.v2.service.collection.request.CreateCollectionReq;​\n​\nCreateCollectionReq createCollectionReq = CreateCollectionReq.builder()​\n .collectionName(\"my_collection\")​\n .collectionSchema(schema)​\n .numPartitions(1024)​\n .build();​\n client.createCollection(createCollectionReq);​\n\n","await client.create_collection({​\n collection_name: \"my_collection\",​\n schema: schema,​\n num_partitions: 1024​\n})​\n\n","export params='{​\n \"partitionsNum\": 1024​\n}'​\n​\nexport CLUSTER_ENDPOINT=\"http://localhost:19530\"​\nexport TOKEN=\"root:Milvus\"​\n​\ncurl --request POST \\​\n--url \"${CLUSTER_ENDPOINT}/v2/vectordb/collections/create\" \\​\n--header \"Authorization: Bearer ${TOKEN}\" \\​\n--header \"Content-Type: application/json\" \\​\n-d \"{​\n \\\"collectionName\\\": \\\"myCollection\\\",​\n \\\"schema\\\": $schema,​\n \\\"params\\\": $params​\n}\"​\n\n","# Filter based on a single partition key value, or​\nfilter='partition_key == \"x\" && '​\n​\n# Filter based on multiple partition key values​\nfilter='partition_key in [\"x\", \"y\", \"z\"] && '​\n\n","// Filter based on a single partition key value, or​\nString filter = \"partition_key == 'x' && \";​\n​\n// Filter based on multiple partition key values​\nString filter = \"partition_key in ['x', 'y', 'z'] && \";​\n\n","// Filter based on a single partition key value, or​\nconst filter = 'partition_key == \"x\" && '​\n​\n// Filter based on multiple partition key values​\nconst filter = 'partition_key in [\"x\", \"y\", \"z\"] && '​\n\n","# Filter based on a single partition key value, or​\nexport filter='partition_key == \"x\" && '​\n​\n# Filter based on multiple partition key values​\nexport filter='partition_key in [\"x\", \"y\", \"z\"] && '​\n\n"],"headingContent":"Use Partition Key​","anchorList":[{"label":"Use Partition Key​","href":"Use-Partition-Key​","type":1,"isActive":false},{"label":"Overview​","href":"Overview​","type":2,"isActive":false},{"label":"Use Partition Key​","href":"Use-Partition-Key​","type":2,"isActive":false}]} \ No newline at end of file +{"codeList":["from pymilvus import (​\n MilvusClient, DataType​\n)​\n​\nclient = MilvusClient(​\n uri=\"http://localhost:19530\",​\n token=\"root:Milvus\"​\n)​\n​\nschema = client.create_schema()​\n​\n# Add the partition key​\nschema.add_field(​\n field_name=\"my_varchar\", ​\n datatype=DataType.VARCHAR, ​\n max_length=512,​\n # highlight-next-line​\n is_partition_key=True,​\n)​\n\n","import io.milvus.v2.client.ConnectConfig;​\nimport io.milvus.v2.client.MilvusClientV2;​\nimport io.milvus.v2.common.DataType;​\nimport io.milvus.v2.service.collection.request.AddFieldReq;​\nimport io.milvus.v2.service.collection.request.CreateCollectionReq;​\n​\nMilvusClientV2 client = new MilvusClientV2(ConnectConfig.builder()​\n .uri(\"http://localhost:19530\")​\n .token(\"root:Milvus\")​\n .build());​\n​\n// Create schema​\nCreateCollectionReq.CollectionSchema schema = client.createSchema();​\n​\n// Add the partition key​\nschema.addField(AddFieldReq.builder()​\n .fieldName(\"my_varchar\")​\n .dataType(DataType.VarChar)​\n .maxLength(512)​\n // highlight-next-line​\n .isPartitionKey(true)​\n .build());​\n\n","import { MilvusClient, DataType } from \"@zilliz/milvus2-sdk-node\";​\n​\nconst address = \"http://localhost:19530\";​\nconst token = \"root:Milvus\";​\nconst client = new MilvusClient({address, token});​\n​\n// 3. Create a collection in customized setup mode​\n// 3.1 Define fields​\nconst fields = [​\n {​\n name: \"my_varchar\",​\n data_type: DataType.VarChar,​\n max_length: 512,​\n // highlight-next-line​\n is_partition_key: true​\n }​\n]​\n\n","export schema='{​\n \"autoId\": true,​\n \"enabledDynamicField\": false,​\n \"fields\": [​\n {​\n \"fieldName\": \"my_id\",​\n \"dataType\": \"Int64\",​\n \"isPrimary\": true​\n },​\n {​\n \"fieldName\": \"my_vector\",​\n \"dataType\": \"FloatVector\",​\n \"elementTypeParams\": {​\n \"dim\": \"5\"​\n }​\n },​\n {​\n \"fieldName\": \"my_varchar\",​\n \"dataType\": \"VarChar\",​\n \"isPartitionKey\": true,​\n \"elementTypeParams\": {​\n \"max_length\": 512​\n }​\n }​\n ]​\n }'​\n\n","client.create_collection(​\n collection_name=\"my_collection\",​\n schema=schema,​\n # highlight-next-line​\n num_partitions=1024​\n)​\n\n","import io.milvus.v2.service.collection.request.CreateCollectionReq;​\n​\nCreateCollectionReq createCollectionReq = CreateCollectionReq.builder()​\n .collectionName(\"my_collection\")​\n .collectionSchema(schema)​\n .numPartitions(1024)​\n .build();​\n client.createCollection(createCollectionReq);​\n\n","await client.create_collection({​\n collection_name: \"my_collection\",​\n schema: schema,​\n num_partitions: 1024​\n})​\n\n","export params='{​\n \"partitionsNum\": 1024​\n}'​\n​\nexport CLUSTER_ENDPOINT=\"http://localhost:19530\"​\nexport TOKEN=\"root:Milvus\"​\n​\ncurl --request POST \\​\n--url \"${CLUSTER_ENDPOINT}/v2/vectordb/collections/create\" \\​\n--header \"Authorization: Bearer ${TOKEN}\" \\​\n--header \"Content-Type: application/json\" \\​\n-d \"{​\n \\\"collectionName\\\": \\\"myCollection\\\",​\n \\\"schema\\\": $schema,​\n \\\"params\\\": $params​\n}\"​\n\n","# Filter based on a single partition key value, or​\nfilter='partition_key == \"x\" && '​\n​\n# Filter based on multiple partition key values​\nfilter='partition_key in [\"x\", \"y\", \"z\"] && '​\n\n","// Filter based on a single partition key value, or​\nString filter = \"partition_key == 'x' && \";​\n​\n// Filter based on multiple partition key values​\nString filter = \"partition_key in ['x', 'y', 'z'] && \";​\n\n","// Filter based on a single partition key value, or​\nconst filter = 'partition_key == \"x\" && '​\n​\n// Filter based on multiple partition key values​\nconst filter = 'partition_key in [\"x\", \"y\", \"z\"] && '​\n\n","# Filter based on a single partition key value, or​\nexport filter='partition_key == \"x\" && '​\n​\n# Filter based on multiple partition key values​\nexport filter='partition_key in [\"x\", \"y\", \"z\"] && '​\n\n","client.create_collection(\n collection_name=\"my_collection\",\n schema=schema,\n # highlight-next-line\n properties={\"partitionkey.isolation\": True}\n)\n\n","import io.milvus.v2.service.collection.request.CreateCollectionReq;\n\nMap properties = new HashMap<>();\nproperties.put(\"partitionkey.isolation\", \"true\");\n\nCreateCollectionReq createCollectionReq = CreateCollectionReq.builder()\n .collectionName(\"my_collection\")\n .collectionSchema(schema)\n .numPartitions(1024)\n .properties(properties)\n .build();\nclient.createCollection(createCollectionReq);\n\n","res = await client.alterCollection({\n collection_name: \"my_collection\",\n properties: {\n \"partitionkey.isolation\": true\n }\n})\n\n","export params='{\n \"partitionKeyIsolation\": true\n}'\n\nexport CLUSTER_ENDPOINT=\"http://localhost:19530\"\nexport TOKEN=\"root:Milvus\"\n\ncurl --request POST \\\n--url \"${CLUSTER_ENDPOINT}/v2/vectordb/collections/create\" \\\n--header \"Authorization: Bearer ${TOKEN}\" \\\n--header \"Content-Type: application/json\" \\\n-d \"{\n \\\"collectionName\\\": \\\"myCollection\\\",\n \\\"schema\\\": $schema,\n \\\"params\\\": $params\n}\"\n\n"],"headingContent":"Use Partition Key​","anchorList":[{"label":"Use Partition Key​","href":"Use-Partition-Key​","type":1,"isActive":false},{"label":"Overview​","href":"Overview​","type":2,"isActive":false},{"label":"Use Partition Key​","href":"Use-Partition-Key​","type":2,"isActive":false},{"label":"Use Partition Key Isolation","href":"Use-Partition-Key-Isolation","type":2,"isActive":false}]} \ No newline at end of file diff --git a/localization/v2.5.x/site/en/userGuide/search-query-get/use-partition-key.md b/localization/v2.5.x/site/en/userGuide/search-query-get/use-partition-key.md index 070f1cf72..8af56d881 100644 --- a/localization/v2.5.x/site/en/userGuide/search-query-get/use-partition-key.md +++ b/localization/v2.5.x/site/en/userGuide/search-query-get/use-partition-key.md @@ -262,3 +262,90 @@ export filter=' export filter='partition_key in ["x", "y", "z"] && <other conditions>' +
    +

    You have to replace partition_key with the name of the field that is designated as the partition key.

    +
    +

    Use Partition Key Isolation

    In the multi-tenancy scenario, you can designate the scalar field related to tenant identities as the partition key and create a filter based on a specific value in this scalar field. To further improve search performance in similar scenarios, Milvus introduces the Partition Key Isolation feature.

    +

    + + Partition Key Isolation + Partition Key Isolation + +

    +

    As shown in the above figure, Milvus groups entities based on the Partition Key value and creates a separate index for each of these groups. Upon receiving a search request, Milvus locates the index based on the Partition Key value specified in the filtering condition and restricts the search scope within the entities included in the index, thus avoiding scanning irrelevant entities during the search and greatly enhancing the search performance. +Once you have enabled Partition Key Isolation, you can include only a specific value in the Partition-key-based filter so that Milvus can restrict the search scope within the entities included in the index that match.

    +
    +

    Currently, the Partition-Key Isolation feature applies only to searches with the index type set to HNSW.

    +
    +

    Enable Partition Key Isolation

    The following code examples demonstrate how to enable Partition Key Isolation.

    +
    + Python + Java + Node.js + Go + cURL +
    +
    client.create_collection(
    +    collection_name="my_collection",
    +    schema=schema,
    +    # highlight-next-line
    +    properties={"partitionkey.isolation": True}
    +)
    +
    +
    +
    import io.milvus.v2.service.collection.request.CreateCollectionReq;
    +
    +Map<String, String> properties = new HashMap<>();
    +properties.put("partitionkey.isolation", "true");
    +
    +CreateCollectionReq createCollectionReq = CreateCollectionReq.builder()
    +        .collectionName("my_collection")
    +        .collectionSchema(schema)
    +        .numPartitions(1024)
    +        .properties(properties)
    +        .build();
    +client.createCollection(createCollectionReq);
    +
    +
    +
    res = await client.alterCollection({
    +    collection_name: "my_collection",
    +    properties: {
    +        "partitionkey.isolation": true
    +    }
    +})
    +
    +
    +
    export params='{
    +    "partitionKeyIsolation": true
    +}'
    +
    +export CLUSTER_ENDPOINT="http://localhost:19530"
    +export TOKEN="root:Milvus"
    +
    +curl --request POST \
    +--url "${CLUSTER_ENDPOINT}/v2/vectordb/collections/create" \
    +--header "Authorization: Bearer ${TOKEN}" \
    +--header "Content-Type: application/json" \
    +-d "{
    +    \"collectionName\": \"myCollection\",
    +    \"schema\": $schema,
    +    \"params\": $params
    +}"
    +
    +
    +

    Once you have enabled Partition Key Isolation, you can still set the Partition Key and number of partitions as described in Set Partition Numbers. Note that the Partition-Key-based filter should include only a specific Partition Key value.