# def insertar_productos_en_milvus(data):
#     connections.connect(db_name="marcimex", host="198.251.78.201", port="19530")
#     collection_name = "PRODUCTOS_MARCIMEX"

#     if utility.has_collection(collection_name):
#         print("colección ya existe")
#         collection_to_drop = Collection(collection_name)
#         collection_to_drop.drop()
#         print("colección eliminada")
    
#     if not utility.has_collection(collection_name):
#         # Esquema
#         fields = [
#             FieldSchema(name="pk", dtype=DataType.INT64, is_primary=True, auto_id=True),
#             FieldSchema(name="code", dtype=DataType.VARCHAR, max_length=20),
#             FieldSchema(name="text", dtype=DataType.VARCHAR, max_length=10000),
#             FieldSchema(name="namespace", dtype=DataType.VARCHAR, max_length=10000),
#             FieldSchema(name="vector", dtype=DataType.FLOAT_VECTOR, dim=3072)
#         ]
#         schema = CollectionSchema(fields, description="productos")
#         collection = Collection(name=collection_name, schema=schema)
#         print("colección creada")
#     else:
#         collection = Collection(name=collection_name)
    
#     # Crear índice si no existe
#     if not collection.has_index():
#         index_params = {
#             "metric_type": "COSINE",
#             "index_type": "IVF_FLAT",
#             "params": {"nlist": 36}
#         }
#         collection.create_index(field_name="vector", index_params=index_params)
#         print("Índice creado.")
    
#     # Prepara los datos para insertar
#     codes = []
#     texts = []
#     documents = []
#     vectors = []
    
#     for producto in data:
#         codes.append(producto["_id"]) 
#         producto_sin_embeddings = producto.copy()
#         if "embeddings" in producto_sin_embeddings:
#             del producto_sin_embeddings["embeddings"]

#         texts.append(str(producto_sin_embeddings)) 
#         documents.append("productos")
#         vectors.append(producto["embeddings"]) 
    
#     insert_data = [codes, texts, documents, vectors]

#     # Inserta los datos en la colección
#     mr = collection.insert(insert_data)
#     # print('Datos insertados con IDs:', mr.primary_keys)
#     print("terminado")
    
#     collection.load()
#     connections.disconnect("marcimex")