You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 5 Next »

Current state: Under Discussion

ISSUE: #6299

PRs: #6570

Keywords: Query / Search / Vector

Released: Milvus 2.0rc3


Using minimal memory consumption, let `search` or `query` operation support to return vector raw data in output fields.


In Milvus 2.0rc1, operations like search or query do not support return vector raw data in output fields. This is from the consideration of memory consumption,

vector field with big dimension will occupy hundreds of times of memory comparing with scalar field. So in general load_collection or load_partition only load

scalar fields' raw data into memory. Vector fields' raw data is loaded into memory only in 3 cases:

  1. steaming segment
  2. vector field's index type is FLAT
  3. vector field's index has not been created

Design Details

在 search / query 结束后,再分析 output_fields 里是否包含向量列,若包含,则加载结果 IDs 所在 segment 向量列,通过结果 IDs 对应的 offset 得到对应向量数据。

1.  Add new field VectorFieldInfo into segment struct to record vector field related information

type VectorFieldInfo struct {
    mu              sync.RWMutex
    fieldBinlog     *datapb.FieldBinlog
    rowDataInMemory bool
    rawData         map[string]storage.FieldData  // map[binlogPath]FieldData

type Segment struct {
    ... ...
    vectorFieldInfos map[UniqueID]*VectorFieldInfo

2. 在 `segment` 中添加新接口

// fill vector raw data into RetrieveResults
func (s *Segment) fillRetrieveResults(plan *RetrievePlan, result *segcorepb.RetrieveResults) error

// 1. load vector field binlog file from minio
// 2. decode binlog file, get vector raw data
// 3. save raw data into local disk
// 4. do mmap
func (s *Segment) segmentVectorFieldDataMmap(fieldID int64, binlog string, rowCount int, data interface{}) ([]byte, error)

3. 在 `segmentLoader` 中添加新接口

func (loader *segmentLoader) loadSegmentVectorFieldsData(segment *Segment, binlogs []string) error

4. 在 retrieve 函数中添加如下逻辑

* 当输出列包含向量列、向量列未加载、且当前 segment 返回值不为空时

if err = q.historical.loader.loadSegmentVectorFieldsData(segment, binlogs); err != nil {
return err
if err = segment.fillRetrieveResults(plan, result); err != nil {
return err

5. load_segment 接口添加参数 `include_vector_field` or `vector_fields[]`

**`search` 接口不支持返回原始向量数据**
如果想得到 `search` 返回结果所对应的原始向量数据,可通过再次调用 `get_entity_by_id` 得到。

Original vector data storage public interface and struct

Public Interfaces

type FileManager interface {
GetFile(path string) (string, error)
PutFile(path string, content []byte) error
Exist(path string) bool
ReadFile(path string) []byte

A VectorFileManager implements FileManager interface.

type VectorFileManager struct {
localFileManager FileManager
remoteFileManager FileManager
insertCodec *InsertCodec

localFileManager is responsible to local file manager. And can be implements with golang os library.
remoteFileManager is responsible for cloud storage or remote server storage, and will be implemented with minio client now.

When the offset of vector is obtained, we can get origin vector data from local vector data file.

Test Plan

Do query / search (with vector field in output fields) in all kinds of combinations of following scenarios, check the correctness of result.

  1. float vector or binary vector
  2. with/wo index
  3. all kinds of index type

  • No labels