🚀 جرب Zilliz Cloud، الـ Milvus المدارة بالكامل، مجاناً — تجربة أداء أسرع بـ 10 أضعاف! جرب الآن>>

milvus-logo
LFAI
الصفحة الرئيسية
  • عمليات الدمج
  • Home
  • Docs
  • عمليات الدمج

  • تضمين النماذج

  • جينا للذكاء الاصطناعي

دمج ميلفوس مع جينا للذكاء الاصطناعي

Open In Colab GitHub Repository

يوضح هذا الدليل كيفية استخدام تضمينات جينا للذكاء الاصطناعي وميلفوس لإجراء مهام البحث عن التشابه واسترجاعه.

من هي جينا للذكاء الاصطناعي

جينا للذكاء الاصطناعي، التي تأسست في عام 2020 في برلين، هي شركة رائدة في مجال الذكاء الاصطناعي تركز على إحداث ثورة في مستقبل الذكاء الاصطناعي من خلال مؤسسة البحث الخاصة بها. تهدف شركة Jina AI، المتخصصة في الذكاء الاصطناعي متعدد الوسائط، إلى تمكين الشركات والمطورين من تسخير قوة البيانات متعددة الوسائط لخلق القيمة وتوفير التكاليف من خلال مجموعة متكاملة من المكونات، بما في ذلك التضمينات، وإعادة التضمين، والعمليات الفورية، والبنية التحتية الأساسية. تتميز تضمينات Jina AI المتطورة بأداء من الدرجة الأولى، وتتميز بنموذج بطول 8192 رمزًا رمزيًا مثاليًا لتمثيل البيانات الشاملة. ومن خلال تقديم الدعم متعدد اللغات والتكامل السلس مع منصات رائدة مثل OpenAI، تسهل هذه التضمينات التطبيقات متعددة اللغات.

تضمين ميلفوس وجينا للذكاء الاصطناعي

من أجل تخزين هذه التضمينات والبحث فيها بكفاءة من أجل السرعة والتوسع، يلزم وجود بنية تحتية محددة مصممة لهذا الغرض. Milvus عبارة عن قاعدة بيانات متجهية متقدمة مفتوحة المصدر معروفة على نطاق واسع وقادرة على التعامل مع البيانات المتجهة واسعة النطاق. تتيح Milvus إمكانية البحث السريع والدقيق عن المتجهات (التضمينات) وفقًا للكثير من المقاييس. تسمح قابليته للتوسع بالتعامل السلس مع أحجام هائلة من بيانات الصور، مما يضمن عمليات بحث عالية الأداء حتى مع نمو مجموعات البيانات.

أمثلة

تم دمج تضمينات جينا في مكتبة نماذج PyMilvus. والآن، سنقوم بعرض أمثلة برمجية لتوضيح كيفية استخدام تضمينات جينا في العمل.

قبل أن نبدأ، نحتاج إلى تثبيت مكتبة النماذج لـ PyMilvus.

$ pip install -U pymilvus
$ pip install "pymilvus[model]"

إذا كنت تستخدم Google Colab، لتمكين التبعيات المثبتة للتو، قد تحتاج إلى إعادة تشغيل وقت التشغيل. (انقر على قائمة "وقت التشغيل" في أعلى الشاشة، واختر "إعادة تشغيل الجلسة" من القائمة المنسدلة).

التضمين للأغراض العامة

يتفوق نموذج التضمين الأساسي في Jina AI في فهم النص التفصيلي، مما يجعله مثاليًا للبحث الدلالي، وبالتالي تصنيف المحتوى، وبالتالي يدعم تحليل المشاعر المتقدم، وتلخيص النصوص، وأنظمة التوصيات المخصصة.

from pymilvus.model.dense import JinaEmbeddingFunction

jina_api_key = "<YOUR_JINA_API_KEY>"
ef = JinaEmbeddingFunction(
    "jina-embeddings-v3", 
    jina_api_key,
    task="retrieval.passage",
    dimensions=1024
)

query = "what is information retrieval?"
doc = "Information retrieval is the process of finding relevant information from a large collection of data or documents."

qvecs = ef.encode_queries([query])  # This method uses `retrieval.query` as the task
dvecs = ef.encode_documents([doc])  # This method uses `retrieval.passage` as the task

التضمينات ثنائية اللغة

