Skip to content

Commit c930cc1

Browse files
committed
Refactor vector parameter tests to use SQL commands for schema creation
- Updated test_vector_params_verification.py to replace schema methods with SQL commands for creating vertex types and properties. - Updated test_vector_sql.py to similarly replace schema methods with SQL commands for vertex type and property creation. - Ensured consistency in index verification by querying schema metadata via SQL instead of using schema methods.
1 parent 00d0b9a commit c930cc1

82 files changed

Lines changed: 2223 additions & 2200 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

bindings/python/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,6 @@ notebooks/
4545

4646
# local built jars
4747
local-jars/
48+
49+
# test databases
50+
my_test_databases/

bindings/python/README.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ import arcadedb_embedded as arcadedb
3535

3636
# Create database (context manager for automatic open and close)
3737
with arcadedb.create_database("./mydb") as db:
38-
# Create schema (schema ops are auto-transactional)
39-
db.schema.create_document_type("Person")
40-
db.schema.create_property("Person", "name", "STRING")
41-
db.schema.create_property("Person", "age", "INTEGER")
38+
# Create schema (DDL)
39+
db.command("sql", "CREATE DOCUMENT TYPE Person")
40+
db.command("sql", "CREATE PROPERTY Person.name STRING")
41+
db.command("sql", "CREATE PROPERTY Person.age INTEGER")
4242

4343
# Insert data (requires transaction)
4444
with db.transaction():
@@ -48,9 +48,6 @@ with arcadedb.create_database("./mydb") as db:
4848
result = db.query("sql", "SELECT FROM Person WHERE age > 25")
4949
for record in result:
5050
print(f"Name: {record.get('name')}")
51-
52-
# SQL also works (useful when talking to a remote server),
53-
# but the embedded API above is preferred for local use.
5451
```
5552

5653
**[👉 See full tutorial](https://docs.humem.ai/arcadedb/latest/getting-started/quickstart/)**

bindings/python/docs/api-access-methods.md

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ ArcadeDB Python bindings provide **two distinct access methods** that can be use
44

55
## Java API (Embedded Mode)
66

7-
Direct JVM method calls via JPype - **recommended for most Python applications**.
7+
Direct JVM method calls via JPype for embedded/local runtime access.
8+
9+
!!! note "DSL-first guidance"
10+
Prefer SQL/OpenCypher via `db.command(...)` and `db.query(...)` for schema, CRUD, and graph operations.
11+
Wrapper APIs remain available, but examples and guides are standardized on DSL usage.
812

913
### Characteristics
1014

@@ -23,16 +27,13 @@ import arcadedb_embedded as arcadedb
2327
# Direct database access - NO server needed
2428
with arcadedb.create_database("./mydb") as db:
2529
# Create schema (auto-transactional)
26-
db.schema.create_document_type("Person")
27-
db.schema.create_property("Person", "name", "STRING")
28-
db.schema.create_property("Person", "age", "INTEGER")
30+
db.command("sql", "CREATE DOCUMENT TYPE Person")
31+
db.command("sql", "CREATE PROPERTY Person.name STRING")
32+
db.command("sql", "CREATE PROPERTY Person.age INTEGER")
2933

3034
# Insert data (requires transaction)
3135
with db.transaction():
32-
person = db.new_document("Person")
33-
person.set("name", "Alice")
34-
person.set("age", 30)
35-
person.save()
36+
db.command("sql", "INSERT INTO Person SET name = 'Alice', age = 30")
3637

3738
# Query data (SQL is fine for reads)
3839
result = db.query("sql", "SELECT FROM Person WHERE age > 25")
@@ -54,16 +55,13 @@ try:
5455
db = server.create_database("mydb")
5556

5657
# Schema operations are auto-transactional
57-
db.schema.create_document_type("Person")
58-
db.schema.create_property("Person", "name", "STRING")
59-
db.schema.create_property("Person", "age", "INTEGER")
58+
db.command("sql", "CREATE DOCUMENT TYPE Person")
59+
db.command("sql", "CREATE PROPERTY Person.name STRING")
60+
db.command("sql", "CREATE PROPERTY Person.age INTEGER")
6061

6162
# Data operations require explicit transactions
6263
with db.transaction():
63-
person = db.new_document("Person")
64-
person.set("name", "Alice")
65-
person.set("age", 30)
66-
person.save()
64+
db.command("sql", "INSERT INTO Person SET name = 'Alice', age = 30")
6765

6866
result = db.query("sql", "SELECT FROM Person WHERE age > 25")
6967
for record in result:
@@ -130,8 +128,7 @@ try:
130128
if not response.ok:
131129
raise RuntimeError(f"Insert failed: {response.status_code} {response.text}")
132130
# Note: HTTP commands are auto-transactional per request. For multi-statement atomicity, use
133-
# the HTTP transactional endpoints or perform batch writes with the embedded API via
134-
# `with db.transaction():`.
131+
# the HTTP transactional endpoints or embedded `with db.transaction():` blocks.
135132

136133
# Query data via HTTP
137134
response = requests.post(
@@ -205,16 +202,13 @@ try:
205202
db = server.create_database("hybriddb")
206203

207204
# Schema operations are auto-transactional
208-
db.schema.create_document_type("Person")
209-
db.schema.create_property("Person", "name", "STRING")
210-
db.schema.create_property("Person", "age", "INTEGER")
205+
db.command("sql", "CREATE DOCUMENT TYPE Person")
206+
db.command("sql", "CREATE PROPERTY Person.name STRING")
207+
db.command("sql", "CREATE PROPERTY Person.age INTEGER")
211208

212209
# Data operations require explicit transactions
213210
with db.transaction():
214-
person = db.new_document("Person")
215-
person.set("name", "Alice")
216-
person.set("age", 30)
217-
person.save()
211+
db.command("sql", "INSERT INTO Person SET name = 'Alice', age = 30")
218212

219213
# Query same data using HTTP API (remote access)
220214
auth = HTTPBasicAuth("root", "password123")
@@ -248,11 +242,11 @@ finally:
248242

249243
## When to Use Each
250244

251-
### Use Java API When:
245+
### Use Embedded Mode When:
252246

253247
- Single Python process application
254248
- Maximum performance required
255-
- Complex data manipulation
249+
- Local SQL/OpenCypher workflows
256250
- Batch processing
257251
- Local development/testing
258252

@@ -265,16 +259,16 @@ finally:
265259
- Microservices architecture
266260
- Cross-network access
267261

268-
### Use Both When:
262+
### Use Hybrid Access When:
269263

270264
- Local high-performance operations + remote monitoring
271265
- Hybrid applications with embedded + web components
272-
- Development (Java API) + production monitoring (HTTP API)
266+
- Development (embedded) + production monitoring (HTTP API)
273267

274268
## Common Misconceptions
275269

276-
-**"Java API is only for Java"**
277-
-Java API is Python calling Java via JPype (fully Pythonic)
270+
-**"Embedded mode is only for Java"**
271+
-Embedded mode is Python calling Java via JPype (fully Pythonic)
278272
-**"HTTP API is inferior"**
279273
- ✅ HTTP API enables remote access (different purpose)
280274
-**"Must choose one or the other"**

bindings/python/docs/api/async_executor.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -446,12 +446,12 @@ import time
446446
# Create database
447447
db = arcadedb.create_database("./async_demo")
448448

449-
# Create schema (Schema API is auto-transactional)
450-
db.schema.create_vertex_type("Product")
451-
db.schema.create_property("Product", "productId", "LONG")
452-
db.schema.create_property("Product", "name", "STRING")
453-
db.schema.create_property("Product", "price", "DECIMAL")
454-
db.schema.create_index("Product", ["productId"], unique=True)
449+
# Create schema (ArcadeDB SQL DDL)
450+
db.command("sql", "CREATE VERTEX TYPE Product")
451+
db.command("sql", "CREATE PROPERTY Product.productId LONG")
452+
db.command("sql", "CREATE PROPERTY Product.name STRING")
453+
db.command("sql", "CREATE PROPERTY Product.price DECIMAL")
454+
db.command("sql", "CREATE INDEX ON Product (productId) UNIQUE")
455455

456456
# Prepare async executor
457457
async_exec = (db.async_executor()

bindings/python/docs/api/batch.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ import arcadedb_embedded as arcadedb
6161
db = arcadedb.create_database("./mydb")
6262

6363
# Create schema
64-
db.schema.create_vertex_type("User")
65-
db.schema.create_property("User", "userId", "LONG")
66-
db.schema.create_property("User", "name", "STRING")
67-
db.schema.create_index("User", ["userId"], unique=True)
64+
db.command("sql", "CREATE VERTEX TYPE User")
65+
db.command("sql", "CREATE PROPERTY User.userId LONG")
66+
db.command("sql", "CREATE PROPERTY User.name STRING")
67+
db.command("sql", "CREATE INDEX ON User (userId) UNIQUE")
6868

6969
# Batch create vertices
7070
with db.batch_context(batch_size=10000, parallel=8) as batch:
@@ -372,11 +372,11 @@ import time
372372
db = arcadedb.create_database("./bulk_db")
373373

374374
# Create schema
375-
db.schema.create_vertex_type("Product")
376-
db.schema.create_property("Product", "productId", "LONG")
377-
db.schema.create_property("Product", "name", "STRING")
378-
db.schema.create_property("Product", "price", "DECIMAL")
379-
db.schema.create_index("Product", ["productId"], unique=True)
375+
db.command("sql", "CREATE VERTEX TYPE Product")
376+
db.command("sql", "CREATE PROPERTY Product.productId LONG")
377+
db.command("sql", "CREATE PROPERTY Product.name STRING")
378+
db.command("sql", "CREATE PROPERTY Product.price DECIMAL")
379+
db.command("sql", "CREATE INDEX ON Product (productId) UNIQUE")
380380

381381
# Generate sample data
382382
products = [
@@ -429,9 +429,9 @@ db.close()
429429

430430
```python
431431
# ✅ Good: Schema defined before batch
432-
db.schema.create_vertex_type("User")
433-
db.schema.create_property("User", "userId", "LONG")
434-
db.schema.create_index("User", ["userId"], unique=True)
432+
db.command("sql", "CREATE VERTEX TYPE User")
433+
db.command("sql", "CREATE PROPERTY User.userId LONG")
434+
db.command("sql", "CREATE INDEX ON User (userId) UNIQUE")
435435

