From 276ab5085a7b74fe4932252e4e0490007716194c Mon Sep 17 00:00:00 2001 From: Jerry Xiong <63917105+XJerrY1029@users.noreply.github.com> Date: Wed, 12 Feb 2025 07:47:52 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20main.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/embedding/functions/main.py | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/backend/embedding/functions/main.py b/backend/embedding/functions/main.py index 775381a..69146bb 100644 --- a/backend/embedding/functions/main.py +++ b/backend/embedding/functions/main.py @@ -5,30 +5,31 @@ # Create a Firestore client db = firestore.client() +# Reference the 'users' collection collectionRef = db.collection(u'users') +# Define a sample document with vector embedding doc = { - "name": "Your Document Name", - "description": "Some description about the document", - "embedding_field": Vector([0.18332680, 0.24160706, 0.3416704]) + "name": "Your Document Name", # Document name + "description": "Some description about the document", # Document description + "embedding_field": Vector([0.18332680, 0.24160706, 0.3416704]) # Vector embedding field } -# Initialize the Firebase app +# Initialize the Firebase app using a service account key cred = credentials.Certificate("path/to/your/service-account-key.json") firebase_admin.initialize_app(cred) - -# Add data to Firestore +# Add a document to Firestore doc_ref = db.collection(u'users').document(u'alovelace') doc_ref.set({ - u'first': u'Ada', - u'last': u'Lovelace', - u'born': 1815 + u'first': u'Ada', # First name + u'last': u'Lovelace', # Last name + u'born': 1815 # Birth year }) -# Read data from Firestore +# Retrieve and read the document from Firestore doc = doc_ref.get() if doc.exists: - print(f'Document data: {doc.to_dict()}') + print(f'Document data: {doc.to_dict()}') # Print document data if it exists else: - print(u'No such document!') + print(u'No such document!') # Print message if document does not exist \ No newline at end of file