वेक्टर इनजेशन

Pinecone के साथ AI Applications बनाना

James Chapman

Curriculum Manager, DataCamp

इंडेक्स बनाना और कनेक्ट करना

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 के साथ AI Applications बनाना

वेक्टर इनजेस्ट करना

vectors = [
    {
        "id": "0",
        "values": [0.025525547564029694, ..., 0.0188823901116848]
    },
        ...,
    {
        "id": "9",
        "values": [0.020712468773126602, ..., 0.006418442353606224]
    },
]
Pinecone के साथ AI Applications बनाना

डायमेंशनलिटी जाँचना

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 के साथ AI Applications बनाना

वेक्टर अपसर्ट करना

  • .upsert(): Update या insert
index.upsert(

vectors=vectors
)
index.describe_index_stats()
{'dimension': 1536,
 'index_fullness': 0.0,
 'namespaces': {'': {'vector_count': 10}},
 'total_vector_count': 10}
Pinecone के साथ AI Applications बनाना

मेटाडेटा के साथ वेक्टर इनजेस्ट करना

vectors = [
    {
        "id": "0",
        "values": [0.025525547564029694, ..., 0.0188823901116848]
        "metadata": {"genre": "productivity", "year": 2020}
    },
        ...,
]
  • मेटाडेटा: डेटा के बारे में डेटा!
    • मेटाडेटा फ़िल्टरिंग में उपयोग कर सकते हैं → Chapter 2
Pinecone के साथ AI Applications बनाना

मेटाडेटा के साथ वेक्टर अपसर्ट करना

index.upsert(
    vectors=vectors
)

ध्यान रखें यह स्ट्रक्चर उपयोग करें:

    {
        "id": "0",
        "values": [0.025525547564029694, ..., 0.0188823901116848]
        "metadata": {"genre": "productivity", "year": 2020}
    },
        ...,
Pinecone के साथ AI Applications बनाना

अभ्यास करते हैं!

Pinecone के साथ AI Applications बनाना

Preparing Video For Download...