436436
with db.batch_context() as batch:
437437
# Batch operations

bindings/python/docs/api/database.md

Lines changed: 23 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
Complete API reference for working with ArcadeDB databases in Python.
44

5+
!!! note "DSL-first usage"
6+
For application code and examples, prefer SQL/OpenCypher via `db.command(...)` and `db.query(...)`.
7+
This page also documents wrapper/object methods for compatibility and low-level API completeness.
8+
59
## Module Functions
610

711
### create_database
@@ -30,9 +34,8 @@ Create a new database at the specified path.
3034
import arcadedb_embedded as arcadedb
3135

3236
with arcadedb.create_database("./mydb") as db:
33-
# Schema operations are auto-transactional
34-
db.schema.create_document_type("Person")
35-
db.schema.create_property("Person", "name", "STRING")
37+
db.command("sql", "CREATE DOCUMENT TYPE Person")
38+
db.command("sql", "CREATE PROPERTY Person.name STRING")
3639
```
3740

3841
!!! tip "Use Context Manager"
@@ -199,24 +202,16 @@ Execute a command (write operation). Commands modify data and **require a transa
199202
**Example:**
200203

201204
```python
202-
# Schema operations are auto-transactional
203-
db.schema.create_document_type("Person")
204-
db.schema.create_property("Person", "name", "STRING")
205-
db.schema.create_property("Person", "age", "INTEGER")
205+
# Schema operations
206+
db.command("sql", "CREATE DOCUMENT TYPE Person")
207+
db.command("sql", "CREATE PROPERTY Person.name STRING")
208+
db.command("sql", "CREATE PROPERTY Person.age INTEGER")
206209

