试用oceanbase seekdb

官方网站https://www.oceanbase.ai/
我试用的是嵌入式
安装

python3 par/pip.pyz install pyseekdb --break-system-packages -i https://pypi.tuna.tsinghua.edu.cn/simple
它卸载了numpy 2.3.4, 安装了numpy-1.26.4,其他没什么影响。
  Attempting uninstall: numpy
    Found existing installation: numpy 2.3.4
    Uninstalling numpy-2.3.4:
      Successfully uninstalled numpy-2.3.4
Successfully installed anyio-4.11.0 certifi-2025.11.12 charset_normalizer-3.4.4 coloredlogs-15.0.1 filelock-3.20.0 flatbuffers-25.9.23 fsspec-2025.10.0 h11-0.16.0 hf-xet-1.2.0 httpcore-1.0.9 httpx-0.28.1 huggingface_hub-0.36.0 humanfriendly-10.0 idna-3.11 mpmath-1.3.0 numpy-1.26.4

然后把文档https://www.oceanbase.ai/docs/zh-CN/using-seekdb-in-python-sdk中代码复制到文件

import pyseekdb
from pyseekdb import DefaultEmbeddingFunction

# ==================== Step 1: 创建连接 ====================
# You can use embedded mode, server mode, or OceanBase mode
# For this example, we'll use embedded mode (you can change to server or OceanBase mode)

# Server mode (connecting to remote seekdb server)
# client = pyseekdb.Client(
#     host="127.0.0.1",
#     port=2881,
#     database="test",
#     user="root",
#     password=""
# )

# 连接嵌入式 seekdb
client = pyseekdb.Client(
    path="./seekdb",
    database="test"
)

# Alternative: OceanBase mode
# client = pyseekdb.OBClient(
#     host="127.0.0.1",
#     port=11402,
#     tenant="mysql",
#     database="test",
#     user="root",
#     password=""
# )

# ==================== Step 2: 创建带有 Embedding Functions 的 collection ====================
# A collection is like a table that stores documents with vector embeddings
collection_name = "my_simple_collection"

# 使用默认 embedding function 创建 collection
# embedding function 自动将 documents 转化为 vectors
collection = client.create_collection(
    name=collection_name,
    embedding_function=DefaultEmbeddingFunction()  # 使用默认模式 (384 dimensions)
)

print(f"Created collection '{collection_name}' with dimension: {collection.dimension}")
print(f"Embedding function: {collection.embedding_function}")

# ==================== Step 3: 往 Collection 添加数据 ====================
# 通过 embedding function, 您可以直接添加 documents 不需要提供 vectors
# embedding function 将自动从 documents 生成 vectors

documents = [
    "Machine learning is a subset of artificial intelligence",
    "Python is a popular programming language",
    "Vector databases enable semantic search",
    "Neural networks are inspired by the human brain",
    "Natural language processing helps computers understand text"
]

ids = ["id1", "id2", "id3", "id4", "id5"]

# 仅添加 documents - 通过 embedding function 自动生成 vectors
collection.add(
    ids=ids,
    documents=documents,  # Vectors will be automatically generated
    metadatas=[
        {"category": "AI", "index": 0},
        {"category": "Programming", "index": 1},
        {"category": "Database", "index": 2},
        {"category": "AI", "index": 3},
        {"category": "NLP", "index": 4}
    ]
)

print(f"\nAdded {len(documents)} documents to collection")
print("Note: Vectors were automatically generated from documents using the embedding function")

# ==================== Step 4: 查询 Collection ====================
# With embedding function, you can query using text directly
# embedding function 自动将查询 text 转化为查询 vector

# 使用 text 进行查询- 通过 embedding function 将自动生成查询 vector 
query_text = "artificial intelligence and machine learning"

results = collection.query(
    query_texts=query_text,  # Query text - will be embedded automatically
    n_results=3  # 返回前 3 个 documents
)

print(f"\nQuery: '{query_text}'")
print(f"Query results: {len(results)} items found")

# ==================== Step 5: 打印查询结果 ====================
for i, item in enumerate(results, 1):
    print(f"\nResult {i}:")
    print(f"  ID: {item._id}")
    print(f"  Distance: {item.distance:.4f}")
    print(f"  Document: {item.document}")
    print(f"  Metadata: {item.metadata}")

# ==================== Step 6: 清理 collection ====================
# 删除 collection
client.delete_collection(collection_name)
print(f"\nDeleted collection '{collection_name}'")

添加收集的时候会自动下载模型

