OpenAI API ile Embeddings’e Giriş
Emmanuel Pire
Senior Software Engineer, DataCamp


from chromadb.utils.embedding_functions import OpenAIEmbeddingFunction
collection = client.get_collection(
name="netflix_titles",
embedding_function=OpenAIEmbeddingFunction(api_key="...")
)
result = collection.query(
query_texts=["movies where people sing a lot"],
n_results=3
)
print(result)
{'ids': [['s4068', 's293', 's2213']],
'embeddings': None,
'documents': [['Title: Quién te cantará (Movie)\nDescription: When a near-...',
'Title: Quartet (Movie)\nDescription: To save their posh retirement home, ...',
'Title: Sing On! Spain (TV Show)\nDescription: In this fast-paced, high-...']],
'metadatas': [[None, None, None]],
'distances': [[0.350419282913208, 0.36049118638038635, 0.37080681324005127]]
query() birden çok anahtarlı bir sözlük döndürür:
ids: Dönen öğelerin kimlikleriembeddings: Dönen öğelerin gömlemeleridocuments: Dönen öğelerin kaynak metinlerimetadatas: Dönen öğelerin üst verileridistances: Dönen öğelerin sorgu metnine uzaklıkları{'ids': [...],
'embeddings': None,
'documents': [...],
'metadatas': [...],
'distances': [...]}


collection.update(
ids=["id-1", "id-2"],
documents=["New document 1", "New document 2"]
)
collection.upsert(
ids=["id-1", "id-2"],
documents=["New document 1", "New document 2"]
)
Bir koleksiyondan öğe silme
collection.delete(ids=["id-1", "id-2"])
Tüm koleksiyonları ve öğeleri silme
client.reset()
OpenAI API ile Embeddings’e Giriş