تعمل نماذج Jina AI ثنائية اللغة على تعزيز المنصات متعددة اللغات والدعم العالمي واكتشاف المحتوى متعدد اللغات. وهي مصممة للترجمة بين الألمانية-الإنجليزية والصينية-الإنجليزية، وتعزز التفاهم بين المجموعات اللغوية المتنوعة، مما يسهل التفاعلات بين اللغات.

from pymilvus.model.dense import JinaEmbeddingFunction

jina_api_key = "<YOUR_JINA_API_KEY>"
ef = JinaEmbeddingFunction("jina-embeddings-v2-base-de", jina_api_key)

query = "what is information retrieval?"
doc = "Information Retrieval ist der Prozess, relevante Informationen aus einer großen Sammlung von Daten oder Dokumenten zu finden."

qvecs = ef.encode_queries([query])
dvecs = ef.encode_documents([doc])

تضمين الرموز

يوفر نموذج تضمين الكود الخاص بـ Jina AI إمكانية البحث من خلال الكود والوثائق. وهو يدعم اللغة الإنجليزية و30 لغة برمجة شائعة يمكن استخدامها لتحسين التنقل في التعليمات البرمجية ومراجعة التعليمات البرمجية بشكل مبسط والمساعدة الآلية في التوثيق.

from pymilvus.model.dense import JinaEmbeddingFunction

jina_api_key = "<YOUR_JINA_API_KEY>"
ef = JinaEmbeddingFunction("jina-embeddings-v2-base-code", jina_api_key)

# Case1: Enhanced Code Navigation
# query: text description of the functionality
# document: relevant code snippet

query = "function to calculate average in Python."
doc = """
def calculate_average(numbers):
    total = sum(numbers)
    count = len(numbers)
    return total / count
"""

# Case2: Streamlined Code Review
# query: text description of the programming concept
# document: relevante code snippet or PR

query = "pull quest related to Collection"
doc = "fix:[restful v2] parameters of create collection ..."

# Case3: Automatic Documentation Assistance
# query: code snippet you need explanation
# document: relevante document or DocsString

query = "What is Collection in Milvus"
doc = """
In Milvus, you store your vector embeddings in collections. All vector embeddings within a collection share the same dimensionality and distance metric for measuring similarity.
Milvus collections support dynamic fields (i.e., fields not pre-defined in the schema) and automatic incrementation of primary keys.
"""

qvecs = ef.encode_queries([query])
dvecs = ef.encode_documents([doc])

البحث الدلالي مع جينا وميلفوس

مع وظيفة التضمين المتجه القوية، يمكننا الجمع بين التضمينات المسترجعة باستخدام نماذج Jina AI مع قاعدة بيانات Milvus Lite المتجهة لإجراء بحث دلالي.

from pymilvus.model.dense import JinaEmbeddingFunction
from pymilvus import MilvusClient

jina_api_key = "<YOUR_JINA_API_KEY>"
DIMENSION = 1024  # `jina-embeddings-v3` supports flexible embedding sizes (32, 64, 128, 256, 512, 768, 1024), allowing for truncating embeddings to fit your application. 
ef = JinaEmbeddingFunction(
    "jina-embeddings-v3", 
    jina_api_key,
    task="retrieval.passage",
    dimensions=DIMENSION,
)


doc = [
    "In 1950, Alan Turing published his seminal paper, 'Computing Machinery and Intelligence,' proposing the Turing Test as a criterion of intelligence, a foundational concept in the philosophy and development of artificial intelligence.",
    "The Dartmouth Conference in 1956 is considered the birthplace of artificial intelligence as a field; here, John McCarthy and others coined the term 'artificial intelligence' and laid out its basic goals.",
    "In 1951, British mathematician and computer scientist Alan Turing also developed the first program designed to play chess, demonstrating an early example of AI in game strategy.",
    "The invention of the Logic Theorist by Allen Newell, Herbert A. Simon, and Cliff Shaw in 1955 marked the creation of the first true AI program, which was capable of solving logic problems, akin to proving mathematical theorems.",
]

dvecs = ef.encode_documents(doc) # This method uses `retrieval.passage` as the task

data = [
    {"id": i, "vector": dvecs[i], "text": doc[i], "subject": "history"}
    for i in range(len(dvecs))
]

milvus_client = MilvusClient("./milvus_jina_demo.db")
COLLECTION_NAME = "demo_collection"  # Milvus collection name
if milvus_client.has_collection(collection_name=COLLECTION_NAME):
    milvus_client.drop_collection(collection_name=COLLECTION_NAME)
