milvus search api的数据结构

search api的数据结构

此api的功能是向量相似度搜索(vector similarity search)

一个完整的search例子:

服务端collection是一个hnsw类型的索引。

import random
from pymilvus import (
  connections,
  Collection,
)

dim = 128
    
if __name__ == '__main__':
    connections.connect(
        alias="default",
        user='',
        password='',
        host='192.168.230.71',
        port='19530'
    )

    hello_milvus = Collection("hello_milvus")
    # hnsw索引的搜索参数
    search_param = {
        "metric_type": "L2",
        "params": {"ef": 200}
    }
    search_data = [random.random() for _ in range(dim)]
    results = hello_milvus.search(
        data=[search_data],
        anns_field="embeddings",
        param=search_param,
        limit=5,
        expr=None,
        output_fields=['pk','book_id'],
        consistency_level="Eventually"
    )
    print(results)

输出:

[
    "id: 2196, distance: 12.860455513000488, entity: {'pk': 2196, 'book_id': 2196}",
    "id: 888, distance: 15.004779815673828, entity: {'pk': 888, 'book_id': 888}",
    "id: 2454, distance: 15.082155227661133, entity: {'pk': 2454, 'book_id': 2454}",
    "id: 884, distance: 15.443259239196777, entity: {'pk': 884, 'book_id': 884}",
    "id: 2058, distance: 15.52014446258545, entity: {'pk': 2058, 'book_id': 2058}"
]

SearchRequest数据结构

type SearchRequest struct {
	Base           *commonpb.MsgBase
	DbName         string
	CollectionName string
	PartitionNames []string
	Dsl            string
	// serialized `PlaceholderGroup`
	PlaceholderGroup      []byte
	DslType               commonpb.DslType
	OutputFields          []string
	SearchParams          []*commonpb.KeyValuePair
	TravelTimestamp       uint64
	GuaranteeTimestamp    uint64
	Nq                    int64
	NotReturnAllMeta      bool
	ConsistencyLevel      commonpb.ConsistencyLevel
	UseDefaultConsistency bool
	SearchByPrimaryKeys   bool
	XXX_NoUnkeyedLiteral  struct{}
	XXX_unrecognized      []byte
	XXX_sizecache         int32
}

Dsl ??

PlaceholderGroup ??

DslType ??

nq:number of query

ConsistencyLevel:一致性级别

const (
	ConsistencyLevel_Strong     ConsistencyLevel = 0
	ConsistencyLevel_Session    ConsistencyLevel = 1
	ConsistencyLevel_Bounded    ConsistencyLevel = 2
	ConsistencyLevel_Eventually ConsistencyLevel = 3
	ConsistencyLevel_Customized ConsistencyLevel = 4
)

使用Strong一致性级别搜索速度会很慢。
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

从数据结构可以看出,search的时候可以指定partition。

相关推荐

  1. 常见数据结构

    2024-04-08 07:22:04       53 阅读
  2. ArrayList数据结构

    2024-04-08 07:22:04       51 阅读
  3. 数据结构学习

    2024-04-08 07:22:04       43 阅读
  4. 数据结构分类

    2024-04-08 07:22:04       22 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-04-08 07:22:04       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-04-08 07:22:04       101 阅读
  3. 在Django里面运行非项目文件

    2024-04-08 07:22:04       82 阅读
  4. Python语言-面向对象

    2024-04-08 07:22:04       91 阅读

热门阅读

  1. logstash接收kafka日志

    2024-04-08 07:22:04       29 阅读
  2. Elasticsearch知识点

    2024-04-08 07:22:04       29 阅读
  3. mac在终端使用命令启动IDEA打开项目

    2024-04-08 07:22:04       42 阅读
  4. 【Linux】 Vim:掌握高效编辑的艺术

    2024-04-08 07:22:04       33 阅读
  5. 设计模式:迭代器模式

    2024-04-08 07:22:04       36 阅读
  6. 使用Python写简单的点云高斯滤波

    2024-04-08 07:22:04       32 阅读
  7. 24/04/08总结

    2024-04-08 07:22:04       42 阅读
  8. LeetCode 474. 一和零

    2024-04-08 07:22:04       40 阅读
  9. MySQL的列子查询

    2024-04-08 07:22:04       34 阅读
  10. Flink CDC

    Flink CDC

    2024-04-08 07:22:04      36 阅读
  11. 【LintCode】448 · 二叉查找树的中序后继

    2024-04-08 07:22:04       33 阅读
  12. 代码随想录 day24 回溯算法

    2024-04-08 07:22:04       32 阅读