Konversationssuche mit OCI Generative AI

Führen Sie die Schritte in dieser Schritt-für-Schritt-Anleitung aus, um eine End-to-End-Pipeline für Retrieval-Augmented Generation (RAG) in OCI Search mit OpenSearch mit einem OCI Generative AI-Connector einzurichten und zu verwenden.

Sie können den Connector nutzen, um Zugriff auf alle generativen KI-Features wie Retrieval-Augmented Generation (RAG), Textzusammenfassung, Textgenerierung, Konversationssuche und semantische Suche zu erhalten.

Die folgenden Schritte sind zum Erstellen eines Konnektors für generative KI erforderlich:

Zusätzlich zu diesen grundlegenden Schritten wird dieses Thema mit den Schritten fortgesetzt, die zum Einrichten und Verwenden einer End-to-End-Pipeline für Retrieval-Augmented Generation (RAG) in OCI Search mit OpenSearch mit einem OCI Generative AI-Connector erforderlich sind. Jeder Schritt enthält eine generische Vorlage des erforderlichen Codes. Mit der Konsole können Sie diesen Code automatisch mit Werten generieren, die für Ihre Umgebung konfiguriert sind. Informationen hierzu finden Sie unter RAG-Pipeline für die Suche mit OpenSearch erstellen.

Der Connector verwendet das Cohere-Einbettungsmodell, das von generativer KI gehostet wird. Generative KI unterstützt auch das Llma2-Modell, mit dem Sie experimentieren können.

Voraussetzungen

  • Um OCI Generative AI verwenden zu können, muss der Mandant die Region "US Midwest (Chicago)" oder die Region "Germany Central (Frankfurt)" abonniert haben. Sie müssen das Cluster nicht in einer dieser Regionen erstellen. Stellen Sie sicher, dass der Mandant eine der Regionen abonniert hat.
  • Um einen OCI Generative AI-Connector mit OCI Search mit OpenSearch zu verwenden, benötigen Sie ein Cluster, das für die Verwendung von OpenSearch Version 2.11 konfiguriert ist. Standardmäßig sind neue Cluster für die Verwendung von Version 2.11 konfiguriert. Informationen zum Erstellen eines Clusters finden Sie unter OpenSearch-Cluster erstellen.

    Für vorhandene Cluster, die für Version 2.3 konfiguriert sind, können Sie ein Inlineupgrade auf Version 2.11 ausführen. Weitere Informationen finden Sie unter OpenSearch Cluster-Softwareupgrades.

    Um ein Upgrade vorhandener Cluster auszuführen, die für Version 1.2.3 auf 2.11 konfiguriert sind, müssen Sie den unter OpenSearch Clustersoftwareupgrades beschriebenen Upgradeprozess verwenden.

  • Erstellen Sie eine Policy, um Zugriff auf generative KI-Ressourcen zu erteilen. Das folgende Policy-Beispiel enthält die erforderlichen Berechtigungen:
    ALLOW ANY-USER to manage generative-ai-family in tenancy WHERE ALL {request.principal.type='opensearchcluster', request.resource.compartment.id='<cluster_compartment_id>'}

    Wenn Sie mit Policys nicht vertraut sind, finden Sie weitere Informationen unter Erste Schritte mit Policys und Allgemeine Policys.

  • Mit dem Vorgang Einstellungen der Cluster-APIs können Sie die empfohlenen Clustereinstellungen konfigurieren, mit denen Sie einen Connector erstellen können. Das folgende Beispiel enthält die empfohlenen Einstellungen:
    PUT _cluster/settings
    {
      "persistent": {
        "plugins": {
          "ml_commons": {
            "only_run_on_ml_node": "false",
            "model_access_control_enabled": "true",
            "native_memory_threshold": "99",
            "rag_pipeline_feature_enabled": "true",
            "memory_feature_enabled": "true",
            "allow_registering_model_via_local_file": "true",
            "allow_registering_model_via_url": "true",
            "model_auto_redeploy.enable":"true",
            "model_auto_redeploy.lifetime_retry_times": 10
          }
        }
      }
      }

Modellgruppe registrieren

Registrieren Sie eine Modellgruppe mit dem Vorgang registrieren in den Modellgruppen-APIs, wie im folgenden Beispiel dargestellt:

POST /_plugins/_ml/model_groups/_register
{
   "name": "public_model_group-emb",
   "description": "This is a public model group"
}

Notieren Sie sich die in der Antwort zurückgegebene model_group_id:

{
  "model_group_id": "<model_group_ID>",
  "status": "CREATED"
}

Connector erstellen

Sie können einen Connector zu einem der Remote-LLM-Modelle erstellen, die vom GenAI-Service unterstützt werden. Es gibt mehrere Modelle, die ON-DEMAND gehostet werden, aber diese Modelle werden manchmal veraltet. Sie können optional einen DEDICATED GENAI-Modellendpunkt konfigurieren und verwenden, wenn Sie möchten.

Hinweis

Wenn Sie das ON-DEMAND-Modell verwenden, bleiben Sie mit den Modellverfallsbenachrichtigungen vom GenAI-Service auf dem neuesten Stand, und aktualisieren Sie den Connector bei Bedarf, um potenzielle Serviceunterbrechungen zu vermeiden. Informationen zum Auswählen eines Large Language Model aus der Liste der unterstützten Modelle finden Sie unter Pretrained Foundational Models in Generative AI.

