Skip to content

armgit / camel

Public Imported from GitHub
0

🐫 CAMEL: The first and the best multi-agent framework. Finding the Scaling Law of Agents. https://www.camel-ai.org

docs: add oceanbase doc (#2481)

Yifeng Wang(正经人王同学)4414d344f994
diff --git a/docs/get_started/installation.md b/docs/get_started/installation.md
index 3bef034ff..fe5d54796 100644
--- a/docs/get_started/installation.md
+++ b/docs/get_started/installation.md
@@ -19,7 +19,7 @@ Available extras:
- `all`: Includes all features below
- `model_platforms`: OpenAI, Google, Mistral, Anthropic Claude, Cohere etc.
- `huggingface`: Transformers, Diffusers, Accelerate, Datasets, PyTorch etc.
-- `rag`: Sentence Transformers, Qdrant, Milvus, TiDB, BM25 etc.
+- `rag`: Sentence Transformers, Qdrant, Milvus, TiDB, OceanBase,BM25 etc.
- `storage`: Neo4j, Redis, Azure Blob, Google Cloud Storage, AWS S3 etc.
- `web_tools`: DuckDuckGo, Wikipedia, WolframAlpha, Google Maps, Weather API etc.
- `document_tools`: PDF, Word, OpenAPI, BeautifulSoup, Unstructured etc.
diff --git a/docs/key_modules/storages.md b/docs/key_modules/storages.md
index 032d2b5f4..7e6c9dd01 100644
--- a/docs/key_modules/storages.md
+++ b/docs/key_modules/storages.md
@@ -56,6 +56,13 @@ Reference: [TiDB](https://ai.pingcap.com/)
Reference: [Qdrant](https://qdrant.tech/)
+
+**`OceanBaseStorage`**:
+
+- Description: A concrete implementation of `BaseVectorStorage`, tailored for interacting with OceanBase vector engine.
+
+Reference: [OceanBase](https://www.oceanbase.com/)
+
### 2.3 Graph Storages
**`BaseGraphStorage`**:
@@ -232,9 +239,143 @@ qdrant_storage.clear()
```
```markdown
>>> {'key2': 'value2'} 0.5669467095138407
+```
+### 3.6. Using `OceanBaseStorage`
+
+```python
+import random
+
+from camel.storages.vectordb_storages import (
+ OceanBaseStorage,
+ VectorDBQuery,
+ VectorRecord,
+)
+
+"""
+Before running this example, you need to setup an OceanBase instance:
+(Option 1): OceanBase Community Edition (OCE):
+1. Download and install OCE from the official website:
+ https://www.oceanbase.com/docs/oceanbase-database-cn
+2. Start the OceanBase server and create a database user
+3. Install PyOBVector package:
+ pip install pyobvector
+(Option 2): OceanBase Cloud Service:
+1. Sign up for OceanBase Cloud Service
+2. Create a cluster with OceanBase Vector enabled
+3. Get your connection parameters from the service console
+The connection parameters should include:
+- URI: hostname:port
+- User: username@tenant
+- Password: your_password
+- Database name: database_name
+"""
+
+# Replace these with your OceanBase connection parameters
+OB_URI = "127.0.0.1:2881"
+OB_USER = "root@sys"
+OB_PASSWORD = ""
+OB_DB_NAME = "oceanbase"
+
+
+def main():
+ # Create an instance of OceanBaseStorage with dimension = 64
+ ob_storage = OceanBaseStorage(
+ vector_dim=4,
+ table_name="my_ob_vector_table",
+ uri=OB_URI,
+ user=OB_USER,
+ password=OB_PASSWORD,
+ db_name=OB_DB_NAME,
+ distance="cosine",
+ )
+
+ # Get database status
+ status = ob_storage.status()
+ print(f"Vector dimension: {status.vector_dim}")
+ print(f"Initial vector count: {status.vector_count}")
+
+ # Generate and add a larger number of vectors using batching
+ print("\nAdding vectors in batches...")
+ random.seed(20241023)
+
+ # Create a large batch of vector records
+ large_batch = []
+ for i in range(1000):
+ large_batch.append(
+ VectorRecord(
+ vector=[random.uniform(-1, 1) for _ in range(4)],
+ payload={'idx': i, 'batch': 'example'},
+ )
+ )
+
+ # Add vectors with automatic batching (batch_size=100)
+ ob_storage.add(large_batch, batch_size=100)
+
+ # Check updated status
+ status = ob_storage.status()
+ print(f"Vector count after adding batch: {status.vector_count}")
+
+ # Generate a query vector and search for similar vectors
+ print("\nQuerying similar vectors...")
+ query_vector = [random.uniform(-1, 1) for _ in range(4)]
+ query_results = ob_storage.query(
+ VectorDBQuery(query_vector=query_vector, top_k=5)
+ )
+
+ # Display results
+ for i, result in enumerate(query_results):
+ print(f"Result {i+1}:")
+ print(f" ID: {result.record.id}")
+ print(f" Payload: {result.record.payload}")
+ print(f" Similarity: {result.similarity}")
+
+ # Clear all vectors when done
+ print("\nClearing vectors...")
+ ob_storage.clear()
+ status = ob_storage.status()
+ print(f"Vector count after clearing: {status.vector_count}")
+
+
+if __name__ == "__main__":
+ main()
+
+```
+```markdown
+'''
+===============================================================================
+Vector dimension: 4
+Initial vector count: 0
+Adding vectors in batches...
+Vector count after adding batch: 1000
+Querying similar vectors...
+Result 1:
+ ID: f33f008d-688a-468a-9a2d-e005d27ad9d8
+ Payload: {'idx': 496, 'batch': 'example'}
+ Similarity: 0.9847431876706196
+Result 2:
+ ID: 0946ca4a-9129-4343-b339-b2f13a64c827
+ Payload: {'idx': 306, 'batch': 'example'}
+ Similarity: 0.9598140307734809
+Result 3:
+ ID: e2505cc3-7bee-433e-a723-c830b9404f61
+ Payload: {'idx': 654, 'batch': 'example'}
+ Similarity: 0.9548076959468635
+Result 4:
+ ID: 8d6359ff-49fd-4fb7-99fd-bf4ca0a0cdcc
+ Payload: {'idx': 914, 'batch': 'example'}
+ Similarity: 0.9496165658207311
+Result 5:
+ ID: 45cef390-3e1f-4e16-8375-b4108951a93b
+ Payload: {'idx': 806, 'batch': 'example'}
+ Similarity: 0.9485824622759768
+Clearing vectors...
+Vector count after clearing: 0
+===============================================================================
+'''
+
```
-### 3.6. Using `NebulaGraph`
+### 3.7. Using `NebulaGraph`
```python
from camel.storages.graph_storages import NebulaGraph
@@ -246,7 +387,7 @@ query = 'SHOW TAGS;'
print(nebula_graph.query(query))
```
-### 3.7. Using `Neo4jGraph`
+### 3.8. Using `Neo4jGraph`
```python
from camel.storages import Neo4jGraph