0Pricing
Vector Databases: Pinecone, Weaviate & pgvector · บทเรียน

การจัดเก็บและอัปเดตเวกเตอร์ฝังตัว

ทำความเข้าใจแนวปฏิบัติที่ดีที่สุดสำหรับจัดเก็บ สร้างดัชนี และอัปเดตเวกเตอร์ฝังตัวอย่างมีประสิทธิภาพในกระบวนการข้อมูลของคุณ

การจัดเก็บและอัปเดตเวกเตอร์ฝังตัว เป็นบทเรียน Vector Databases: Pinecone, Weaviate & pgvector ฟรีบน CoddyKit นี่คือบทเรียนที่ 3 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Vector Databases: Pinecone, Weaviate & pgvector และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Vector Databases: Pinecone, Weaviate & pgvector มีบทเรียนทั้งหมด 4 บทเรียน

บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ

Storing & Updating Embeddings

Welcome to Lesson 3! This lesson covers the essential practices for managing embeddings: how to store them effectively, the role of indexing for search performance, and strategies for updating embeddings to keep your data fresh.

These concepts are crucial for building dynamic and responsive AI applications.

Why Persist Embeddings?

Generating embeddings can be computationally intensive and time-consuming. Storing them after creation offers significant benefits:

  • Reuse: Avoid re-computing the same embedding for multiple queries.
  • Speed: Enable much faster similarity searches.
  • Scale: Support larger applications without constant re-generation.

Think of it as caching the 'meaning' of your data for quick access.

Choosing an Embedding Store

Where should you keep your embeddings? While simple options exist, specialized solutions are usually best:

  • Vector Databases: Designed specifically for storing and searching vector embeddings (e.g., Pinecone, Weaviate). They offer optimal performance.
  • Relational DBs (with extensions): Traditional databases like PostgreSQL can store vectors using extensions like pgvector.
  • File Systems: Simple for very small or static datasets, but not practical for scalable search.

For most AI applications, a vector database is the preferred choice.

Structure of Stored Data

When you store an embedding, you typically store more than just the raw vector. A complete entry usually includes:

  • Vector: The numerical array representing your data (e.g., [0.1, 0.2, ...]).
  • ID: A unique identifier that links the embedding back to its original data source (e.g., a document ID, image hash).
  • Metadata: Additional descriptive information about the original data (e.g., title, author, category). This is invaluable for filtering and enriching search results.

Simulating Embedding Storage

Here's a simple Python example demonstrating how you might conceptually store an embedding with its ID and metadata. In a real-world scenario, a vector database would handle this more robustly.

def main():
    # Simulate an embedding store (a list of dictionaries)
    embedding_store = []

    # Example data for a document
    doc_id = "doc_abc_123"
    doc_embedding = [0.1, 0.2, 0.3, 0.4, 0.5] # Simplified vector
    doc_metadata = {"title": "Intro to Vectors", "author": "Alice"}

    # Create an entry for the embedding
    embedding_entry = {
        "id": doc_id,
        "vector": doc_embedding,
        "metadata": doc_metadata
    }

    # Add the entry to our simulated store
    embedding_store.append(embedding_entry)

    print(f"Stored entry for ID: {embedding_entry['id']}")
    print(f"Vector: {embedding_entry['vector']}")
    print(f"Metadata: {embedding_entry['metadata']}")

if __name__ == "__main__":
    main()

Introduction to Indexing

Once embeddings are stored, they need to be organized in a way that allows for fast similarity searches. This organization process is called indexing.

Unlike traditional database indexes for exact matches, vector indexes are designed to speed up Approximate Nearest Neighbor (ANN) searches. This means finding vectors that are 'close enough' to a query vector very quickly, even if it's not the absolute closest every single time.

Indexing Trade-offs

When designing or choosing an indexing strategy for embeddings, there are important trade-offs:

  • Speed: How quickly can similarity queries be processed?
  • Accuracy (Recall): How many of the true nearest neighbors are actually found by the index?
  • Memory Usage: How much memory or disk space does the index itself consume?

Often, a slight reduction in accuracy is accepted to gain significant improvements in search speed and memory efficiency, especially with very large datasets.

The Challenge of Updates