Wenn Sie das Modell DEDICATED verwenden, ändern Sie den Parameter servingType im folgenden Payload-Beispiel von ON-DEMAND in DEDICATED.

Die folgenden Abschnitte zeigen die Payload-Vorlage für die Modellklassen Cohere und Llama.

GenAI Connector-Vorlage für Cohere.Command-Modelle

Geben Sie die Informationen für die folgenden Platzhalter in Ihrer Payload an:

  • <connector_name>: Geben Sie einen eindeutigen Namen ein, um den Connector zu identifizieren. Beispiel: "Cohere-Befehls-r-plus-Connector v01".
  • <connector_description>: Geben Sie eine kurze Beschreibung für den Connector mit einer Länge von bis zu 30 Zeichen ein. Beispiel: "Mein Connector zum Modell GenAI cohere.command-r-plus."
  • <compartment_OCID>: Geben Sie die OCID des Compartments ein, in dem sich das OpenSearch-Cluster befindet.
  • <genai_cohere_model>: Geben Sie den Namen des Cohere-Modells ein, das Sie verwenden möchten. Beispiel: "cohere.command-r-plus".
POST _plugins/_ml/connectors/_create
{
     "name": "<connector_name>",
     "description": "<connector_description>",
     "version": 2,
     "protocol": "oci_sigv1",
     "parameters": {
         "endpoint": "inference.generativeai.us-chicago-1.oci.oraclecloud.com",
         "auth_type": "resource_principal"
     },
     "credential": {
     },
     "actions": [
         {
             "action_type": "predict",
             "method": "POST",
             "url": "https://${parameters.endpoint}/20231130/actions/chat",
             "request_body": "{\"compartmentId\":\"<compartment_OCID>\",\"servingMode\":{\"modelId\":\"<genai_cohere_model>\",\"servingType\":\"ON_DEMAND\"},\"chatRequest\":{\"message\":\"${parameters.prompt}\",\"maxTokens\":600,\"temperature\":1,\"frequencyPenalty\":0,\"presencePenalty\":0,\"topP\":0.75,\"topK\":0,\"isStream\":false,\"chatHistory\":[],\"apiFormat\":\"COHERE\"}}",
             "post_process_function": "def text = params['chatResponse']['text'].replace('\n', '\\\\n').replace('\"','');\n return '{\"name\":\"response\",\"dataAsMap\":{\"inferenceResponse\":{\"generatedTexts\":[{\"text\":\"' + text + '\"}]}}}'"
  
         }
     ]
 }

GenAI Connector-Vorlage für Meta-LLAMA-Modelle

Geben Sie die Informationen für die folgenden Platzhalter in Ihrer Payload an:

  • <connector_name>: Geben Sie einen eindeutigen Namen ein, um den Connector zu identifizieren. Beispiel: "meta-llama-Connector v1".
  • <connector_description>: Geben Sie eine kurze Beschreibung für den Connector mit einer Länge von bis zu 30 Zeichen ein. Beispiel: "Mein Connector zu GenAI meta.llama."
  • <compartment_OCID>: Geben Sie die OCID des Compartments ein, in dem sich das OpenSearch-Cluster befindet.
  • <genai_llama_model>: Geben Sie den Namen des LLAMA-Modells ein, das Sie verwenden möchten. Beispiel: "meta-llama-Connector v1".
POST _plugins/_ml/connectors/_create
{
     "name": "<connector_name>",
     "description": "<connector_description>",
     "version": 2,
     "protocol": "oci_sigv1",
     "parameters": {
         "endpoint": "inference.generativeai.us-chicago-1.oci.oraclecloud.com",
         "auth_type": "resource_principal"
     },
     "credential": {
     },
     "actions": [
         {
             "action_type": "predict",
             "method": "POST",
             "url": "https://${parameters.endpoint}/20231130/actions/chat",
             "request_body": "{\"compartmentId\":\<compartment_OCID>\",\"servingMode\":{\"modelId\":\"<genai_llama_model>\",\"servingType\":\"ON_DEMAND\"},\"chatRequest\":{\"maxTokens\":600,\"temperature\":1,\"frequencyPenalty\":0,\"presencePenalty\":0,\"topP\":0.75,\"topK\":-1,\"isStream\":false,\"apiFormat\":\"GENERIC\",\"messages\":[{\"role\":\"USER\",\"content\":[{\"type\":\"TEXT\",\"text\":\"${parameters.prompt}\"}]}]}}",
              
              "post_process_function": "def text = params['chatResponse']['choices'][0]['message']['content'][0]['text'].replace('\n', '\\\\n').replace('\"','');\n return '{\"name\":\"response\",\"dataAsMap\":{\"inferenceResponse\":{\"generatedTexts\":[{\"text\":\"' + text + '\"}]}}}'"
 
 
 
         }
     ]
 }

GenAI Connector-Vorlagen für OpenAI-Modelle

Im Folgenden finden Sie Beispiele für GenAI-Connector-Vorlagen für OpenAI-Modelle:

4o/4o-mini

