-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Keming <[email protected]>
- Loading branch information
Showing
8 changed files
with
90 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
server/pgvecto.rs/compose.yaml → docker/compose.pgvecto_rs.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
services: | ||
qdrant: | ||
image: qdrant/qdrant:v1.7.4 | ||
container_name: qdrant | ||
ports: | ||
- "6333:6333" | ||
logging: | ||
driver: "json-file" | ||
options: | ||
max-file: "1" | ||
max-size: "10m" | ||
deploy: | ||
resources: | ||
limits: | ||
cpus: "8" | ||
reservations: | ||
cpus: "4" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
from vector_bench.client.pgvecto_rs import PgVectorsClient | ||
from vector_bench.client.pgvector import PgvectorClient | ||
from vector_bench.client.qdrant import QdrantVectorClient | ||
from vector_bench.spec import EnumSelector | ||
|
||
|
||
class DataBaseClient(EnumSelector): | ||
PGVECTO_RS = PgVectorsClient | ||
PGVECTOR = PgvectorClient | ||
QDRANT = QdrantVectorClient |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
from __future__ import annotations | ||
|
||
from qdrant_client import QdrantClient | ||
from qdrant_client.models import Distance as QdrantDistance | ||
from qdrant_client.models import PointStruct, ScoredPoint, VectorParams | ||
|
||
from vector_bench.client.base import BaseClient | ||
from vector_bench.spec import DatabaseConfig, Distance, Record | ||
|
||
DISTANCE_TO_QDRANT = { | ||
Distance.COSINE: QdrantDistance.COSINE, | ||
Distance.EUCLIDEAN: QdrantDistance.EUCLID, | ||
Distance.DOT_PRODUCT: QdrantDistance.DOT, | ||
} | ||
|
||
|
||
class QdrantVectorClient(BaseClient): | ||
dim: int | ||
url: str | ||
table: str | ||
distance: Distance | ||
|
||
@classmethod | ||
def from_config(cls, config: DatabaseConfig) -> QdrantVectorClient: | ||
cls.dim = config.vector_dim | ||
cls.url = config.url | ||
cls.table = f"{config.table}_qdrant" | ||
cls.distance = config.distance | ||
|
||
cls = QdrantVectorClient() | ||
cls.init_db() | ||
return cls | ||
|
||
def init_db(self): | ||
self.client = QdrantClient(url=self.url) | ||
self.client.create_collection( | ||
collection_name=self.table, | ||
vectors_config=VectorParams( | ||
size=self.dim, | ||
distance=DISTANCE_TO_QDRANT[self.distance.__func__], | ||
), | ||
) | ||
|
||
def insert_batch(self, records: list[Record]): | ||
self.client.upsert( | ||
collection_name=self.table, | ||
points=[ | ||
PointStruct( | ||
id=record.id, vector=record.vector.tolist(), payload=record.metadata | ||
) | ||
for record in records | ||
], | ||
) | ||
|
||
def query(self, vector: list[float], top_k: int = 10) -> list[Record]: | ||
points: list[ScoredPoint] = self.client.search( | ||
collection_name=self.table, | ||
query_vector=vector, | ||
limit=top_k, | ||
) | ||
return [ | ||
Record(id=point.id, vector=point.vector, metadata=point.payload) | ||
for point in points | ||
] |