I realized that when I tried to search it returns nothing, how to solve this? #33556
Answered
by
yhmo
JenuelDev
asked this question in
Q&A and General discussion
-
So I have this function, that creates a milvus collection def __generate_collection(self):
if self.collection_name not in self.milvusClient.list_collections():
schema = MilvusClient.create_schema(auto_id=True, enable_dynamic_field=True, primary_field="id")
schema.add_field(field_name="id", datatype=DataType.INT64, is_primary=True)
schema.add_field(field_name="source", datatype=DataType.VARCHAR, max_length=50000)
schema.add_field(field_name="embeddings", datatype=DataType.FLOAT_VECTOR, dim=self.truncate_dim)
index_params = MilvusClient.prepare_index_params()
index_params.add_index(field_name="id", index_type="STL_SORT")
index_params.add_index(
field_name="embeddings",
index_type="IVF_FLAT",
metric_type="L2",
params={"nlist": 1024},
)
self.milvusClient.create_collection(
collection_name=self.collection_name, schema=schema, index_params=index_params
)
I also inerted data.. using this: entities = [
{"source": "blah blah vlah", "embeddings": [1,2,3,4, etc..]}
]
insert_result = self.milvusClient.insert(collection_name=self.collection_name, data=entities)
print(insert_result)
#outputs {'insert_count': 1, 'ids': [450065725884255501], 'cost': 0} As you can see it inserted something,, but when I try to search. It does not give me anything def search_and_query(
self,
search_vectors: list,
search_field: str = "embeddings",
search_params={"metric_type": "L2", "params": {"nprobe": 10}},
vector_search_limit=10,
):
result = self.milvusClient.search(
collection_name=self.collection_name,
data=search_vectors,
search_params=search_params,
anns_field=search_field,
limit=vector_search_limit,
output_fields=["source"],
)
print(result)
return result
# output: data: ['[]'] , extra_info: {'cost': 0} I need help, or did I did something wrong here? do I need to await something? |
Beta Was this translation helpful? Give feedback.
Answered by
yhmo
Jun 3, 2024
Replies: 1 comment
-
Data visibility is controlled by consistency_level: https://milvus.io/docs/consistency.md#Consistency Add consistency_level="Strong" to search() and you will see the result:
|
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
JenuelDev
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Data visibility is controlled by consistency_level: https://milvus.io/docs/consistency.md#Consistency
Add consistency_level="Strong" to search() and you will see the result: