mirror of https://github.com/milvus-io/milvus.git
Updated Similarity Metrics (markdown)
parent
3c33a8cb36
commit
1b6a9f6a5e
|
@ -198,5 +198,49 @@ Where
|
|||
- N<sub>AB</sub> specifies the number of shared bits in the fingerprint of molecular A and B.
|
||||
|
||||
|
||||
For example:
|
||||
|
||||
**In python**
|
||||
|
||||
```python
|
||||
from pymilvus import connections, FieldSchema, CollectionSchema, DataType, Collection
|
||||
# create a collection
|
||||
collection_name = "milvus_test"
|
||||
default_fields = [
|
||||
FieldSchema(name="id", dtype=DataType.INT64, is_primary=True, auto_id=True),
|
||||
FieldSchema(name="vector", dtype=DataType.FLOAT_VECTOR, dim=d)
|
||||
]default_schema = CollectionSchema(fields=default_fields, description="test collection")
|
||||
print(f"\nCreate collection...")
|
||||
collection = Collection(name= collection_name, schema=default_schema)
|
||||
|
||||
# insert data
|
||||
import random
|
||||
vectors = [[random.random() for _ in range(8)] for _ in range(10)]
|
||||
entities = [vectors]
|
||||
mr = collection.insert(entities)
|
||||
print(collection.num_entities)
|
||||
|
||||
# create index
|
||||
collection.create_index(field_name=field_name,
|
||||
index_params={'index_type': 'IVF_FLAT',
|
||||
'metric_type': 'JACCARD',
|
||||
'params': {
|
||||
"M": 16, # int. 4~64
|
||||
"efConstruction": 40 # int. 8~512
|
||||
}})
|
||||
collection.load()
|
||||
|
||||
# search
|
||||
top_k = 10
|
||||
search_params = {"metric_type": "JACCARD", "params": {"nprobe": 10}}
|
||||
results = collection.search(vectors[:5], anns_field="vector", param=search_params,limit=top_k)
|
||||
|
||||
# show results
|
||||
for result in results:
|
||||
print(result.ids)
|
||||
print(result.distance)
|
||||
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue