Spaces:
Runtime error
Runtime error
File size: 797 Bytes
63e2f2d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
import pinecone
import numpy as np
import uuid
import os
from dotenv import load_dotenv
load_dotenv()
# Pinecone client
pc = pinecone.Pinecone(api_key=os.getenv("PINECONE_APIKEY"))
index = pc.Index("face-embeddings")
def upsert_embedding( embedding: list):
"""
Inserts or updates an embedding with a given ID in Pinecone.
"""
generate_id = str(uuid.uuid4())
index.upsert(vectors=[{
"id":generate_id,
"values": embedding
}])
return generate_id
def search_embedding(embedding: list, top_k: int = 1):
"""
Searches for similar embeddings in Pinecone and returns the top matches.
"""
results = index.query(vector=embedding, top_k=top_k, include_values=False, include_metadata=False)
return results
|