mirror of
https://github.com/qdrant/qdrant-client.git
synced 2026-08-03 08:30:58 -05:00
* new: update autogenerated code * fix: fix config conversions * new: add pydantic compat * new: add types to pydantic_compat * new: update dependencies * new: use pydantic compat functions * new: add pydantic v2 field check * fix typing * fix typing --------- Co-authored-by: generall <andrey@vasnetsov.com>
70 lines
2.0 KiB
Python
70 lines
2.0 KiB
Python
import random
|
|
import tempfile
|
|
|
|
import numpy as np
|
|
|
|
import qdrant_client
|
|
import qdrant_client.http.models as rest
|
|
from qdrant_client._pydantic_compat import construct
|
|
|
|
default_collection_name = "example"
|
|
|
|
|
|
def ingest_data(
|
|
vector_size=1500,
|
|
path=None,
|
|
collection_name=default_collection_name,
|
|
): # vector_size < 433: works, vector_size >= 433: crashes
|
|
lines = [x for x in range(10)]
|
|
|
|
embeddings = np.random.randn(len(lines), vector_size).tolist()
|
|
client = qdrant_client.QdrantClient(path=path)
|
|
|
|
client.recreate_collection(
|
|
collection_name,
|
|
vectors_config=rest.VectorParams(
|
|
size=vector_size,
|
|
distance=rest.Distance.COSINE,
|
|
),
|
|
)
|
|
|
|
client.upsert(
|
|
collection_name=collection_name,
|
|
points=construct(
|
|
rest.Batch,
|
|
ids=random.sample(range(100), len(lines)),
|
|
vectors=embeddings,
|
|
),
|
|
)
|
|
|
|
|
|
def test_prevent_parallel_access():
|
|
with tempfile.TemporaryDirectory() as tmpdir:
|
|
client = qdrant_client.QdrantClient(path=tmpdir)
|
|
|
|
try:
|
|
client2 = qdrant_client.QdrantClient(path=tmpdir)
|
|
assert False
|
|
except Exception as e:
|
|
error_message = str(e)
|
|
assert "already accessed by another instance" in error_message
|
|
|
|
|
|
def test_local_persistence():
|
|
with tempfile.TemporaryDirectory() as tmpdir:
|
|
ingest_data(path=tmpdir)
|
|
client = qdrant_client.QdrantClient(path=tmpdir)
|
|
assert 10 == client.count(default_collection_name).count
|
|
del client
|
|
|
|
ingest_data(path=tmpdir)
|
|
client = qdrant_client.QdrantClient(path=tmpdir)
|
|
assert 10 == client.count(default_collection_name).count
|
|
del client
|
|
|
|
ingest_data(path=tmpdir)
|
|
ingest_data(path=tmpdir, collection_name="example_2")
|
|
client = qdrant_client.QdrantClient(path=tmpdir)
|
|
assert 10 == client.count(default_collection_name).count
|
|
assert 10 == client.count("example_2").count
|