milvus_client.create_collection(collection_name=COLLECTION_NAME, dimension=DIMENSION)

res = milvus_client.insert(collection_name=COLLECTION_NAME, data=data)

print(res["insert_count"])

أما بالنسبة لحجة MilvusClient:

  • يعد تعيين uri كملف محلي، على سبيل المثال./milvus.db ، هو الطريقة الأكثر ملاءمة، حيث يستخدم تلقائيًا ملف Milvus Lite لتخزين جميع البيانات في هذا الملف.
  • إذا كان لديك حجم كبير من البيانات، يمكنك إعداد خادم Milvus أكثر أداءً على docker أو kubernetes. في هذا الإعداد، يُرجى استخدام الخادم uri، على سبيل المثالhttp://localhost:19530 ، كـ uri.
  • إذا كنت ترغب في استخدام Zilliz Cloud، الخدمة السحابية المدارة بالكامل لـ Milvus، اضبط uri و token ، والتي تتوافق مع نقطة النهاية العامة ومفتاح Api في Zilliz Cloud.

مع وجود جميع البيانات في قاعدة بيانات Milvus vector، يمكننا الآن إجراء بحث دلالي من خلال إنشاء تضمين متجه للاستعلام وإجراء بحث متجه.

queries = "What event in 1956 marked the official birth of artificial intelligence as a discipline?"
qvecs = ef.encode_queries([queries]) # This method uses `retrieval.query` as the task

res = milvus_client.search(
    collection_name=COLLECTION_NAME,  # target collection
    data=[qvecs[0]],  # query vectors
    limit=3,  # number of returned entities
    output_fields=["text", "subject"],  # specifies fields to be returned
)[0]

for result in res:
    print(result)
{'id': 1, 'distance': 0.8802614808082581, 'entity': {'text': "The Dartmouth Conference in 1956 is considered the birthplace of artificial intelligence as a field; here, John McCarthy and others coined the term 'artificial intelligence' and laid out its basic goals.", 'subject': 'history'}}

إعادة تصنيف جينا

يوفر Jina Ai أيضًا أداة إعادة التصنيف لتعزيز جودة الاسترجاع بعد البحث باستخدام التضمينات.

from pymilvus.model.reranker import JinaRerankFunction

jina_api_key = "<YOUR_JINA_API_KEY>"

rf = JinaRerankFunction("jina-reranker-v1-base-en", jina_api_key)

query = "What event in 1956 marked the official birth of artificial intelligence as a discipline?"

documents = [
    "In 1950, Alan Turing published his seminal paper, 'Computing Machinery and Intelligence,' proposing the Turing Test as a criterion of intelligence, a foundational concept in the philosophy and development of artificial intelligence.",
    "The Dartmouth Conference in 1956 is considered the birthplace of artificial intelligence as a field; here, John McCarthy and others coined the term 'artificial intelligence' and laid out its basic goals.",
    "In 1951, British mathematician and computer scientist Alan Turing also developed the first program designed to play chess, demonstrating an early example of AI in game strategy.",
    "The invention of the Logic Theorist by Allen Newell, Herbert A. Simon, and Cliff Shaw in 1955 marked the creation of the first true AI program, which was capable of solving logic problems, akin to proving mathematical theorems.",
]

rf(query, documents)
[RerankResult(text="The Dartmouth Conference in 1956 is considered the birthplace of artificial intelligence as a field; here, John McCarthy and others coined the term 'artificial intelligence' and laid out its basic goals.", score=0.9370958209037781, index=1),
 RerankResult(text='The invention of the Logic Theorist by Allen Newell, Herbert A. Simon, and Cliff Shaw in 1955 marked the creation of the first true AI program, which was capable of solving logic problems, akin to proving mathematical theorems.', score=0.35420963168144226, index=3),
 RerankResult(text="In 1950, Alan Turing published his seminal paper, 'Computing Machinery and Intelligence,' proposing the Turing Test as a criterion of intelligence, a foundational concept in the philosophy and development of artificial intelligence.", score=0.3498658835887909, index=0),
 RerankResult(text='In 1951, British mathematician and computer scientist Alan Turing also developed the first program designed to play chess, demonstrating an early example of AI in game strategy.', score=0.2728956639766693, index=2)]

جرب Managed Milvus مجاناً

Zilliz Cloud خالي من المتاعب، ويعمل بواسطة Milvus ويعمل بسرعة 10 أضعاف.

ابدأ
التعليقات

هل كانت هذه الصفحة مفيدة؟