Skip to content

Commit 4173453

Browse files
committed
irisvector example
1 parent 2cc72dc commit 4173453

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

README.md

+54
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,60 @@ docker run -d --name iris \
7474
intersystemsdc/iris-community:preview
7575
```
7676

77+
Examples
78+
===
79+
80+
IRISVector
81+
---
82+
83+
```python
84+
from sqlalchemy import Column, MetaData, Table, select
85+
from sqlalchemy.sql.sqltypes import Integer, UUID
86+
from sqlalchemy_iris import IRISVector
87+
from sqlalchemy import create_engine
88+
from sqlalchemy.orm import DeclarativeBase
89+
import uuid
90+
91+
DATABASE_URL = "iris://_SYSTEM:SYS@localhost:1972/USER"
92+
engine = create_engine(DATABASE_URL, echo=False)
93+
94+
# Create a table metadata
95+
metadata = MetaData()
96+
97+
98+
class Base(DeclarativeBase):
99+
pass
100+
101+
102+
def main():
103+
demo_table = Table(
104+
"demo_table",
105+
metadata,
106+
Column("id", Integer, primary_key=True, autoincrement=True),
107+
Column("uuid", UUID),
108+
Column("embedding", IRISVector(item_type=float, max_items=3)),
109+
)
110+
111+
demo_table.drop(engine, checkfirst=True)
112+
demo_table.create(engine, checkfirst=True)
113+
with engine.connect() as conn:
114+
conn.execute(
115+
demo_table.insert(),
116+
[
117+
{"uuid": uuid.uuid4(), "embedding": [1, 2, 3]},
118+
{"uuid": uuid.uuid4(), "embedding": [2, 3, 4]},
119+
],
120+
)
121+
conn.commit()
122+
result = conn.execute(
123+
demo_table.select()
124+
).fetchall()
125+
print("result", result)
126+
127+
128+
main()
129+
```
130+
77131
_Port 1972 is used for binary communication (this driver, xDBC and so on), and 52773 is for web (Management Portal, IRIS based web-applications and API's)._
78132

79133
The System Management Portal is available by URL: `http://localhost:52773/csp/sys/UtilHome.csp`

0 commit comments

Comments
 (0)