model.onnx: 100%|█████████████████████████████████████████████████████████████████| 86.2M/86.2M [00:10<00:00, 8.56MiB/s]
tokenizer.json: 455kiB [00:00, 1.42MiB/s]
config.json: 612iB [00:00, 2.73MiB/s]
special_tokens_map.json: 112iB [00:00, 724kiB/s]
tokenizer_config.json: 350iB [00:00, 2.00MiB/s]
vocab.txt: 226kiB [00:00, 774kiB/s]

代码打印查询结果错

Result 1:
Traceback (most recent call last):
  File "<stdin>", line 3, in <module>
AttributeError: 'str' object has no attribute '_id'

我把它改成如下,出结果了,原来属性名是ids不是_id。

>>> print(results)
{'ids': [['id1', 'id4', 'id5']], 'distances': [[0.3007760478126502, 0.5982640429376553, 0.685555282270486]], 'documents': [['Machine learning is a subset of artificial intelligence', 'Neural networks are inspired by the human brain', 'Natural language processing helps computers understand text']], 'metadatas': [[{'index': 0, 'category': 'AI'}, {'index': 3, 'category': 'AI'}, {'index': 4, 'category': 'NLP'}]]}

如果不删除收集,下次create会报错,可以用以下语法打开已有的收集

>>> collection = client.get_collection(
        name=collection_name,
        embedding_function=DefaultEmbeddingFunction()  # 使用默认模式 (384 dimensions)
 )

主页上还有另一种语法

import pyseekdb

client = pyseekdb.Client()

# create a knowledge base
collection = client.get_or_create_collection("product_database")
# Add product documents
collection.upsert(
    documents=[
        "Laptop Pro with 16GB RAM, 512GB SSD, and high-speed processor",
        "Gaming Laptop with 32GB RAM, 1TB SSD, and high-performance graphics",
        "Business Ultrabook with 8GB RAM, 256GB SSD, and long battery life",
        "Tablet with 6GB RAM, 128GB storage, and 10-inch display"
    ],
    metadatas=[
        {"category": "laptop", "ram": 16, "storage": 512, "price": 12000, "type": "professional"},
        {"category": "laptop", "ram": 32, "storage": 1000, "price": 25000, "type": "gaming"},
        {"category": "laptop", "ram": 8, "storage": 256, "price": 9000, "type": "business"},
        {"category": "tablet", "ram": 6, "storage": 128, "price": 6000, "type": "consumer"}
    ],
    ids=["1", "2", "3", "4"]
)

# Hybrid search for high-performance laptops
results = collection.query(
    query_texts=["powerful computer for professional work"],  # Vector search
    where={                                                   # Relational filter
        "category": "laptop",
        "ram": {"$gte": 16}
    },
    where_document={"$contains": "RAM"},                      # Full-text search
    n_results=2
)

print("\nResults:")
for i, (doc, metadata) in enumerate(zip(results['documents'][0], results['metadatas'][0])):
    print(f"  {i+1}. {doc}")

也能新建收集

>>> client = pyseekdb.Client()
>>> collection = client.get_or_create_collection("collection_name")
[seekdb] seekdb has opened

客户端/服务器模式只要修改第一部分,其他都一样

import pyseekdb

client = pyseekdb.Client(
        host = "127.0.0.1",          # server host
        port = 2881,                 # server port (default: 2881)
        )

# create a knowledge base
collection = client.get_or_create_collection("product_database")

实际执行会报错,需要mysql服务器

