Jupyter Notebook运行Milvus Lite

安装python和notebook

https://blog.csdn.net/Cosmoshhhyyy/article/details/153722910?spm=1001.2014.3001.5501

nodebook使用venv虚拟环境

https://blog.csdn.net/Cosmoshhhyyy/article/details/153724440?spm=1001.2014.3001.5501

复制代码
pip3 install -U pymilvus

官网说下载了pymilvus就自带milvus-lite了,但是我这里还是报错缺少milvus-lite,下载一下。

复制代码
pip3 install milvus_lite

运行官方demo:

python 复制代码
from pymilvus import MilvusClient
import numpy as np

client = MilvusClient("./milvus_demo.db")
client.create_collection(
    collection_name="demo_collection",
    dimension=384  # The vectors we will use in this demo has 384 dimensions
)

docs = [
    "Artificial intelligence was founded as an academic discipline in 1956.",
    "Alan Turing was the first person to conduct substantial research in AI.",
    "Born in Maida Vale, London, Turing was raised in southern England.",
]

vectors = [[ np.random.uniform(-1, 1) for _ in range(384) ] for _ in range(len(docs)) ]
data = [ {"id": i, "vector": vectors[i], "text": docs[i], "subject": "history"} for i in range(len(vectors)) ]
res = client.insert(
    collection_name="demo_collection",
    data=data
)

res = client.search(
    collection_name="demo_collection",
    data=[vectors[0]],
    filter="subject == 'history'",
    limit=2,
    output_fields=["text", "subject"],
)
print(res)

res = client.query(
    collection_name="demo_collection",
    filter="subject == 'history'",
    output_fields=["text", "subject"],
)
print(res)

res = client.delete(
    collection_name="demo_collection",
    filter="subject == 'history'",
)
print(res)
相关推荐
悟能不能悟2 小时前
如何打开2个notepad++
ide
wVelpro4 小时前
如何在Pycharm 2025.3 版本实现虚拟环境“Make available to all projects”
linux·ide·pycharm
jun_bai6 小时前
VSCode使用
ide·vscode·编辑器
猫头虎7 小时前
OpenClaw-VSCode:在 VS Code 里玩转 OpenClaw,远程管理+SSH 双剑合璧
ide·vscode·开源·ssh·github·aigc·ai编程
手揽回忆怎么睡9 小时前
opencode和TRAE使用Superpowers 和ui-ux-pro-max skillls
ide·ui·ai·ux
CaracalTiger10 小时前
OpenClaw-VSCode:在 VS Code 中通过 WebSocket 远程管理 OpenClaw 网关的完整方案
运维·ide·人工智能·vscode·websocket·开源·编辑器
CS创新实验室11 小时前
Pandas 3 的新功能
android·ide·pandas
uncle_ll1 天前
Milvus介绍及多模态检索实践:从部署到实战全解析
milvus·多模态·向量数据库·ann·rag·搜索·检索
先跑起来再说1 天前
Git 入门到实战:一篇搞懂安装、命令、远程仓库与 IDEA 集成
ide·git·后端·elasticsearch·golang·intellij-idea
LYOBOYI1231 天前
vscode界面美化
ide·vscode·编辑器