High-Level SDK¶
이 예제는 akasicdb.sdk.AkasicDB를 사용하여 collection을 만들고, record를 삽입한 뒤 metadata filter와 함께 vector search를 실행합니다.
설치¶
예제¶
from akasicdb.sdk import AkasicDB, Record, filters
DB_URL = "postgresql+psycopg://postgres:mysecretpassword@localhost:5432/postgres"
TARGET = [1.0, 2.0, 5.0]
client = AkasicDB(
db_url=DB_URL,
collection_name="example",
dimension=3,
create_vector_index=True,
recreate=True,
)
try:
client.insert(
[
Record.from_text("Hello world", [1.0, 2.0, 3.0], {"src": "one"}),
Record.from_text("Hello PostgreSQL", [1.0, 2.0, 4.0], {"src": "one"}),
Record.from_text("Hello AkasicDB", [1.0, 3.0, 4.0], {"src": "two"}),
]
)
print("Filter helper")
for record, distance in client.search(
TARGET,
top_k=3,
filter=filters.meta_contains({"src": "one"}),
):
print(record.text, distance)
print("Dictionary filter")
for record, distance in client.search(
TARGET,
top_k=3,
filter={"src": {"$eq": "one"}},
):
print(record.text, distance)
finally:
client.drop()
recreate=True는 같은 이름의 collection table이 이미 있으면 새로 생성합니다. 예제 마지막의 client.drop()은 예제에서 만든 collection_example table을 정리합니다.