تصویر اصلی مقاله
تصویر اصلی مقاله

ساخت موتور جستجوی معنایی خود در کمتر از 50 خط کد - بدون شوخی

خیلی طولانی؛ نخواندم

CocoIndex یک ETL متن‌باز است برای تبدیل داده‌ها به داده‌های آماده هوش مصنوعی با پردازش افزایشی بی‌درنگ برای عملکرد و تأخیر کم در به‌روزرسانی‌های منبع. Qdrant یک پایگاه داده برداری متن‌باز پیشرو است که برای مدیریت بردارهای با ابعاد بالا برای عملکرد طراحی شده است. شروع به کار با کمتر از 50 خط کد پایتون.

CocoIndex رسماً از Qdrant پشتیبانی می‌کند! این ادغام، پشته RUST با کارایی بالا را با ETL بی‌درنگ برای ذخیره بردار ترکیب می‌کند:

CocoIndex یک ETL متن‌باز است برای تبدیل داده‌ها به داده‌های آماده هوش مصنوعی - با پردازش افزایشی بی‌درنگ برای عملکرد و تأخیر کم در به‌روزرسانی‌های منبع. https://github.com/cocoindex-io/cocoindex/

Qdrant یک پایگاه داده برداری متن‌باز پیشرو است که برای مدیریت بردارهای با ابعاد بالا برای عملکرد و کاربردهای هوش مصنوعی در مقیاس بزرگ طراحی شده است. https://github.com/qdrant/qdrant

صادر کردن داده‌ها به یک مجموعه Qdrant ساده است.

مشخصات فیلدهای زیر را می‌گیرد:

  • collection_name (نوع: str، مورد نیاز): نام مجموعه‌ای که داده‌ها به آن صادر می‌شوند.
  • grpc_url (نوع: str، اختیاری): آدرس gRPC نمونه Qdrant. به‌طور پیش‌فرض http://localhost:6334/ است.
  • api_key (نوع: str، اختیاری). کلید API برای احراز هویت درخواست‌ها.

قبل از صادر کردن، باید یک مجموعه با نام بردار ایجاد کنید که با نام فیلد بردار در CocoIndex مطابقت داشته باشد و در طول صادر کردن، setup_by_user=True را تنظیم کنید.


doc_embeddings.export(
    "doc_embeddings",
    cocoindex.storages.Qdrant(
        collection_name="cocoindex",
        grpc_url="https://xyz-example.cloud-region.cloud-provider.cloud.qdrant.io:6334/",
        api_key="<your-api-key-here>",
    ),
    primary_key_fields=["id_field"],
    setup_by_user=True,
)
                    

شروع به کار (با کد نمونه!) با کمتر از 50 خط کد پایتون!:

https://github.com/cocoindex-io/cocoindex/tree/main/examples/text_embedding_qdrant


@cocoindex.flow_def(name="TextEmbedding")
def text_embedding_flow(
    flow_builder: cocoindex.FlowBuilder, data_scope: cocoindex.DataScope
):
    """
    Define an example flow that embeds text into a vector database.
    """
    data_scope["documents"] = flow_builder.add_source(
        cocoindex.sources.LocalFile(path="markdown_files")
    )

    doc_embeddings = data_scope.add_collector()

    with data_scope["documents"].row() as doc:
        doc["chunks"] = doc["content"].transform(
            cocoindex.functions.SplitRecursively(),
            language="markdown",
            chunk_size=2000,
            chunk_overlap=500,
        )

        with doc["chunks"].row() as chunk:
            chunk["embedding"] = text_to_embedding(chunk["text"])
            doc_embeddings.collect(
                id=cocoindex.GeneratedField.UUID,
                filename=doc["filename"],
                location=chunk["location"],
                text=chunk["text"],
                # 'text_embedding' is the name of the vector we've created the Qdrant collection with.
                text_embedding=chunk["embedding"],
            )

    doc_embeddings.export(
        "doc_embeddings",
        cocoindex.storages.Qdrant(
            collection_name="cocoindex", grpc_url="http://localhost:6334/"
        ),
        primary_key_fields=["id"],
        setup_by_user=True,
    )
                    

ما دائماً در حال بهبود و اضافه کردن نمونه‌ها و وبلاگ‌های جدید هستیم. لطفاً برای دریافت آخرین به‌روزرسانی‌ها، یک ستاره در مخزن گیت‌هاب ما بیندازید https://github.com/cocoindex-io/cocoindex !