Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions backend/embedding/functions/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading