|
|
1 månad sedan | |
|---|---|---|
| .. | ||
| 01_operate_db.py | 1 månad sedan | |
| 02_collection_operations.py | 1 månad sedan | |
| 03_entity_insert_update_delete.py | 1 månad sedan | |
| 04_entity_query.py | 1 månad sedan | |
| 05_hybrid_search_rerank.py | 1 månad sedan | |
| 06_load_and_drop_collection.py | 1 månad sedan | |
| README.md | 1 månad sedan | |
本目录对应课件 ② 项目工具/2.4 Milvus向量数据库,代码内容与课件保持一致(仅针对当前环境的 pymilvus 版本做了少量兼容性修正,见下方说明)。
01_operate_db.py: 设置向量数据库(operate_db)。02_collection_operations.py: Collection 与索引操作(operate_table)。03_entity_insert_update_delete.py: Entity 增、删、改(operate_entity)。04_entity_query.py: 单向量、批量、分区、过滤、范围搜索(query_operation)。05_hybrid_search_rerank.py: 多向量混合检索与 RRF/加权重排(demo_rankers + complex_query)。06_load_and_drop_collection.py: 加载已有数据与删除 Collection。示例默认使用 Milvus Lite,本地数据库文件为当前目录下的 milvus_demo.db(首次运行会自动创建)。
请使用 EnterpriseKB-RAG conda 环境,并按顺序依次运行 01 ~ 06(04 依赖 03 写入的数据,06 依赖 03/04 使用的 demo_v2 集合):
conda activate EnterpriseKB-RAG
python 01_operate_db.py
python 02_collection_operations.py
python 03_entity_insert_update_delete.py
python 04_entity_query.py
python 05_hybrid_search_rerank.py
python 06_load_and_drop_collection.py
每个脚本都会在开头清理自己创建的 collection(has_collection + drop_collection),所以可以重复运行整套流程。
当前环境安装的 pymilvus==3.0.0(对应 milvus-lite==3.2.1)比课件编写时用的版本更新,以下两处课件写法在新版本下会报错,已做调整:
index_type=''(留空表示自动索引)在新版本会报 missing required 'index_type' parameter,已改为向量字段用 'AUTOINDEX'、标量字段用 'INVERTED'。index_name 不生效:新版本里实际生效的索引名固定为字段名(课件里自定义的 vector_index/default_index 只是入参,服务端仍以字段名命名索引),因此 describe_index 前先用 list_indexes(field_name=...) 取真实的索引名,避免 "多个索引,请指定 index_name" 的报错。load_collection:Milvus Lite 每次新建 MilvusClient 连接同一个库文件时,之前写入的 collection 默认是 released 状态(只有同一进程内创建/插入数据后才会自动处于加载状态)。因此 04_entity_query.py、06_load_and_drop_collection.py 在查询前显式调用了 client.load_collection(...)。除以上三点,其余代码逻辑、数据、注释均与课件保持一致。