207210
# Data operations must be in a transaction
208211
with db.transaction():
209-
doc = db.new_document("Person")
210-
doc.set("name", "Alice")
211-
doc.set("age", 30)
212-
doc.save()
213-
214-
# Update data via API
215-
doc.set("age", 31)
216-
doc.save()
217-
218-
# Delete data
219-
doc.delete()
212+
db.command("sql", "INSERT INTO Person SET name = ?, age = ?", "Alice", 30)
213+
db.command("sql", "UPDATE Person SET age = 31 WHERE name = 'Alice'")
214+
db.command("sql", "DELETE FROM Person WHERE name = 'Alice'")
220215
```
221216

222217
!!! warning "Transaction Required"
@@ -225,14 +220,10 @@ with db.transaction():
225220
```python
226221
# ✅ Correct
227222
with db.transaction():
228-
doc = db.new_document("Person")
229-
doc.set("name", "Alice")
230-
doc.save()
223+
db.command("sql", "INSERT INTO Person SET name = 'Alice'")
231224

232225
# ❌ Will fail
233-
doc = db.new_document("Person")
234-
doc.set("name", "Alice")
235-
# doc.save() outside a transaction will raise
226+
db.command("sql", "INSERT INTO Person SET name = 'Alice'")
236227
```
237228

238229
---
@@ -254,9 +245,7 @@ Create a transaction context manager.
254245
```python
255246
with db.transaction():
256247
for name in ["Alice", "Bob"]:
257-
doc = db.new_document("Person")
258-
doc.set("name", name)
259-
doc.save()
248+
db.command("sql", "INSERT INTO Person SET name = ?", name)
260249
# Automatic commit on success, rollback on exception
261250
```
262251

@@ -267,9 +256,7 @@ with db.transaction():
267256
db.begin()
268257
try:
269258
for name in ["Alice", "Bob"]:
270-
doc = db.new_document("Person")
271-
doc.set("name", name)
272-
doc.save()
259+
db.command("sql", "INSERT INTO Person SET name = ?", name)
273260
db.commit()
274261
except Exception as e:
275262
db.rollback()
@@ -438,9 +425,9 @@ Lookup a record by an indexed key (O(1) index-based lookup).
438425
**Example:**
439426

440427
```python
441-
db.schema.create_vertex_type("User")
442-
db.schema.create_property("User", "email", "STRING")
443-
db.schema.create_index("User", ["email"], unique=True)
428+
db.command("sql", "CREATE VERTEX TYPE User")
429+
db.command("sql", "CREATE PROPERTY User.email STRING")
430+
db.command("sql", "CREATE INDEX ON User (email) UNIQUE")
444431

445432
with db.transaction():
446433
db.new_vertex("User").set("email", "alice@example.com").save()
@@ -607,9 +594,9 @@ Create a vector index for similarity search (JVector implementation). Existing r
607594
import numpy as np
608595

609596
# Create schema (auto-transactional)
610-
db.schema.create_vertex_type("Document")
611-
db.schema.create_property("Document", "embedding", "ARRAY_OF_FLOATS")
612-
db.schema.create_property("Document", "id", "STRING")
597+
db.command("sql", "CREATE VERTEX TYPE Document")
598+
db.command("sql", "CREATE PROPERTY Document.embedding ARRAY_OF_FLOATS")
599+
db.command("sql", "CREATE PROPERTY Document.id STRING")
613600

614601
# Create vector index
615602
index = db.create_vector_index("Document", "embedding", dimensions=384)

bindings/python/docs/api/exceptions.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -376,11 +376,10 @@ def safe_database_operation():
376376
db = arcadedb.create_database("./mydb")
377377

378378
# Initialize schema
379-
# Prefer Schema API for embedded usage (auto-transactional)
380-
db.schema.create_document_type("Person")
381-
db.schema.create_property("Person", "name", "STRING")
382-
db.schema.create_property("Person", "email", "STRING")
383-
db.schema.create_index("Person", ["email"], unique=True)
379+
db.command("sql", "CREATE DOCUMENT TYPE Person")
380+
db.command("sql", "CREATE PROPERTY Person.name STRING")
381+
db.command("sql", "CREATE PROPERTY Person.email STRING")
382+
db.command("sql", "CREATE INDEX ON Person (email) UNIQUE")
384383
else:
385384
db = arcadedb.open_database("./mydb")
386385

0 commit comments

Comments
 (0)