POST _plugins/_ml/connectors/_create
{
     "name": "rag-connector",
     "description": "OpenAI connector for RAG pipeline",
     "version": 2,
     "protocol": "oci_sigv1",
     "parameters": {
         "endpoint": "inference.generativeai.us-chicago-1.oci.oraclecloud.com",
         "auth_type": "resource_principal"
     },
     "credential": {
     },
     "actions": [
         {
             "action_type": "predict",
             "method": "POST",
             "url": "https://${parameters.endpoint}/20231130/actions/chat",
             "request_body": "{\"compartmentId\":\"<compartment_OCID>\",\"servingMode\":{\"modelId\":\"<MODEL NAME>\",\"servingType\":\"ON_DEMAND\"},\"chatRequest\":{\"maxCompletionTokens\":600,\"temperature\":0.5,\"frequencyPenalty\":0,\"presencePenalty\":0,\"topP\":1.0,\"isStream\":false,\"apiFormat\":\"GENERIC\",\"messages\":[{\"role\":\"USER\",\"content\":[{\"type\":\"TEXT\",\"text\":\"${parameters.prompt}\"}]}]}}",
              "post_process_function": "def text = params['chatResponse']['choices'][0]['message']['content'][0]['text'].replace('\n', '\\\\n').replace('\"','');\n return '{\"name\":\"response\",\"dataAsMap\":{\"inferenceResponse\":{\"generatedTexts\":[{\"text\":\"' + text + '\"}]}}}'"
         }
     ]
}

o3-mini/o1

POST _plugins/_ml/connectors/_create
{
     "name": "o3-mini-rag-connector",
     "description": "OpenAI o3-mini connector for RAG pipeline",
     "version": 2,
     "protocol": "oci_sigv1",
     "parameters": {
         "endpoint": "inference.generativeai.us-chicago-1.oci.oraclecloud.com",
         "auth_type": "resource_principal"
     },
     "credential": {
     },
     "actions": [
         {
             "action_type": "predict",
             "method": "POST",
             "url": "https://${parameters.endpoint}/20231130/actions/chat",
             "request_body": "{\"compartmentId\":\"<compartment_OCID>\",\"servingMode\":{\"modelId\":\"<MODEL_NAME>\",\"servingType\":\"ON_DEMAND\"},\"chatRequest\":{\"isStream\":false,\"apiFormat\":\"GENERIC\",\"reasoningEffort\":\"LOW\",\"messages\":[{\"role\":\"USER\",\"content\":[{\"type\":\"TEXT\",\"text\":\"${parameters.prompt}\"}]}]}}",
              "post_process_function": "def text = params['chatResponse']['choices'][0]['message']['content'][0]['text'].replace('\n', '\\\\n').replace('\"','');\n return '{\"name\":\"response\",\"dataAsMap\":{\"inferenceResponse\":{\"generatedTexts\":[{\"text\":\"' + text + '\"}]}}}'"
         }
     ]
 } 

Das Modell registrieren

Registrieren Sie das Remotemodell mit dem Konnektor für generative KI mit der Connector-ID und der Modellgruppen-ID aus den vorherigen Schritten, wie im folgenden Beispiel dargestellt:

POST /_plugins/_ml/models/_register
{
   "name": "oci-genai-embed-test",
   "function_name": "remote",
   "model_group_id": "<model_group_ID>",
   "description": "test semantic",
   "connector_id": "<connector_ID>"
}

Modell bereitstellen

Stellen Sie das Modell mit der Modell-ID bereit, die in der Antwort aus den vorherigen Schritten zurückgegeben wurde, wie im folgenden Beispiel dargestellt:

POST /_plugins/_ml/models/<embedding_model_ID>/_deploy

RAG-Pipeline erstellen

Erstellen Sie eine RAG-Pipeline mit der model_id aus dem vorherigen Schritt, wie im folgenden Beispiel dargestellt:

PUT /_search/pipeline/demo_rag_pipeline
{
  "response_processors": [
    {
      "retrieval_augmented_generation": {
        "tag": "genai_conversational_search_demo",
        "description": "Demo pipeline for conversational search Using Genai Connector",
        "model_id": "<llm_model_ID>",
        "conversation_id": "<conversation_ID>",
        "context_field_list": ["<text_field_name>"],
        "system_prompt":"hepfull assistant",
        "user_instructions":"generate concise answer"
      }
    }
  ]
}

Suchindex erstellen

Nachdem die RAG-Pipeline erstellt wurde, können Sie RAG plus Konversationssuche für jeden Index ausführen. Sie können auch eine Datenaufnahme-Pipeline mit einem vortrainierten Modell nutzen, um die hybride Suche als Teil des Abrufs zu verwenden.

Suchindex ohne k-NN-Plugin erstellen

In diesem Abschnitt werden die Schritte zum Erstellen eines Index ohne Verwendung einer Aufnahmepipeline beschrieben.

