벡터 수집

Pinecone로 AI 애플리케이션 구축하기

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 애플리케이션 구축하기

벡터 수집

vectors = [
    {
        "id": "0",
        "values": [0.025525547564029694, ..., 0.0188823901116848]
    },
        ...,
    {
        "id": "9",
        "values": [0.020712468773126602, ..., 0.006418442353606224]
    },
]
Pinecone로 AI 애플리케이션 구축하기

차원 수 확인

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 애플리케이션 구축하기

벡터 업서트

  • .upsert(): 데이트 또는 삽입
index.upsert(

vectors=vectors
)
index.describe_index_stats()
{'dimension': 1536,
 'index_fullness': 0.0,
 'namespaces': {'': {'vector_count': 10}},
 'total_vector_count': 10}
Pinecone로 AI 애플리케이션 구축하기

메타데이터와 함께 벡터 수집

vectors = [
    {
        "id": "0",
        "values": [0.025525547564029694, ..., 0.0188823901116848]
        "metadata": {"genre": "productivity", "year": 2020}
    },
        ...,
]
  • 메타데이터: 데이터에 관한 데이터!
    • 메타데이터 필터링에 활용 가능 → 2장
Pinecone로 AI 애플리케이션 구축하기

메타데이터와 함께 벡터 업서트

index.upsert(
    vectors=vectors
)

다음 구조를 사용하십시오:

    {
        "id": "0",
        "values": [0.025525547564029694, ..., 0.0188823901116848]
        "metadata": {"genre": "productivity", "year": 2020}
    },
        ...,
Pinecone로 AI 애플리케이션 구축하기

연습해 봅시다!

Pinecone로 AI 애플리케이션 구축하기

Preparing Video For Download...