mirror of
https://github.com/zots0127/paper_dataset.git
synced 2026-06-06 00:04:51 +00:00
73 lines
1.7 KiB
Plaintext
73 lines
1.7 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 5,
|
|
"id": "bcda7dd6-621a-4018-806a-e3a4b7c7b5b2",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"Vector dimension: 384\n",
|
|
"First element of the vector: -0.027828959748148918\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"import redis\n",
|
|
"import numpy as np\n",
|
|
"\n",
|
|
"# 初始化Redis客户端\n",
|
|
"r = redis.Redis(host='localhost', port=6379, db=3) # 假设向量保存在db=0中\n",
|
|
"\n",
|
|
"# 获取一个向量的键\n",
|
|
"keys = r.keys('*')\n",
|
|
"if not keys:\n",
|
|
" print(\"No keys found in Redis.\")\n",
|
|
"else:\n",
|
|
" # 读取第一个键的向量\n",
|
|
" key = keys[0]\n",
|
|
" vector_data = r.get(key)\n",
|
|
"\n",
|
|
" # 将二进制数据转换为numpy数组\n",
|
|
" vector = np.frombuffer(vector_data, dtype=np.float32)\n",
|
|
"\n",
|
|
" # 打印向量维度\n",
|
|
" print(f\"Vector dimension: {vector.shape[0]}\")\n",
|
|
" print(f\"First element of the vector: {vector[0]}\") # 举例打印第一个元素\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "d55ce965-c121-45dc-8570-a34f1edbefa1",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "Python 3 (ipykernel)",
|
|
"language": "python",
|
|
"name": "python3"
|
|
},
|
|
"language_info": {
|
|
"codemirror_mode": {
|
|
"name": "ipython",
|
|
"version": 3
|
|
},
|
|
"file_extension": ".py",
|
|
"mimetype": "text/x-python",
|
|
"name": "python",
|
|
"nbconvert_exporter": "python",
|
|
"pygments_lexer": "ipython3",
|
|
"version": "3.12.2"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 5
|
|
}
|