Mit dieser Option können Sie Daten ohne Einbettung erstellen.

  1. Erstellen Sie einen Suchindex, wie im folgenden Beispiel gezeigt:
    PUT /conversation-demo-index
    {
      "settings": {
        "index": {
          "number_of_shards": 1,
          "number_of_replicas": 0
        }
      },
      "mappings": {
        "properties": {
          "title": {
            "type": "text"
          },
          "text": {
            "type": "text"
          }
        }
      }
    }
  2. Nehmen Sie Daten in den Index auf, wie im folgenden Beispiel dargestellt:
    PUT /conversation-demo-index/_doc/1
    {
        "text": "The emergence of resistance of bacteria to antibiotics is a common phenomenon. Emergence of resistance often reflects evolutionary processes that take place during antibiotic therapy. The antibiotic treatment may select for bacterial strains with physiologically or genetically enhanced capacity to survive high doses of antibiotics. Under certain conditions, it may result in preferential growth of resistant bacteria, while growth of susceptible bacteria is inhibited by the drug. For example, antibacterial selection for strains having previously acquired antibacterial-resistance genes was demonstrated in 1943 by the Luria–Delbrück experiment. Antibiotics such as penicillin and erythromycin, which used to have a high efficacy against many bacterial species and strains, have become less effective, due to the increased resistance of many bacterial strains."
       
    }
    GET /conversation-demo-index/_doc/1
    PUT /conversation-demo-index/_doc/2
    {
      "text": "The successful outcome of antimicrobial therapy with antibacterial compounds depends on several factors. These include host defense mechanisms, the location of infection, and the pharmacokinetic and pharmacodynamic properties of the antibacterial. A bactericidal activity of antibacterials may depend on the bacterial growth phase, and it often requires ongoing metabolic activity and division of bacterial cells. These findings are based on laboratory studies, and in clinical settings have also been shown to eliminate bacterial infection. Since the activity of antibacterials depends frequently on its concentration, in vitro characterization of antibacterial activity commonly includes the determination of the minimum inhibitory concentration and minimum bactericidal concentration of an antibacterial. To predict clinical outcome, the antimicrobial activity of an antibacterial is usually combined with its pharmacokinetic profile, and several pharmacological parameters are used as markers of drug efficacy."
    }
     
    PUT /conversation-demo-index/_doc/3
    {
      "text": "Antibacterial antibiotics are commonly classified based on their mechanism of action, chemical structure, or spectrum of activity. Most target bacterial functions or growth processes. Those that target the bacterial cell wall (penicillins and cephalosporins) or the cell membrane (polymyxins), or interfere with essential bacterial enzymes (rifamycins, lipiarmycins, quinolones, and sulfonamides) have bactericidal activities. Those that target protein synthesis (macrolides, lincosamides and tetracyclines) are usually bacteriostatic (with the exception of bactericidal aminoglycosides). Further categorization is based on their target specificity. Narrow-spectrum antibacterial antibiotics target specific types of bacteria, such as Gram-negative or Gram-positive bacteria, whereas broad-spectrum antibiotics affect a wide range of bacteria. Following a 40-year hiatus in discovering new classes of antibacterial compounds, four new classes of antibacterial antibiotics have been brought into clinical use in the late 2000s and early 2010s: cyclic lipopeptides (such as daptomycin), glycylcyclines (such as tigecycline), oxazolidinones (such as linezolid), and lipiarmycins (such as fidaxomicin)"
    }
     
     
    PUT /conversation-demo-index/_doc/4
    {
      "text": "The Desert Land Act of 1877 was passed to allow settlement of arid lands in the west and allotted 640 acres (2.6 km2) to settlers for a fee of $.25 per acre and a promise to irrigate the land. After three years, a fee of one dollar per acre would be paid and the land would be owned by the settler. This act brought mostly cattle and sheep ranchers into Montana, many of whom grazed their herds on the Montana prairie for three years, did little to irrigate the land and then abandoned it without paying the final fees. Some farmers came with the arrival of the Great Northern and Northern Pacific Railroads throughout the 1880s and 1890s, though in relatively small numbers"
    }
     
    PUT /conversation-demo-index/_doc/5
    {
      "text": "In the early 1900s, James J. Hill of the Great Northern began promoting settlement in the Montana prairie to fill his trains with settlers and goods. Other railroads followed suit. In 1902, the Reclamation Act was passed, allowing irrigation projects to be built in Montana's eastern river valleys. In 1909, Congress passed the Enlarged Homestead Act that expanded the amount of free land from 160 to 320 acres (0.6 to 1.3 km2) per family and in 1912 reduced the time to prove up on a claim to three years. In 1916, the Stock-Raising Homestead Act allowed homesteads of 640 acres in areas unsuitable for irrigation.  This combination of advertising and changes in the Homestead Act drew tens of thousands of homesteaders, lured by free land, with World War I bringing particularly high wheat prices. In addition, Montana was going through a temporary period of higher-than-average precipitation. Homesteaders arriving in this period were known as Honyockers, or scissorbills. Though the word honyocker, possibly derived from the ethnic slur hunyak, was applied in a derisive manner at homesteaders as being greenhorns, new at his business or unprepared, the reality was that a majority of these new settlers had previous farming experience, though there were also many who did not"
    }
     
    PUT /conversation-demo-index/_doc/6
    {
      "text": "In June 1917, the U.S. Congress passed the Espionage Act of 1917 which was later extended by the Sedition Act of 1918, enacted in May 1918. In February 1918, the Montana legislature had passed the Montana Sedition Act, which was a model for the federal version. In combination, these laws criminalized criticism of the U.S. government, military, or symbols through speech or other means. The Montana Act led to the arrest of over 200 individuals and the conviction of 78, mostly of German or Austrian descent. Over 40 spent time in prison. In May 2006, then-Governor Brian Schweitzer posthumously issued full pardons for all those convicted of violating the Montana Sedition Act."
    }
     
    PUT /conversation-demo-index/_doc/7
    {
      "text": "When the U.S. entered World War II on December 8, 1941, many Montanans already had enlisted in the military to escape the poor national economy of the previous decade. Another 40,000-plus Montanans entered the armed forces in the first year following the declaration of war, and over 57,000 joined up before the war ended. These numbers constituted about 10 percent of the state's total population, and Montana again contributed one of the highest numbers of soldiers per capita of any state. Many Native Americans were among those who served, including soldiers from the Crow Nation who became Code Talkers. At least 1500 Montanans died in the war. Montana also was the training ground for the First Special Service Force or Devil's Brigade a joint U.S-Canadian commando-style force that trained at Fort William Henry Harrison for experience in mountainous and winter conditions before deployment. Air bases were built in Great Falls, Lewistown, Cut Bank and Glasgow, some of which were used as staging areas to prepare planes to be sent to allied forces in the Soviet Union. During the war, about 30 Japanese balloon bombs were documented to have landed in Montana, though no casualties nor major forest fires were attributed to them"
    }

