Skip to content

Commit

Permalink
Update app.py
Browse files Browse the repository at this point in the history
  • Loading branch information
aburhan authored Mar 4, 2024
1 parent e235892 commit 9340539
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions databases/qdrant/manifests/04-qdrant-client/app.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"))

Expand All @@ -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",
Expand All @@ -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.")
print("Please provide a query string as an argument.")
# [END qdrant_sample_app]

0 comments on commit 9340539

Please sign in to comment.