pymysql.err.OperationalError: (2003, "Can't connect to MySQL server on '127.0.0.1' ([Errno 111] Connection refused)")
<think> 根据用户的问题,需要解决在CentOS7虚拟机上使用Yum部署OceanBase时因无法解析镜像站点域名而失败的问题。用户提到无法解析镜像站点域名,这通常与DNS配置有关。 解决思路: 1. 检查网络连通性,特别是DNS解析是否正常。 2. 配置正确的DNS服务器。 3. 确保虚拟机可以访问互联网。 具体步骤: 1. 检查网络连通性: - 使用`ping`命令测试能否解析并访问外部域名(如百度)。 2. 检查DNS配置: - 查看`/etc/resolv.conf`文件,确认是否有有效的DNS服务器。 3. 修改DNS配置(如果需要): - 编辑网络配置文件,添加DNS服务器。 4. 重启网络服务使配置生效。 另外,用户提到使用yum部署,需要确保yum源配置正确。用户之前尝试使用阿里云的镜像源,所以这里我们也会检查yum源配置。 详细步骤: 步骤1:检查网络连通性 ```bash ping www.baidu.com ``` 如果无法解析,则说明DNS解析有问题。 步骤2:检查DNS配置文件 ```bash cat /etc/resolv.conf ``` 如果其中没有有效的DNS服务器(如8.8.8.8或114.114.114.114),则需要配置。 步骤3:修改DNS配置(以CentOS7为例) - 编辑网卡配置文件,例如`/etc/sysconfig/network-scripts/ifcfg-ens33`(网卡名称可能不同) - 在文件中添加或修改: ``` DNS1=8.8.8.8 DNS2=114.114.114.114 ``` - 保存并退出。 步骤4:重启网络服务 ```bash systemctl restart network ``` 步骤5:再次测试网络连通性 ```bash ping www.baidu.com ``` 此外,如果用户使用的是虚拟机(如VMware),还需要检查虚拟机的网络连接模式(建议使用NAT模式),并确保宿主机的网络正常。 如果问题依然存在,可能需要检查防火墙设置(关闭防火墙测试)或者检查宿主机的DNS设置。 关于yum源配置,用户已经使用了阿里云的镜像源,但为了确保正确,可以检查: ```bash cat /etc/yum.repos.d/CentOS-Base.repo ``` 如果以上步骤还不能解决问题,可能需要检查虚拟机的DNS解析服务是否被覆盖(例如,Docker服务可能会修改/etc/resolv.conf),或者检查是否有其他网络配置问题。 注意:用户特别指出是部署OceanBase时遇到的问题,但根本原因在于DNS解析,因此解决DNS解析问题即可。 根据引用[1]和[2],用户之前尝试了使用阿里云的yum源,并且提到了docker的安装,但问题出现在解析镜像站点域名,所以重点在DNS解析。 生成相关问题: 1. 如何配置CentOS7的静态IP? 2. 如何检查CentOS7的网络连接? 3. OceanBase部署需要哪些先决条件? </think> ### CentOS7虚拟机使用Yum部署OceanBase时无法解析镜像站点域名的解决方案 该问题通常由DNS配置错误或网络连接问题导致。以下是完整的解决步骤: #### 1. **检查网络连通性** ```bash ping 8.8.8.8 # 测试基础网络连通性 ping www.baidu.com # 测试DNS解析能力 ``` - 若IP可通但域名不通 → **DNS配置问题** - 若IP也不通 → **虚拟机网络设置问题**[^1] #### 2. **修复DNS配置** **修改DNS服务器地址**: ```bash sudo vi /etc/resolv.conf # 添加公共DNS ``` 添加内容: ```plaintext nameserver 8.8.8.8 nameserver 114.114.114.114 ``` 保存后执行: ```bash sudo chattr +i /etc/resolv.conf # 防止重启被覆盖 systemctl restart NetworkManager ``` #### 3. **配置Yum镜像源** ```bash sudo mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup # 备份 sudo curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo sudo yum makecache # 重建缓存 ``` #### 4. **验证DNS解析** ```bash nslookup mirrors.aliyun.com # 测试镜像站解析 curl -I http://mirrors.aliyun.com # 测试HTTP访问 ``` #### 5. **防火墙设置(关键)** ```bash sudo firewall-cmd --permanent --add-service=http sudo firewall-cmd --permanent --add-service=https sudo firewall-cmd --reload ``` #### 6. **虚拟机网络模式检查** 在VMware中: 1. 选择虚拟机 → 设置 → 网络适配器 2. 确认使用 **NAT模式**(非主机模式) 3. 编辑 → 虚拟网络编辑器 → 恢复默认设置 #### 7. **完整部署流程验证** ```bash sudo yum install -y docker # 测试基础安装 sudo systemctl start docker docker pull oceanbase/oceanbase-ce # 测试OceanBase镜像获取 ``` > **注意**:若使用公司内网,需在`/etc/sysconfig/network-scripts/ifcfg-ens33`中添加: > ```plaintext > DNS1=公司内网DNS_IP > PEERDNS=no > ``` ### 常见错误处理 - **错误: Could not resolve host** 执行`sudo vi /etc/hosts`添加: ```plaintext 192.168.1.1 hostname # 替换实际主机名和IP ``` - **错误: Temporary failure in name resolution** 重启网络服务: ```bash sudo systemctl restart network ``` [^1]: 引用自OceanBase数据库Docker部署文档中关于虚拟机配置的说明 [^2]: 参考OceanBase官方Docker部署指南中的网络要求
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值