Code Monkey home page Code Monkey logo

Comments (11)

xiaofan-luan avatar xiaofan-luan commented on September 22, 2024 1

@cydrain
do a check on that?

from milvus.

yanliang567 avatar yanliang567 commented on September 22, 2024

/assign @xiaocai2333
/unassign

from milvus.

xiaocai2333 avatar xiaocai2333 commented on September 22, 2024

/assign @foxspy
please help on it.

from milvus.

foxspy avatar foxspy commented on September 22, 2024

image
binary index crashed during building stage

from milvus.

foxspy avatar foxspy commented on September 22, 2024

/assign @cydrain

from milvus.

cydrain avatar cydrain commented on September 22, 2024

Hi @ThreadDao,

HNSW with Binary data type has not been fully supported, and it's also not officially announced.
Please remove the "critical-urgent" tag.

from milvus.

cydrain avatar cydrain commented on September 22, 2024

This issue is because Milvus creates HNSW index for a binary vector filed with COSINE metric type.
COSINE metric type is only available for float vector, we need add more param legacy check.

from milvus.

cydrain avatar cydrain commented on September 22, 2024

can reproduce this issue using this script:

import random
import numpy as np

from pymilvus import (
    connections,
    FieldSchema, CollectionSchema, DataType,
    Collection,
    utility
)

_HOST = '127.0.0.1'
_PORT = '19530'

# Const names
_COLLECTION_NAME = 'demo'
_ID_FIELD_NAME = 'id_field'
_VECTOR_FIELD_NAME = 'bin_vector_field'

# Vector parameters
_DIM = 128
_INDEX_FILE_SIZE = 32  # max file size of stored index
_NQ = 10

# Index parameters
_METRIC_TYPE = 'COSINE'
_INDEX_TYPE = 'HNSW'
_NLIST = 128
_NPROBE = 16
_TOPK = 5
_EFC = 200
_EF = 64
_M = 8

# Create a Milvus connection
def create_connection():
    print(f"\nCreate connection...")
    connections.connect(host=_HOST, port=_PORT)
    print(f"\nList connections:")
    print(connections.list_connections())

# Create a collection named 'demo'
def create_collection(name, id_field, vector_field):
    field1 = FieldSchema(name=id_field, dtype=DataType.INT64, description="int64", is_primary=True)
    field2 = FieldSchema(name=vector_field, dtype=DataType.BINARY_VECTOR, description="binary vector", dim=_DIM,
                         is_primary=False)
    schema = CollectionSchema(fields=[field1, field2], description="collection description")
    collection = Collection(name=name, data=None, schema=schema, properties={"collection.ttl.seconds": 15})
    print("\ncollection created:", name)
    return collection

def has_collection(name):
    return utility.has_collection(name)

# Drop a collection in Milvus
def drop_collection(name):
    collection = Collection(name)
    collection.drop()
    print("\nDrop collection: {}".format(name))

# List all collections in Milvus
def list_collections():
    print("\nlist collections:")
    print(utility.list_collections())

def insert(collection, num, dim):
    raw_vectors = []
    binary_vectors = []
    for i in range(num):
        raw_vector = [random.randint(0, 1) for i in range(dim)]
        raw_vectors.append(raw_vector)
        binary_vectors.append(bytes(np.packbits(raw_vector, axis=-1).tolist()))
    data = [
        [i for i in range(num)],
        binary_vectors,
    ]
    collection.insert(data)
    return data[1]

def get_entity_num(collection):
    print("\nThe number of entity:")
    print(collection.num_entities)

def create_index(collection, filed_name):
    index_param = {
        "index_type": _INDEX_TYPE,
        "params": {"nlist": _NLIST, "M": _M, "efConstruction": _EFC},
        "metric_type": _METRIC_TYPE}
    collection.create_index(filed_name, index_param)
    print("\nCreated index:\n{}".format(collection.index().params))

def drop_index(collection):
    collection.drop_index()
    print("\nDrop index sucessfully")

def load_collection(collection):
    collection.load()

def release_collection(collection):
    collection.release()

def search(collection, vector_field, id_field, search_vectors):
    search_param = {
        "data": search_vectors,
        "anns_field": vector_field,
        "param": {"metric_type": _METRIC_TYPE, "params": {"nprobe": _NPROBE, "ef": _EF}},
        "limit": _TOPK,
        "expr": "id_field >= 0"}
    results = collection.search(**search_param)
    for i, result in enumerate(results):
        print("\nSearch result for {}th vector: ".format(i))
        for j, res in enumerate(result):
            print("Top {}: {}".format(j, res))

def set_properties(collection):
    collection.set_properties(properties={"collection.ttl.seconds": 1800})

def main():
    # create a connection
    create_connection()

    # drop collection if the collection exists
    if has_collection(_COLLECTION_NAME):
        drop_collection(_COLLECTION_NAME)

    # create collection
    collection = create_collection(_COLLECTION_NAME, _ID_FIELD_NAME, _VECTOR_FIELD_NAME)

    # alter ttl properties of collection level
    set_properties(collection)

    # show collections
    list_collections()

    # insert 10000 vectors with 128 dimension
    vectors = insert(collection, 10000, _DIM)

    collection.flush()
    # get the number of entities
    get_entity_num(collection)

    # create index
    create_index(collection, _VECTOR_FIELD_NAME)

    # load data to memory
    load_collection(collection)

    # search
    search(collection, _VECTOR_FIELD_NAME, _ID_FIELD_NAME, vectors[:_NQ])

    # release memory
    release_collection(collection)

    # drop collection index
    drop_index(collection)

    # drop collection
    drop_collection(_COLLECTION_NAME)

if __name__ == '__main__':
    main()

from milvus.

cydrain avatar cydrain commented on September 22, 2024

with #31825, Milvus will raise exception when create HNSW binary index.

  File "/home/caiyd/work/vec/pymilvus/pymilvus/client/utils.py", line 60, in check_status
    raise MilvusException(status.code, status.reason, status.error_code)
pymilvus.exceptions.MilvusException: <MilvusException: (code=1100, message=only support float vector: invalid parameter[expected=valid index params][actual=invalid index params])>

from milvus.

cydrain avatar cydrain commented on September 22, 2024

@ThreadDao
HNSW binary has been disabled, please have a check.

from milvus.

ThreadDao avatar ThreadDao commented on September 22, 2024

fixed

from milvus.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.