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)
相关推荐
wabil2 天前
[AI-Talk] codx制作xmind文件技巧
ide·ai编程·myeclipse·xmind
大衛說2 天前
02 · 环境搭建:uv 包管理与现代 IDE
ide·uv
cndes2 天前
安装Miniconda+Jupyter notebook
ide·python·jupyter
典典分享指南2 天前
用大模型把写作 SOP 变成可复用 Prompt
docker·jupyter·eclipse·phpstorm·myeclipse
洛兮银儿2 天前
pycharm选中同一个词的标记颜色的修改
ide·python·pycharm
Sherotree3 天前
Google Antigravity——Agent 被提到主界面
前端·ide·后端·edge浏览器
YZJenny3 天前
在服务器上安装使用code-server(Web 版 VS Code)
ide·vscode·编辑器
m0_579146653 天前
PostgreSQL+Milvus分层存储架构:双写一致性与CAP理论取舍分析
postgresql·架构·milvus·cap
salestina3 天前
vscode迁移扩展目录
ide·vscode·编辑器
Chasing__Dreams4 天前
向量数据库--Milvus--2--介绍
数据库·milvus