استخدام وحدات Weaviate
استكشفوا منظومة وحدات Weaviate الواسعة وادمجوها لتوفير وظائف مثل الإجابة عن الأسئلة والتلخيص وغير ذلك.
استخدام وحدات Weaviate درس مجاني في Vector Databases: Pinecone, Weaviate & pgvector على CoddyKit. هذا هو الدرس 2 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Vector Databases: Pinecone, Weaviate & pgvector، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Vector Databases: Pinecone, Weaviate & pgvector 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
Weaviate Modules Introduction
Weaviate's power comes from its flexible architecture, which can be extended using modules. These modules add specialized functionalities directly to your Weaviate instance.
Think of them as plugins that enhance Weaviate's core capabilities. They can handle tasks like generating embeddings, performing Q&A, or even processing images.
Why Use Weaviate Modules?
Modules streamline your data pipeline by integrating advanced AI functionalities directly into your vector database. This means:
- Automatic Vectorization: Weaviate can create embeddings for you.
- Enhanced Search: Add capabilities like Q&A or summarization to queries.
- Simplified Development: Less external code needed for common AI tasks.
- Multi-modal Support: Handle various data types like text and images.
Types of Modules
Weaviate offers a rich ecosystem of modules, typically categorized by their function:
- Text2Vec: Generate vector embeddings from text (e.g.,
text2vec-openai,text2vec-huggingface). - Generative: Add Large Language Model (LLM) capabilities for Q&A, summarization (e.g.,
generative-openai,generative-cohere). - Multi-modal: Process different data types like images (e.g.,
img2vec-clip). - Rerank: Improve search relevance by reordering results.
Enabling Modules for Use
Before you can use a module, it must be enabled in your Weaviate instance. This is typically done during setup (e.g., via Docker Compose) or when using Weaviate Cloud.
When you initialize your client, you often specify the modules you intend to use. For example, to use text2vec-openai and generative-openai, you'd configure your client accordingly.
Text2Vec: Auto-Vectorization
The text2vec modules are fundamental for automatically creating vector embeddings. When you define a class schema, you specify which vectorizer to use.
Weaviate then takes care of calling the embedding model for you whenever new data is imported, turning your text into searchable vectors.
Code: Schema with Text2Vec Module
Here's how to define a schema that uses the text2vec-openai module to automatically vectorize the description property of a 'Article' class:
import weaviate
import os
# NOTE: Replace with your Weaviate URL and API key
# and OpenAI API key if using text2vec-openai
# client = weaviate.Client(
# url="YOUR_WEAVIATE_URL",
# auth_client_secret=weaviate.AuthApiKey(api_key="YOUR_WEAVIATE_API_KEY"),
# headers={
# "X-OpenAI-Api-Key": os.environ.get("OPENAI_API_KEY") # Or your key
# }
# )
# For demonstration, we'll just show the schema
# and assume client is configured.
class_obj = {
"class": "Article",
"vectorizer": "text2vec-openai", # Enable vectorization
"moduleConfig": {
"text2vec-openai": {
"model": "ada",
"modelVersion": "002",
"type": "text"
}
},
"properties": [
{
"name": "title",
"dataType": ["text"]
},
{
"name": "description",
"dataType": ["text"]
}
]
}
# client.schema.create_class(class_obj)
print("Schema definition for Article class:")
print(class_obj)
# This code isn't runnable as is without a Weaviate instance and API keys
# but demonstrates the schema structure.
Generative Modules for LLMs
Generative modules (like generative-openai) allow you to integrate Large Language Models (LLMs) directly into your Weaviate queries. This enables powerful features such as:
- Q&A: Ask questions about your retrieved data.
- Summarization: Get summaries of search results.
- Extraction: Pull specific information from context.
You use these modules via the _additional { generate { ... } } GraphQL syntax in your queries.
Code: Query with Generative Module
Here's a conceptual example of how to use a generative module to get an answer to a question based on retrieved data. Assume a 'Question' class exists with relevant data.
import weaviate
import os
# NOTE: Replace with your Weaviate URL and API key
# client = weaviate.Client(
# url="YOUR_WEAVIATE_URL",
# auth_client_secret=weaviate.AuthApiKey(api_key="YOUR_WEAVIATE_API_KEY"),
# headers={
# "X-OpenAI-Api-Key": os.environ.get("OPENAI_API_KEY") # Or your key
# }
# )
# For demonstration, we'll just show the query structure.
# query_result = client.query
# .get("Question", ["question", "answer"])
# .with_generate(single_prompt="What is the main topic of these questions?")
# .with_limit(2)
# .do()
print("Conceptual query using generative module:")
print("client.query.get(\"Question\", [\"question\"]).with_generate(...)")
print("This would ask an LLM to summarize or answer based on results.")
# This code is illustrative and not runnable without a Weaviate instance,
# data, and API keys.Multi-modal & Advanced Modules
Beyond text, Weaviate supports multi-modal modules like img2vec-clip, which can generate embeddings for images. This allows you to perform similarity searches on visual data.
Other advanced modules include those for reranking search results (e.g., rerank-transformers) to boost relevance, ensuring users see the most pertinent information first.
Module Best Practices
When using Weaviate modules, consider these best practices:
- Choose Wisely: Select modules that align with your specific application needs (e.g., OpenAI for general text, Hugging Face for specialized models).
- Monitor Costs: Many modules rely on external APIs (like OpenAI), which incur costs. Monitor usage and set limits.
- Version Control: Keep track of module versions as they can impact embedding quality or generative output.
- Security: Protect your API keys and ensure proper access control to your Weaviate instance.
Module Capabilities Check
Which of the following are primary benefits of using Weaviate modules?
Recap & Next Steps
In this lesson, we explored Weaviate's powerful module ecosystem. We learned that modules extend Weaviate's capabilities for tasks like automatic vectorization (text2vec), generative AI (generative), and multi-modal data handling (img2vec).
By integrating these modules, you can build more sophisticated and efficient AI applications directly on top of your Weaviate instance. Understanding how to enable and configure them is key to unlocking advanced functionalities.
الأسئلة الشائعة
هل درس «استخدام وحدات Weaviate» مجاني؟
نعم — نص درس «استخدام وحدات Weaviate» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Vector Databases: Pinecone, Weaviate & pgvector، انتقل إلى CoddyKit PRO. تتضمن دورة Vector Databases: Pinecone, Weaviate & pgvector 4 دروس في المجموع.
ماذا ستتعلم في «استخدام وحدات Weaviate»؟
استكشفوا منظومة وحدات Weaviate الواسعة وادمجوها لتوفير وظائف مثل الإجابة عن الأسئلة والتلخيص وغير ذلك. تتمرن على Vector Databases: Pinecone, Weaviate & pgvector مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ Vector Databases: Pinecone, Weaviate & pgvector؟
لا تُشترط خبرة سابقة. Vector Databases: Pinecone, Weaviate & pgvector على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 2 من أصل 4.
كم من الوقت يستغرق درس «استخدام وحدات Weaviate»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس Vector Databases: Pinecone, Weaviate & pgvector هذا؟
نعم. كل درس في Vector Databases: Pinecone, Weaviate & pgvector يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- البحث الدلالي والبحث الهجين
- استخدام وحدات Weaviate
- استراتيجيات النسخ الاحتياطي والاستعادة
- تعدد المستأجرين في Weaviate