Da dieses Verfahren keine Aufnahmepipeline mit diesem Index verwendet, werden während der Aufnahme keine Einbettungen für Textdokumente generiert. Das bedeutet, dass nur die BM25-Suche zum Abrufen relevanter Dokumente verwendet wird.

Wenn Sie nach dem Erstellen eines Suchindex ohne das k-NN-Plug-in den folgenden Befehl ausführen, um ein indexiertes Dokument zu prüfen, wird nur der Text wie folgt zurückgegeben:

Anforderung:

GET /conversation-demo-index/_doc/1

Antwort:

{
  "_index": "conversation-demo-index",
  "_id": "1",
  "_version": 1,
  "_seq_no": 0,
  "_primary_term": 1,
  "found": true,
  "_source": {
    "text": "The emergence of resistance of bacteria to antibiotics is a common phenomenon. Emergence of resistance often reflects evolutionary processes that take place during antibiotic therapy. The antibiotic treatment may select for bacterial strains with physiologically or genetically enhanced capacity to survive high doses of antibiotics. Under certain conditions, it may result in preferential growth of resistant bacteria, while growth of susceptible bacteria is inhibited by the drug. For example, antibacterial selection for strains having previously acquired antibacterial-resistance genes was demonstrated in 1943 by the Luria–Delbrück experiment. Antibiotics such as penicillin and erythromycin, which used to have a high efficacy against many bacterial species and strains, have become less effective, due to the increased resistance of many bacterial strains."
  }
}

Suchindex mit k-NN-Plug-in erstellen

Um die hybride Suche anstelle von BM25 zu nutzen, um den Retriever-Teil der RAG-Pipeline anzureichern, müssen Sie eine Aufnahmepipeline einrichten und ein importiertes vortrainiertes Modell verwenden, damit Dokumenteinbettungen zur Aufnahmezeit erstellt werden.

