mirror of https://github.com/milvus-io/milvus.git
Updated Searching with IVF index (markdown)
parent
4530346486
commit
2b68d6647e
|
@ -63,6 +63,82 @@ for result in results:
|
|||
print(result.distance)
|
||||
|
||||
```
|
||||
In node
|
||||
|
||||
```javascript
|
||||
import { MilvusClient } from "@zilliz/milvus2-sdk-node";
|
||||
|
||||
# connect Milvus
|
||||
const milvusClient = new MilvusClient("localhost:19530");
|
||||
|
||||
# create a collection
|
||||
const collection_name = "milvus_test1"
|
||||
const params = {
|
||||
collection_name: collection_name,
|
||||
fields: [
|
||||
{
|
||||
name: "vector",
|
||||
description: "vector field",
|
||||
data_type: DataType.FloatVector,
|
||||
type_params: {
|
||||
dim: d,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "id",
|
||||
data_type: DataType.Int64,
|
||||
autoID: true,
|
||||
is_primary_key: true,
|
||||
description: "",
|
||||
},
|
||||
],
|
||||
};
|
||||
await milvusClient.collectionManager.createCollection(params);
|
||||
|
||||
# insert data
|
||||
await milvusClient.dataManager.insert({{
|
||||
collection_name: collection_name,
|
||||
fields_data: entities,
|
||||
});
|
||||
|
||||
# flush data to disk.
|
||||
await milvusClient.dataManager.flush({ collection_names: [collection_name] });
|
||||
|
||||
# create index
|
||||
await milvusClient.collectionManager.createIndex({
|
||||
collection_name: collection_name,
|
||||
field_name: "vector",
|
||||
extra_params: {
|
||||
index_type: "IVF_FLAT",
|
||||
metric_type: "L2",
|
||||
params: JSON.stringify({ nlist: 100 }),
|
||||
},
|
||||
});
|
||||
|
||||
# Load data to memory
|
||||
await milvusClient.collectionManager.loadCollection({
|
||||
collection_name: collection_name,
|
||||
});
|
||||
|
||||
# search
|
||||
const top_k = 5;
|
||||
const searchParams = {
|
||||
anns_field: "vector",
|
||||
topk: top_k,
|
||||
metric_type: "L2",
|
||||
params: JSON.stringify({ nprobe: 10 }),
|
||||
};
|
||||
|
||||
await milvusClient.dataManager.search({
|
||||
collection_name: collection_name,
|
||||
expr: "",
|
||||
vectors: [[1, 2, 3, 4, 5, 6, 7, 8]],
|
||||
search_params: searchParams,
|
||||
vector_type: 100, // Float vector -> 100
|
||||
});
|
||||
|
||||
```
|
||||
|
||||
|
||||
|
||||
# IVF_SQ8
|
||||
|
|
Loading…
Reference in New Issue