Data in real-world applications is rarely static. Documents are edited, images are replaced, and user profiles are updated. When the original data changes, its corresponding embedding also needs to be updated to reflect the new content.

Failing to update embeddings can lead to outdated or inaccurate search results, making your AI application less effective.

Strategies for Updating Embeddings

There are two primary approaches to handling embedding updates:

  • Full Re-indexing (Batch Updates): Regenerate all embeddings from scratch and completely rebuild the entire vector index. This is simple but very resource-intensive for large datasets.
  • Partial Updates (Upserts): Modify or insert specific vectors without rebuilding the whole index. Most vector databases support this operation, often called 'upsert' (update if exists, otherwise insert). This is much more efficient for dynamic data.

Simulating an Embedding Update

Here's how you might conceptually update an embedding in our simulated store. A real vector database would provide an optimized 'upsert' command to handle this efficiently.

def main():
    # Simulate an embedding store with an existing entry
    embedding_store = [
        {
            "id": "doc_abc_123",
            "vector": [0.1, 0.2, 0.3, 0.4, 0.5],
            "metadata": {"title": "Intro to Vectors", "author": "Alice"}
        }
    ]

    # New embedding data for an existing ID
    updated_doc_id = "doc_abc_123"
    new_embedding_vector = [0.6, 0.7, 0.8, 0.9, 1.0] # The new vector
    new_metadata = {"title": "Intro to Vectors (Revised)", "author": "Alice"}

    # Find and update the entry in our store
    found = False
    for entry in embedding_store:
        if entry["id"] == updated_doc_id:
            entry["vector"] = new_embedding_vector
            entry["metadata"] = new_metadata
            found = True
            break

    if found:
        print(f"Updated entry for ID: {updated_doc_id}")
        print(f"New vector: {embedding_store[0]['vector']}")
        print(f"New metadata: {embedding_store[0]['metadata']}")
    else:
        print(f"ID {updated_doc_id} not found for update.")

if __name__ == "__main__":
    main()

Understanding Updates

Imagine you have a document stored in your vector database. The document's content is updated, meaning its embedding needs to change. Which term describes the most efficient way to replace an existing embedding with a new one in most modern vector databases?

Recap: Storing & Updating

In this lesson, we covered the essential aspects of managing embeddings:

  • Storing: Persisting embeddings with IDs and metadata for reuse and speed.
  • Indexing: Organizing embeddings for efficient Approximate Nearest Neighbor (ANN) search.
  • Updating: Strategies like 'upsert' to keep embeddings fresh when source data changes.

Mastering these practices is key to building robust and performant vector-search applications.

คำถามที่พบบ่อย

บทเรียน “การจัดเก็บและอัปเดตเวกเตอร์ฝังตัว” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “การจัดเก็บและอัปเดตเวกเตอร์ฝังตัว” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Vector Databases: Pinecone, Weaviate & pgvector ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Vector Databases: Pinecone, Weaviate & pgvector มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “การจัดเก็บและอัปเดตเวกเตอร์ฝังตัว”

ทำความเข้าใจแนวปฏิบัติที่ดีที่สุดสำหรับจัดเก็บ สร้างดัชนี และอัปเดตเวกเตอร์ฝังตัวอย่างมีประสิทธิภาพในกระบวนการข้อมูลของคุณ คุณปฏิบัติ Vector Databases: Pinecone, Weaviate & pgvector ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Vector Databases: Pinecone, Weaviate & pgvector หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน Vector Databases: Pinecone, Weaviate & pgvector บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 3 จากทั้งหมด 4 บทเรียน

บทเรียน “การจัดเก็บและอัปเดตเวกเตอร์ฝังตัว” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน Vector Databases: Pinecone, Weaviate & pgvector นี้ได้ไหม

ได้ บทเรียน Vector Databases: Pinecone, Weaviate & pgvector ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. โมเดลเวกเตอร์ฝังตัวข้อความ
  2. การใช้เอพีไอสำหรับเวกเตอร์ฝังตัว
  3. การจัดเก็บและอัปเดตเวกเตอร์ฝังตัว
  4. แบ่งข้อความเป็นส่วนเพื่อสร้างเวกเตอร์ฝังที่ดียิ่งขึ้น
← กลับไปที่ Vector Databases: Pinecone, Weaviate & pgvector