Vektör alma

Pinecone ile Vektör Veritabanları ve Embeddings

James Chapman

Curriculum Manager, DataCamp

Dizin oluşturma ve bağlanma

pc = Pinecone(api_key="API_KEY")

pc.create_index(
    name='datacamp-index',
    dimension=1536,
    spec=ServerlessSpec(
        cloud='aws', 
        region='us-east-1'
    )
)

index = pc.Index('datacamp-index')
Pinecone ile Vektör Veritabanları ve Embeddings

Vektör alma

vectors = [
    {
        "id": "0",
        "values": [0.025525547564029694, ..., 0.0188823901116848]
    },
        ...,
    {
        "id": "9",
        "values": [0.020712468773126602, ..., 0.006418442353606224]
    },
]
Pinecone ile Vektör Veritabanları ve Embeddings

Boyutsallığı kontrol etme

vector_dims = [len(vector['values']) == 1536 for vector in vectors]

all(vector_dims)
True
PineconeApiException: (400)
Reason: Bad Request
HTTP response headers: HTTPHeaderDict({'Date': 'Fri, 17 May 2024 10:54:57 GMT', ...
HTTP response body: {"code":3,"message":"Vector dimension 256 does not match the
dimension of the index 1536","details":[]}
Pinecone ile Vektör Veritabanları ve Embeddings

Vektörleri upsert etme

  • .upsert(): güncelle veya ekle
index.upsert(

vectors=vectors
)
index.describe_index_stats()
{'dimension': 1536,
 'index_fullness': 0.0,
 'namespaces': {'': {'vector_count': 10}},
 'total_vector_count': 10}
Pinecone ile Vektör Veritabanları ve Embeddings

Metadata ile vektör alma

vectors = [
    {
        "id": "0",
        "values": [0.025525547564029694, ..., 0.0188823901116848]
        "metadata": {"genre": "productivity", "year": 2020}
    },
        ...,
]
  • Metadata: verinin verisi
    • Metadata filtering için kullanılabilir → Bölüm 2
Pinecone ile Vektör Veritabanları ve Embeddings

Vektörleri metadata ile upsert etme

index.upsert(
    vectors=vectors
)

Unutmayın, yapı şöyle olmalı:

    {
        "id": "0",
        "values": [0.025525547564029694, ..., 0.0188823901116848]
        "metadata": {"genre": "productivity", "year": 2020}
    },
        ...,
Pinecone ile Vektör Veritabanları ve Embeddings

Haydi pratik yapalım!

Pinecone ile Vektör Veritabanları ve Embeddings

Preparing Video For Download...