From 4c74c1a8370dd844af0d851f72aac1bfcfb755ac Mon Sep 17 00:00:00 2001 From: Ameenah Burhan Date: Thu, 29 Feb 2024 11:15:37 -0500 Subject: [PATCH 1/6] Update ha-app.yaml --- databases/qdrant/manifests/01-regional-pd/ha-app.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/databases/qdrant/manifests/01-regional-pd/ha-app.yaml b/databases/qdrant/manifests/01-regional-pd/ha-app.yaml index d72fef60e1..0dd41f8e1b 100644 --- a/databases/qdrant/manifests/01-regional-pd/ha-app.yaml +++ b/databases/qdrant/manifests/01-regional-pd/ha-app.yaml @@ -24,7 +24,7 @@ spec: resourceKind: StatefulSet selector: matchLabels: - app.kubernetes.io/instance=qdrant-database + app.kubernetes.io/instance:"qdrant-database" policy: storageSettings: requireRegionalStorage: true From d944c6c9d47e742b7649e033ac4b0f46ed90afb1 Mon Sep 17 00:00:00 2001 From: Ameenah Burhan Date: Thu, 29 Feb 2024 11:15:50 -0500 Subject: [PATCH 2/6] Update ha-app.yaml --- databases/qdrant/manifests/01-regional-pd/ha-app.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/databases/qdrant/manifests/01-regional-pd/ha-app.yaml b/databases/qdrant/manifests/01-regional-pd/ha-app.yaml index 0dd41f8e1b..47fb778d37 100644 --- a/databases/qdrant/manifests/01-regional-pd/ha-app.yaml +++ b/databases/qdrant/manifests/01-regional-pd/ha-app.yaml @@ -24,7 +24,7 @@ spec: resourceKind: StatefulSet selector: matchLabels: - app.kubernetes.io/instance:"qdrant-database" + app.kubernetes.io/instance: "qdrant-database" policy: storageSettings: requireRegionalStorage: true From ee5a31d8fc66846f18beb44378f2bb0ef071a773 Mon Sep 17 00:00:00 2001 From: aburhan Date: Mon, 4 Mar 2024 17:04:13 +0000 Subject: [PATCH 3/6] add python scripts --- .../qdrant/manifests/04-qdrant-client/app.py | 51 +++++++++++++++++++ .../04-qdrant-client/client-pod.yaml | 5 ++ 2 files changed, 56 insertions(+) create mode 100644 databases/qdrant/manifests/04-qdrant-client/app.py diff --git a/databases/qdrant/manifests/04-qdrant-client/app.py b/databases/qdrant/manifests/04-qdrant-client/app.py new file mode 100644 index 0000000000..4ba584e862 --- /dev/null +++ b/databases/qdrant/manifests/04-qdrant-client/app.py @@ -0,0 +1,51 @@ +from qdrant_client import QdrantClient +from qdrant_client.http import models +import os +import sys +import csv + + +def main(query_string): + # Connect to Qdrant + qdrant = QdrantClient( + url="http://qdrant-database:6333", api_key=os.getenv("APIKEY")) + + # Create a collection + books = [*csv.DictReader(open('/usr/local/dataset/dataset.csv'))] + + documents: list[dict[str, any]] = [] + metadata: list[dict[str, any]] = [] + ids: list[int] = [] + + for idx, doc in enumerate(books): + ids.append(idx) + documents.append(doc["description"]) + metadata.append( + { + "title": doc["title"], + "author": doc["author"], + "publishDate": doc["publishDate"], + } + ) + + # Add my_books to the collection + qdrant.add(collection_name="my_books", documents=documents, metadata=metadata, ids=ids, parallel=2) + + # Query the collection + results = qdrant.query( + collection_name="my_books", + query_text=query_string, + limit=2, + ) + for result in results: + print("Title:", result.metadata["title"], "\nAuthor:", result.metadata["author"]) + print("Description:", result.metadata["document"], "Published:", result.metadata["publishDate"], "\nScore:", result.score) + print("-----") + +if __name__ == "__main__": + if len(sys.argv) > 1: + query_string = " ".join(sys.argv[1:]) + print("Querying qdrant for: ", query_string) + main(query_string) + else: + print("Please provide a query string as an argument.") \ No newline at end of file diff --git a/databases/qdrant/manifests/04-qdrant-client/client-pod.yaml b/databases/qdrant/manifests/04-qdrant-client/client-pod.yaml index 3cf7538641..485c1d51b9 100644 --- a/databases/qdrant/manifests/04-qdrant-client/client-pod.yaml +++ b/databases/qdrant/manifests/04-qdrant-client/client-pod.yaml @@ -41,8 +41,13 @@ spec: volumeMounts: - name: books-dataset mountPath: /usr/local/dataset + - name: script-volume + mountPath: /usr/local/script volumes: - name: books-dataset configMap: name: books-dataset + - name: script-volume + configMap: + name: demo-app # [END gke_databases_qdrant_04_client_pod] From 93405392d9c8a99754f65d210a2262edeb9bf115 Mon Sep 17 00:00:00 2001 From: Ameenah Burhan Date: Mon, 4 Mar 2024 12:19:25 -0500 Subject: [PATCH 4/6] Update app.py --- .../qdrant/manifests/04-qdrant-client/app.py | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/databases/qdrant/manifests/04-qdrant-client/app.py b/databases/qdrant/manifests/04-qdrant-client/app.py index 4ba584e862..95449a1075 100644 --- a/databases/qdrant/manifests/04-qdrant-client/app.py +++ b/databases/qdrant/manifests/04-qdrant-client/app.py @@ -1,3 +1,18 @@ +# Copyright 2024 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# [START qdrant_sample_app] from qdrant_client import QdrantClient from qdrant_client.http import models import os @@ -6,7 +21,7 @@ def main(query_string): - # Connect to Qdrant +# [START qdrant_create_collection] qdrant = QdrantClient( url="http://qdrant-database:6333", api_key=os.getenv("APIKEY")) @@ -30,7 +45,8 @@ def main(query_string): # Add my_books to the collection qdrant.add(collection_name="my_books", documents=documents, metadata=metadata, ids=ids, parallel=2) - +# [END qdrant_create_collection] +# [START qdrant_query_collection] # Query the collection results = qdrant.query( collection_name="my_books", @@ -41,11 +57,12 @@ def main(query_string): print("Title:", result.metadata["title"], "\nAuthor:", result.metadata["author"]) print("Description:", result.metadata["document"], "Published:", result.metadata["publishDate"], "\nScore:", result.score) print("-----") - +# [END qdrant_query_collection] if __name__ == "__main__": if len(sys.argv) > 1: query_string = " ".join(sys.argv[1:]) print("Querying qdrant for: ", query_string) main(query_string) else: - print("Please provide a query string as an argument.") \ No newline at end of file + print("Please provide a query string as an argument.") +# [END qdrant_sample_app] From 0df0c7f5941b06382f298270b664cd41f0859d68 Mon Sep 17 00:00:00 2001 From: Ameenah Burhan Date: Mon, 4 Mar 2024 12:41:23 -0500 Subject: [PATCH 5/6] Update app.py --- databases/qdrant/manifests/04-qdrant-client/app.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/databases/qdrant/manifests/04-qdrant-client/app.py b/databases/qdrant/manifests/04-qdrant-client/app.py index 95449a1075..5932deacb8 100644 --- a/databases/qdrant/manifests/04-qdrant-client/app.py +++ b/databases/qdrant/manifests/04-qdrant-client/app.py @@ -19,9 +19,8 @@ import sys import csv - def main(query_string): -# [START qdrant_create_collection] + qdrant = QdrantClient( url="http://qdrant-database:6333", api_key=os.getenv("APIKEY")) @@ -45,8 +44,7 @@ def main(query_string): # Add my_books to the collection qdrant.add(collection_name="my_books", documents=documents, metadata=metadata, ids=ids, parallel=2) -# [END qdrant_create_collection] -# [START qdrant_query_collection] + # Query the collection results = qdrant.query( collection_name="my_books", @@ -57,7 +55,7 @@ def main(query_string): print("Title:", result.metadata["title"], "\nAuthor:", result.metadata["author"]) print("Description:", result.metadata["document"], "Published:", result.metadata["publishDate"], "\nScore:", result.score) print("-----") -# [END qdrant_query_collection] + if __name__ == "__main__": if len(sys.argv) > 1: query_string = " ".join(sys.argv[1:]) From d4462a9407ea29fb61ae7ad43f0802068976b19f Mon Sep 17 00:00:00 2001 From: Ameenah Burhan Date: Mon, 4 Mar 2024 13:17:18 -0500 Subject: [PATCH 6/6] Update app.py --- databases/qdrant/manifests/04-qdrant-client/app.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/databases/qdrant/manifests/04-qdrant-client/app.py b/databases/qdrant/manifests/04-qdrant-client/app.py index 5932deacb8..904c472a74 100644 --- a/databases/qdrant/manifests/04-qdrant-client/app.py +++ b/databases/qdrant/manifests/04-qdrant-client/app.py @@ -12,7 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -# [START qdrant_sample_app] from qdrant_client import QdrantClient from qdrant_client.http import models import os @@ -63,4 +62,3 @@ def main(query_string): main(query_string) else: print("Please provide a query string as an argument.") -# [END qdrant_sample_app]