Mit dieser Option können Sie den Index mit einer Aufnahmepipeline erstellen, um während der Aufnahme automatisch Einbettungen für die Daten zu generieren.

  1. Für diesen Durchlauf verwenden Sie eine der folgenden Optionen:
    • Option 1: Registrieren Sie ein vorgeschultes Modell, das in OCI Search mit OpenSearch gehostet wird, und stellen Sie es bereit. Verwenden Sie dazu die unter Vorgeschultes Modell mit OpenSearch verwenden beschriebenen Schritte. Diese Option ist die einfachste zu verwendende Option. Sie müssen keine zusätzlichen IAM-Policys konfigurieren, und die Payload ist nicht so komplex wie die Payload für die nächste Option.

    • Option 2: Importieren, registrieren und stellen Sie ein vortrainiertes OpenSearch-Modell mit den unter Benutzerdefinierte Modelle beschriebenen Schritten bereit. Dazu gehört das Hochladen der Modelldatei in einen Objektspeicher-Bucket und das Angeben der Objektspeicher-URL der Modelldatei, wenn Sie das Modell registrieren.

    • Option 3: Sie können auch ein Remote-Modell zur GenAI-Einbettung wie cohere.embed-english-v3.0 in Ihrem Cluster über unseren GenAI-Connector registrieren und bereitstellen. Sie müssen zuerst einen Connector erstellen und dann das Modell mit der Connector-ID registrieren und bereitstellen, wie in den folgenden Schritten beschrieben.

      Hinweis

      Wenn Sie das ON-DEMAND-Modell verwenden, bleiben Sie mit den Modellverfallsbenachrichtigungen vom GenAI-Service auf dem neuesten Stand, und aktualisieren Sie den Connector bei Bedarf, um potenzielle Serviceunterbrechungen zu vermeiden. Unter Pretrained Foundational Models in Generative AI finden Sie die unterstützten Einbettungsmodelle, um ein Einbettungsmodell aus der Liste der unterstützten Modelle auszuwählen.

      Wenn Sie das Modell DEDICATED verwenden, ändern Sie den Parameter servingType im folgenden Payload-Beispiel von ON-DEMAND in DEDICATED.

    Notieren Sie sich die Modell-ID, die zurückgegeben wird, wenn Sie das Modell registrieren und bereitstellen.

  2. Erstellen Sie eine Aufnahmepipeline mit der model id aus dem vorherigen Schritt, wie im folgenden Beispiel dargestellt:
    PUT _ingest/pipeline/minil12-test-pipeline
    {
      "description": "pipeline for RAG demo index",
      "processors" : [
        {
          "text_embedding": {
            "model_id": "<embedding_model_ID>",
            "field_map": {
               "text": "passage_embedding"
            }
          }
        }
      ]
    }
  3. Erstellen Sie einen Suchindex mit einer Aufnahmepipeline, wie im folgenden Beispiel dargestellt:
    PUT /conversation-demo-index-knn
    {
        "settings": {
            "index.knn": true,
            "default_pipeline": "minil12-test-pipeline"
        },
        "mappings": {
            "properties": {
                "passage_embedding": {
                    "type": "knn_vector",
                    "dimension": <model_dimension>,
                    "method": {
                        "name":"hnsw",
                        "engine":"lucene",
                        "space_type": "l2",
                        "parameters":{
                            "m":512,
                            "ef_construction": 245
                        }
                    }
                },
                "text": {
                    "type": "text"
                }
            }
        }
    }
  4. Nehmen Sie die Daten mit der Aufnahmepipeline aus dem vorherigen Schritt auf, wie im folgenden Beispiel dargestellt

    PUT /conversation-demo-index-knn/_doc/1
    {
        "text": "The emergence of resistance of bacteria to antibiotics is a common phenomenon. Emergence of resistance often reflects evolutionary processes that take place during antibiotic therapy. The antibiotic treatment may select for bacterial strains with physiologically or genetically enhanced capacity to survive high doses of antibiotics. Under certain conditions, it may result in preferential growth of resistant bacteria, while growth of susceptible bacteria is inhibited by the drug. For example, antibacterial selection for strains having previously acquired antibacterial-resistance genes was demonstrated in 1943 by the Luria–Delbrück experiment. Antibiotics such as penicillin and erythromycin, which used to have a high efficacy against many bacterial species and strains, have become less effective, due to the increased resistance of many bacterial strains."
       
    }
    GET /conversation-demo-index-knn/_doc/1
    PUT /conversation-demo-index-knn/_doc/2
    {
      "text": "The successful outcome of antimicrobial therapy with antibacterial compounds depends on several factors. These include host defense mechanisms, the location of infection, and the pharmacokinetic and pharmacodynamic properties of the antibacterial. A bactericidal activity of antibacterials may depend on the bacterial growth phase, and it often requires ongoing metabolic activity and division of bacterial cells. These findings are based on laboratory studies, and in clinical settings have also been shown to eliminate bacterial infection. Since the activity of antibacterials depends frequently on its concentration, in vitro characterization of antibacterial activity commonly includes the determination of the minimum inhibitory concentration and minimum bactericidal concentration of an antibacterial. To predict clinical outcome, the antimicrobial activity of an antibacterial is usually combined with its pharmacokinetic profile, and several pharmacological parameters are used as markers of drug efficacy."
    }
     
    PUT /conversation-demo-index-knn/_doc/3
    {
      "text": "Antibacterial antibiotics are commonly classified based on their mechanism of action, chemical structure, or spectrum of activity. Most target bacterial functions or growth processes. Those that target the bacterial cell wall (penicillins and cephalosporins) or the cell membrane (polymyxins), or interfere with essential bacterial enzymes (rifamycins, lipiarmycins, quinolones, and sulfonamides) have bactericidal activities. Those that target protein synthesis (macrolides, lincosamides and tetracyclines) are usually bacteriostatic (with the exception of bactericidal aminoglycosides). Further categorization is based on their target specificity. Narrow-spectrum antibacterial antibiotics target specific types of bacteria, such as Gram-negative or Gram-positive bacteria, whereas broad-spectrum antibiotics affect a wide range of bacteria. Following a 40-year hiatus in discovering new classes of antibacterial compounds, four new classes of antibacterial antibiotics have been brought into clinical use in the late 2000s and early 2010s: cyclic lipopeptides (such as daptomycin), glycylcyclines (such as tigecycline), oxazolidinones (such as linezolid), and lipiarmycins (such as fidaxomicin)"
    }
     
     
    PUT /conversation-demo-index-knn/_doc/4
    {
      "text": "The Desert Land Act of 1877 was passed to allow settlement of arid lands in the west and allotted 640 acres (2.6 km2) to settlers for a fee of $.25 per acre and a promise to irrigate the land. After three years, a fee of one dollar per acre would be paid and the land would be owned by the settler. This act brought mostly cattle and sheep ranchers into Montana, many of whom grazed their herds on the Montana prairie for three years, did little to irrigate the land and then abandoned it without paying the final fees. Some farmers came with the arrival of the Great Northern and Northern Pacific Railroads throughout the 1880s and 1890s, though in relatively small numbers"
    }
     
    PUT /conversation-demo-index-knn/_doc/5
    {
      "text": "In the early 1900s, James J. Hill of the Great Northern began promoting settlement in the Montana prairie to fill his trains with settlers and goods. Other railroads followed suit. In 1902, the Reclamation Act was passed, allowing irrigation projects to be built in Montana's eastern river valleys. In 1909, Congress passed the Enlarged Homestead Act that expanded the amount of free land from 160 to 320 acres (0.6 to 1.3 km2) per family and in 1912 reduced the time to prove up on a claim to three years. In 1916, the Stock-Raising Homestead Act allowed homesteads of 640 acres in areas unsuitable for irrigation.  This combination of advertising and changes in the Homestead Act drew tens of thousands of homesteaders, lured by free land, with World War I bringing particularly high wheat prices. In addition, Montana was going through a temporary period of higher-than-average precipitation. Homesteaders arriving in this period were known as Honyockers, or scissorbills. Though the word honyocker, possibly derived from the ethnic slur hunyak, was applied in a derisive manner at homesteaders as being greenhorns, new at his business or unprepared, the reality was that a majority of these new settlers had previous farming experience, though there were also many who did not"
    }
     
    PUT /conversation-demo-index-knn/_doc/6
    {
      "text": "In June 1917, the U.S. Congress passed the Espionage Act of 1917 which was later extended by the Sedition Act of 1918, enacted in May 1918. In February 1918, the Montana legislature had passed the Montana Sedition Act, which was a model for the federal version. In combination, these laws criminalized criticism of the U.S. government, military, or symbols through speech or other means. The Montana Act led to the arrest of over 200 individuals and the conviction of 78, mostly of German or Austrian descent. Over 40 spent time in prison. In May 2006, then-Governor Brian Schweitzer posthumously issued full pardons for all those convicted of violating the Montana Sedition Act."
    }
     
    PUT /conversation-demo-index-knn/_doc/7
    {
      "text": "When the U.S. entered World War II on December 8, 1941, many Montanans already had enlisted in the military to escape the poor national economy of the previous decade. Another 40,000-plus Montanans entered the armed forces in the first year following the declaration of war, and over 57,000 joined up before the war ended. These numbers constituted about 10 percent of the state's total population, and Montana again contributed one of the highest numbers of soldiers per capita of any state. Many Native Americans were among those who served, including soldiers from the Crow Nation who became Code Talkers. At least 1500 Montanans died in the war. Montana also was the training ground for the First Special Service Force or Devil's Brigade a joint U.S-Canadian commando-style force that trained at Fort William Henry Harrison for experience in mountainous and winter conditions before deployment. Air bases were built in Great Falls, Lewistown, Cut Bank and Glasgow, some of which were used as staging areas to prepare planes to be sent to allied forces in the Soviet Union. During the war, about 30 Japanese balloon bombs were documented to have landed in Montana, though no casualties nor major forest fires were attributed to them"
    }

Nachdem Sie den Suchindex mit dem k-NN-Plug-in erstellt haben, enthält die Antwort Einbettungen, wenn Sie den folgenden Befehl ausführen, um ein indiziertes Dokument zu prüfen:

Anforderung:

GET /conversation-demo-index-knn/_doc/1

Antwort:

{
  "_index": "conversation-demo-index-knn",
  "_id": "1",
  "_version": 1,
  "_seq_no": 0,
  "_primary_term": 1,
  "found": true,
  "_source": {
    "passage_embedding": [
      -0.02929831,
      -0.04421867,
      -0.10647401,
      0.07105031,
      0.004921746,
      -0.04529944,
      -0.092778176,
      0.14189903,
      -0.0016610072,
      0.08001712,
      0.053442925,
      -0.022703059,
      0.039608333,
      0.042299673,
      ..............

Unterhaltungs-ID erstellen

Führen Sie diesen Befehl durch, um die Unterhaltungs-ID zu erstellen:

POST /_plugins/_ml/memory/conversation
{
  "name": "rag-conversation"
}

Antwort:

{
  "conversation_id": "<conversation_ID>"
}

RAG mit BM25 ausführen

Nachdem die Dokumente indexiert wurden, können Sie RAG mit dem Namen der unter RAG-Pipeline erstellen angegebenen RAG-Pipeline ausführen, wie im folgenden Beispiel dargestellt.

Wenn Sie einen Data-Science-Connector verwenden, müssen Sie den Wert "llm_model" in "oci_datascience/<your_llm_model_name>" ändern.

GET /conversation-demo-index/_search?search_pipeline=<pipeline_name>
{
    "query": {
        "match": {
            "text": {
                "query": "when did us pass espionage act?"
            }
        }
    },
    "ext": {
        "generative_qa_parameters": {
            "llm_model": "oci_genai/<your_llm_model_name>",
            "llm_question": "when did us pass espionage act? answer only in two sentences using provided context.",
            "conversation_id": "<conversation_ID>",
            "context_size": 2,
            "interaction_size": 1,
            "timeout": 15
        }
    }
}

Der erste Teil ist der Abruf mit der Abfrage zum Index, um die relevantesten Dokumente basierend auf der Abfrage des Benutzers zu finden. Im zweiten Teil wird die Benutzerabfrage um weitere Anweisungen erweitert, und die Antwort aus dem Abrufteil wird dann als Kontext verwendet. Diese werden dann alle an das große Sprachmodell übergeben, um die Antwort nur mit Wissen in den Anwendungsfalldaten zu generieren.

Geben Sie den Modellnamen an, den Sie in der Payload unter Connector erstellen für <your_llm_model_name> verwendet haben. Im Folgenden sind Beispiele für Modellnamen aufgeführt:

  • oci_genai/cohere.command-r-plus-08-2024
  • oci_genai/cohere.command-08-2024
  • oci_genai/meta.llama-3.1-70b-instruct
  • oci_genai/meta.llama-3.2-90b-vision-instruct

In der folgenden Antwort ist der erste Teil eine Gruppe von Dokumenten, die vom Abrufer zurückgegeben werden (die Suchmaschine in OpenSearch). Darauf folgt die Antwort des großen Sprachmodells (LLM), das die tatsächliche Antwort des LLM-Modells ist, indem Textgenerierung und kontextbezogenes Lernen verwendet werden, um die Wissensdatenbank des LLM zu erweitern. Die hier verwendete Suchmaschine lautet BM25, weil der Index conversation-demo-index kein bereitgestelltes Modell verwendet, um Dokumenteinbettungen während der Aufnahme zu generieren.

{
  "took": 1,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 4,
      "relation": "eq"
    },
    "max_score": 3.6364775,
    "hits": [
      {
        "_index": "conversation-demo-index",
        "_id": "6",
        "_score": 3.6364775,
        "_source": {
          "text": "In June 1917, the U.S. Congress passed the Espionage Act of 1917 which was later extended by the Sedition Act of 1918, enacted in May 1918. In February 1918, the Montana legislature had passed the Montana Sedition Act, which was a model for the federal version. In combination, these laws criminalized criticism of the U.S. government, military, or symbols through speech or other means. The Montana Act led to the arrest of over 200 individuals and the conviction of 78, mostly of German or Austrian descent. Over 40 spent time in prison. In May 2006, then-Governor Brian Schweitzer posthumously issued full pardons for all those convicted of violating the Montana Sedition Act."
        }
      },
      {
        "_index": "conversation-demo-index",
        "_id": "4",
        "_score": 2.675274,
        "_source": {
          "text": "The Desert Land Act of 1877 was passed to allow settlement of arid lands in the west and allotted 640 acres (2.6 km2) to settlers for a fee of $.25 per acre and a promise to irrigate the land. After three years, a fee of one dollar per acre would be paid and the land would be owned by the settler. This act brought mostly cattle and sheep ranchers into Montana, many of whom grazed their herds on the Montana prairie for three years, did little to irrigate the land and then abandoned it without paying the final fees. Some farmers came with the arrival of the Great Northern and Northern Pacific Railroads throughout the 1880s and 1890s, though in relatively small numbers"
        }
      },
      {
        "_index": "conversation-demo-index",
        "_id": "5",
        "_score": 2.5380564,
        "_source": {
          "text": "In the early 1900s, James J. Hill of the Great Northern began promoting settlement in the Montana prairie to fill his trains with settlers and goods. Other railroads followed suit. In 1902, the Reclamation Act was passed, allowing irrigation projects to be built in Montana's eastern river valleys. In 1909, Congress passed the Enlarged Homestead Act that expanded the amount of free land from 160 to 320 acres (0.6 to 1.3 km2) per family and in 1912 reduced the time to prove up on a claim to three years. In 1916, the Stock-Raising Homestead Act allowed homesteads of 640 acres in areas unsuitable for irrigation.  This combination of advertising and changes in the Homestead Act drew tens of thousands of homesteaders, lured by free land, with World War I bringing particularly high wheat prices. In addition, Montana was going through a temporary period of higher-than-average precipitation. Homesteaders arriving in this period were known as Honyockers, or scissorbills. Though the word honyocker, possibly derived from the ethnic slur hunyak, was applied in a derisive manner at homesteaders as being greenhorns, new at his business or unprepared, the reality was that a majority of these new settlers had previous farming experience, though there were also many who did not"
        }
      },
      {
        "_index": "conversation-demo-index",
        "_id": "7",
        "_score": 1.4905708,
        "_source": {
          "text": "When the U.S. entered World War II on December 8, 1941, many Montanans already had enlisted in the military to escape the poor national economy of the previous decade. Another 40,000-plus Montanans entered the armed forces in the first year following the declaration of war, and over 57,000 joined up before the war ended. These numbers constituted about 10 percent of the state's total population, and Montana again contributed one of the highest numbers of soldiers per capita of any state. Many Native Americans were among those who served, including soldiers from the Crow Nation who became Code Talkers. At least 1500 Montanans died in the war. Montana also was the training ground for the First Special Service Force or Devil's Brigade a joint U.S-Canadian commando-style force that trained at Fort William Henry Harrison for experience in mountainous and winter conditions before deployment. Air bases were built in Great Falls, Lewistown, Cut Bank and Glasgow, some of which were used as staging areas to prepare planes to be sent to allied forces in the Soviet Union. During the war, about 30 Japanese balloon bombs were documented to have landed in Montana, though no casualties nor major forest fires were attributed to them"
        }
      }
    ]
  },
  "ext": {
    "retrieval_augmented_generation": {
      "answer": " Through the Espionage Act of 1917 and the Sedition Act of 1918, passed in May of 1918, the U.S. Congress outlawed criticism of the military, government, or symbols through speech or other means. The Montana Sedition Act was enacted in February 1918, serving as a model for the federal version, and resulting in the arrest of over 200 people, chiefly of German or Austrian descent, with over 40 imprisoned. "
    }
  }
}