{"id":10287,"date":"2025-12-09T02:13:28","date_gmt":"2025-12-09T10:13:28","guid":{"rendered":"https:\/\/www.couchbase.com\/developers\/tutorials\/openai-haystack-rag-with-hyperscale-or-composite-vector-index\/"},"modified":"2025-12-09T02:13:28","modified_gmt":"2025-12-09T10:13:28","slug":"openai-haystack-rag-with-hyperscale-or-composite-vector-index","status":"publish","type":"tutorials","link":"https:\/\/www.couchbase.com\/ja\/developers\/tutorials\/openai-haystack-rag-with-hyperscale-or-composite-vector-index\/","title":{"rendered":"RAG with OpenAI, Haystack, and Couchbase Hyperscale &#038; Composite Vector Indexes"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/github.com\/couchbase-examples\/vector-search-cookbook\/tree\/main\/haystack\/query_based\/RAG_with_Couchbase_Capella_and_OpenAI.ipynb\">View Source<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In this guide, we will walk you through building a Retrieval Augmented Generation (RAG) application with Haystack orchestrating OpenAI models and Couchbase Capella. We will use the <a href=\"https:\/\/platform.openai.com\/docs\/models\/gpt-4o\">gpt-4o<\/a> model for response generation and the <a href=\"https:\/\/platform.openai.com\/docs\/guides\/embeddings\/embedding-models\">text-embedding-3-large<\/a> model for generating embeddings.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This notebook demonstrates how to build a RAG system using:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The <a href=\"https:\/\/huggingface.co\/datasets\/RealTimeData\/bbc_news_alltime\">BBC News dataset<\/a> containing news articles<\/li>\n\n\n<li>Couchbase Capella Hyperscale and Composite Vector Indexes for vector search<\/li>\n\n\n<li>Haystack framework for the RAG pipeline<\/li>\n\n\n<li>OpenAI for embeddings and text generation<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">We leverage Couchbase&#8217;s Hyperscale and Composite Vector Indexes to enable efficient semantic search at scale. Hyperscale indexes prioritize high-throughput vector similarity across billions of vectors with a compact on-disk footprint, while Composite indexes blend scalar predicates with a vector column to narrow candidate sets before similarity search. For a deeper dive into how these indexes work, see the <a href=\"https:\/\/docs.couchbase.com\/cloud\/vector-index\/vectors-and-indexes-overview.html\">overview of Capella vector indexes<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Semantic search goes beyond simple keyword matching by understanding the context and meaning behind the words in a query, making it an essential tool for applications that require intelligent information retrieval. This tutorial shows how to combine OpenAI Services and Haystack with Couchbase&#8217;s Hyperscale and Composite Vector Indexes to deliver a production-ready RAG workflow.<\/p>\n\n\n\n<h3 id=\"h-create-and-deploy-your-operational-cluster-on-capella\" class=\"wp-block-heading\">Create and Deploy Your Operational cluster on Capella<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">To get started with Couchbase Capella, create an account and use it to deploy an operational cluster.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To know more, please follow the <a href=\"https:\/\/docs.couchbase.com\/cloud\/get-started\/create-account.html\">instructions<\/a>.<\/p>\n\n\n\n<h4 id=\"h-couchbase-capella-configuration\" class=\"wp-block-heading\">Couchbase Capella Configuration<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">When running Couchbase using <a href=\"https:\/\/cloud.couchbase.com\/sign-in\">Capella<\/a>, the following prerequisites need to be met:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Have a multi-node Capella cluster running the Data, Query, Index, and Search services.<\/li>\n\n\n<li>Create the <a href=\"https:\/\/docs.couchbase.com\/cloud\/clusters\/manage-database-users.html\">database credentials<\/a> to access the bucket (Read and Write) used in the application.<\/li>\n\n\n<li><a href=\"https:\/\/docs.couchbase.com\/cloud\/clusters\/allow-ip-address.html\">Allow access<\/a> to the Cluster from the IP on which the application is running.<\/li>\n\n<\/ul>\n\n\n\n<h4 id=\"h-openai-models-setup\" class=\"wp-block-heading\">OpenAI Models Setup<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">In order to create the RAG application, we need an embedding model to generate embeddings of documents for Vector Search and a large language model (LLM) for generating the responses based on the context.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For this implementation, we&#8217;ll use OpenAI&#8217;s models which provide state-of-the-art performance for both embeddings and text generation:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Embedding Model<\/strong>: We&#8217;ll use OpenAI&#8217;s <code>text-embedding-3-large<\/code> model, which provides high-quality embeddings with 3,072 dimensions for semantic search capabilities.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Large Language Model<\/strong>: We&#8217;ll use OpenAI&#8217;s <code>gpt-4o<\/code> model for generating responses based on the retrieved context. This model offers excellent reasoning capabilities and can handle complex queries effectively.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Prerequisites for OpenAI Integration<\/strong>:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Create an OpenAI account at <a href=\"https:\/\/platform.openai.com\">platform.openai.com<\/a><\/li>\n\n\n<li>Generate an API key from your OpenAI dashboard<\/li>\n\n\n<li>Ensure you have sufficient credits or a valid payment method set up<\/li>\n\n\n<li>Set up your API key as an environment variable or input it securely in the notebook<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">For more details about OpenAI&#8217;s models and pricing, please refer to the <a href=\"https:\/\/platform.openai.com\/docs\/models\">OpenAI documentation<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To build our RAG system, we need a set of libraries. The libraries we install handle everything from connecting to databases to performing AI tasks. Each library has a specific role: Couchbase libraries manage database operations, Haystack handles AI model integrations and pipeline management, and we will use the OpenAI SDK for generating embeddings and calling OpenAI&#8217;s language models.<\/p>\n\n\n\n<pre class=\"wp-block-code language-python\"><code># Install required packages\n%pip install -r requirements.txt\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The script starts by importing a series of libraries required for various tasks, including handling JSON, logging, time tracking, Couchbase connections, Haystack components for RAG pipeline, embedding generation, and dataset loading.<\/p>\n\n\n\n<pre class=\"wp-block-code language-python\"><code>import getpass\nimport base64\nimport logging\nimport sys\nimport time\nimport pandas as pd\nfrom datetime import timedelta\n\nfrom couchbase.auth import PasswordAuthenticator\nfrom couchbase.cluster import Cluster\nfrom couchbase.exceptions import CouchbaseException\nfrom couchbase.options import ClusterOptions, KnownConfigProfiles, QueryOptions\n\nfrom datasets import load_dataset\n\nfrom haystack import Pipeline, Document, GeneratedAnswer\nfrom haystack.components.embedders import OpenAIDocumentEmbedder, OpenAITextEmbedder\nfrom haystack.components.builders.answer_builder import AnswerBuilder\nfrom haystack.components.generators import OpenAIGenerator\nfrom haystack.components.preprocessors import DocumentCleaner\nfrom haystack.components.writers import DocumentWriter\nfrom haystack.utils import Secret\nfrom haystack.components.builders import PromptBuilder\nfrom couchbase_haystack import (\n    CouchbaseQueryDocumentStore, \n    CouchbaseQueryEmbeddingRetriever,\n    QueryVectorSearchType, \n    QueryVectorSearchSimilarity,\n    CouchbasePasswordAuthenticator,\n    CouchbaseClusterOptions\n)\n\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">In this section, we prompt the user to input essential configuration settings needed. These settings include sensitive information like database credentials, collection names, and API keys. Instead of hardcoding these details into the script, we request the user to provide them at runtime, ensuring flexibility and security.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The script also validates that all required inputs are provided, raising an error if any crucial information is missing. This approach ensures that your integration is both secure and correctly configured without hardcoding sensitive information, enhancing the overall security and maintainability of your code.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>OPENAI_API_KEY<\/strong> is your OpenAI API key which can be obtained from your OpenAI dashboard at <a href=\"https:\/\/platform.openai.com\/api-keys\">platform.openai.com<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>INDEX_NAME<\/strong> is the name of the Hyperscale or Composite Vector Index we will create for vector search operations.<\/p>\n\n\n\n<pre class=\"wp-block-code language-python\"><code>CB_CONNECTION_STRING = input(&quot;Couchbase Cluster URL (default: localhost): &quot;) or &quot;couchbase:\/\/localhost&quot;\nCB_USERNAME = input(&quot;Couchbase Username (default: admin): &quot;) or &quot;admin&quot;\nCB_PASSWORD = input(&quot;Couchbase password (default: Password@12345): &quot;) or &quot;Password@12345&quot;\nCB_BUCKET_NAME = input(&quot;Couchbase Bucket: &quot;)\nSCOPE_NAME = input(&quot;Couchbase Scope: &quot;)\nCOLLECTION_NAME = input(&quot;Couchbase Collection: &quot;)\nINDEX_NAME = input(&quot;Vector Search Index: &quot;)\nOPENAI_API_KEY = input(&quot;OpenAI API Key: &quot;)\n\n# Check if the variables are correctly loaded\nif not all([CB_CONNECTION_STRING, CB_USERNAME, CB_PASSWORD, CB_BUCKET_NAME, SCOPE_NAME, COLLECTION_NAME, INDEX_NAME, OPENAI_API_KEY]):\n    raise ValueError(&quot;All configuration variables must be provided.&quot;)\n\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Logging is essential for tracking the execution of our script and debugging any issues that may arise. We set up a logger that will display information about the script&#8217;s progress, including timestamps and log levels.<\/p>\n\n\n\n<pre class=\"wp-block-code language-python\"><code># Configure logging\nlogging.basicConfig(\n    level=logging.INFO,\n    format=&quot;%(asctime)s - %(levelname)s - %(message)s&quot;,\n    handlers=[logging.StreamHandler(sys.stdout)],\n)\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The next step is to establish a connection to our Couchbase Capella cluster. This connection will allow us to interact with the database, store and retrieve documents, and perform vector searches.<\/p>\n\n\n\n<pre class=\"wp-block-code language-python\"><code>try:\n    # Initialize the Couchbase Cluster\n    auth = PasswordAuthenticator(CB_USERNAME, CB_PASSWORD)\n    options = ClusterOptions(auth)\n    options.apply_profile(KnownConfigProfiles.WanDevelopment)\n    \n    # Connect to the cluster\n    cluster = Cluster(CB_CONNECTION_STRING, options)\n    \n    # Wait for the cluster to be ready\n    cluster.wait_until_ready(timedelta(seconds=5))\n    logging.info(&quot;Successfully connected to the Couchbase cluster&quot;)\nexcept CouchbaseException as e:\n    raise RuntimeError(f&quot;Failed to connect to Couchbase: {str(e)}&quot;)\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Before we can store our data, we need to ensure that the appropriate bucket, scope, and collection exist in our Couchbase cluster. The code below checks if these components exist and creates them if they don&#8217;t, providing a foundation for storing our vector embeddings and documents.<\/p>\n\n\n\n<pre class=\"wp-block-code language-python\"><code>from couchbase.management.buckets import CreateBucketSettings\nimport json\n\n# Create bucket if it does not exist\nbucket_manager = cluster.buckets()\ntry:\n    bucket_manager.get_bucket(CB_BUCKET_NAME)\n    print(f&quot;Bucket &#039;{CB_BUCKET_NAME}&#039; already exists.&quot;)\nexcept Exception as e:\n    print(f&quot;Bucket &#039;{CB_BUCKET_NAME}&#039; does not exist. Creating bucket...&quot;)\n    bucket_settings = CreateBucketSettings(name=CB_BUCKET_NAME, ram_quota_mb=500)\n    bucket_manager.create_bucket(bucket_settings)\n    print(f&quot;Bucket &#039;{CB_BUCKET_NAME}&#039; created successfully.&quot;)\n\n# Create scope and collection if they do not exist\ncollection_manager = cluster.bucket(CB_BUCKET_NAME).collections()\nscopes = collection_manager.get_all_scopes()\nscope_exists = any(scope.name == SCOPE_NAME for scope in scopes)\n\nif scope_exists:\n    print(f&quot;Scope &#039;{SCOPE_NAME}&#039; already exists.&quot;)\nelse:\n    print(f&quot;Scope &#039;{SCOPE_NAME}&#039; does not exist. Creating scope...&quot;)\n    collection_manager.create_scope(SCOPE_NAME)\n    print(f&quot;Scope &#039;{SCOPE_NAME}&#039; created successfully.&quot;)\n\ncollections = [collection.name for scope in scopes if scope.name == SCOPE_NAME for collection in scope.collections]\ncollection_exists = COLLECTION_NAME in collections\n\nif collection_exists:\n    print(f&quot;Collection &#039;{COLLECTION_NAME}&#039; already exists in scope &#039;{SCOPE_NAME}&#039;.&quot;)\nelse:\n    print(f&quot;Collection &#039;{COLLECTION_NAME}&#039; does not exist in scope &#039;{SCOPE_NAME}&#039;. Creating collection...&quot;)\n    collection_manager.create_collection(collection_name=COLLECTION_NAME, scope_name=SCOPE_NAME)\n    print(f&quot;Collection &#039;{COLLECTION_NAME}&#039; created successfully.&quot;)\n\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">To build a RAG engine, we need data to search through. We use the <a href=\"https:\/\/huggingface.co\/datasets\/RealTimeData\/bbc_news_alltime\">BBC Realtime News dataset<\/a>, a dataset with up-to-date BBC news articles grouped by month. This dataset contains articles that were created after the LLM was trained. It will showcase the use of RAG to augment the LLM.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The BBC News dataset&#8217;s varied content allows us to simulate real-world scenarios where users ask complex questions, enabling us to fine-tune our RAG&#8217;s ability to understand and respond to various types of queries.<\/p>\n\n\n\n<pre class=\"wp-block-code language-python\"><code>try:\n    news_dataset = load_dataset(&#039;RealTimeData\/bbc_news_alltime&#039;, &#039;2024-12&#039;, split=&quot;train&quot;)\n    print(f&quot;Loaded the BBC News dataset with {len(news_dataset)} rows&quot;)\nexcept Exception as e:\n    raise ValueError(f&quot;Error loading BBC News dataset: {str(e)}&quot;)\n<\/code><\/pre>\n\n\n\n<h3 id=\"h-preview-the-data\" class=\"wp-block-heading\">Preview the Data<\/h3>\n\n\n\n<pre class=\"wp-block-code language-python\"><code># Print the first two examples from the dataset\nprint(&quot;Dataset columns:&quot;, news_dataset.column_names)\nprint(&quot;nFirst two examples:&quot;)\nprint(news_dataset[:2])\n<\/code><\/pre>\n\n\n\n<h3 id=\"h-preparing-the-data-for-rag\" class=\"wp-block-heading\">Preparing the Data for RAG<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">We need to extract the context passages from the dataset to use as our knowledge base for the RAG system.<\/p>\n\n\n\n<pre class=\"wp-block-code language-python\"><code>import hashlib\n\nnews_articles = news_dataset\nunique_articles = {}\n\nfor article in news_articles:\n    content = article.get(&quot;content&quot;)\n    if content:\n        content_hash = hashlib.md5(content.encode()).hexdigest()  # Generate hash of content\n        if content_hash not in unique_articles:\n            unique_articles[content_hash] = article  # Store full article\n\nunique_news_articles = list(unique_articles.values())  # Convert back to list\n\nprint(f&quot;We have {len(unique_news_articles)} unique articles in our database.&quot;)\n\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Embeddings are numerical representations of text that capture semantic meaning. Unlike keyword-based search, embeddings enable semantic search to understand context and retrieve documents that are conceptually similar even without exact keyword matches. We&#8217;ll use OpenAI&#8217;s <code>text-embedding-3-large<\/code> model to create high-quality embeddings with 3,072 dimensions. This model transforms our text data into vector representations that can be efficiently searched using Haystack&#8217;s OpenAI document embedder.<\/p>\n\n\n\n<pre class=\"wp-block-code language-python\"><code>try:\n    # Set up the document embedder for processing documents\n    document_embedder = OpenAIDocumentEmbedder(\n        api_key=Secret.from_token(OPENAI_API_KEY),\n        model=&quot;text-embedding-3-large&quot;\n    )\n    \n    # Set up the text embedder for query processing\n    rag_embedder = OpenAITextEmbedder(\n        api_key=Secret.from_token(OPENAI_API_KEY),\n        model=&quot;text-embedding-3-large&quot;\n    )\n    \n    print(&quot;Successfully created embedding models&quot;)\nexcept Exception as e:\n    raise ValueError(f&quot;Error creating embedding models: {str(e)}&quot;)\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">We can test the text embeddings model by generating an embedding for a string<\/p>\n\n\n\n<pre class=\"wp-block-code language-python\"><code>test_result = rag_embedder.run(text=&quot;this is a test sentence&quot;)\ntest_embedding = test_result[&quot;embedding&quot;]\nprint(f&quot;Embedding dimension: {len(test_embedding)}&quot;)\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>CouchbaseQueryDocumentStore<\/code> from the <code>couchbase_haystack<\/code> package provides seamless integration with Couchbase, supporting both Hyperscale and Composite Vector Indexes.<\/p>\n\n\n\n<pre class=\"wp-block-code language-python\"><code>try:\n    # Create the Couchbase vector document store\n    document_store = CouchbaseQueryDocumentStore(\n        cluster_connection_string=Secret.from_token(CB_CONNECTION_STRING),\n        authenticator=CouchbasePasswordAuthenticator(\n            username=Secret.from_token(CB_USERNAME),\n            password=Secret.from_token(CB_PASSWORD)\n        ),\n        cluster_options=CouchbaseClusterOptions(\n            profile=KnownConfigProfiles.WanDevelopment,\n        ),\n        bucket=CB_BUCKET_NAME,\n        scope=SCOPE_NAME,\n        collection=COLLECTION_NAME,\n        search_type=QueryVectorSearchType.ANN,\n        similarity=QueryVectorSearchSimilarity.L2\n    )\n    print(&quot;Successfully created Couchbase vector document store&quot;)\nexcept Exception as e:\n    raise ValueError(f&quot;Failed to create Couchbase vector document store: {str(e)}&quot;)\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">In this section, we&#8217;ll process our news articles and create Haystack Document objects.\nEach Document is created with specific metadata that will be used for retrieval and generation.\nWe&#8217;ll observe examples of the document content to understand how the documents are structured.<\/p>\n\n\n\n<pre class=\"wp-block-code language-python\"><code>haystack_documents = []\n# Process and store documents\nfor article in unique_news_articles:  # Process all unique articles\n    try:\n        document = Document(\n            content=article[&quot;content&quot;],\n            meta={\n                &quot;title&quot;: article[&quot;title&quot;],\n                &quot;description&quot;: article[&quot;description&quot;],\n                &quot;published_date&quot;: article[&quot;published_date&quot;],\n                &quot;link&quot;: article[&quot;link&quot;],\n            }\n        )\n        haystack_documents.append(document)\n    except Exception as e:\n        print(f&quot;Failed to create document: {str(e)}&quot;)\n        continue\n\n# Observing an example of the document content\nprint(&quot;Document content preview:&quot;)\nprint(f&quot;Content: {haystack_documents[0].content[:200]}...&quot;)\nprint(f&quot;Metadata: {haystack_documents[0].meta}&quot;)\n\nprint(f&quot;Created {len(haystack_documents)} documents&quot;)\n\n        \n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">In this section, we&#8217;ll create an indexing pipeline to process our documents. The pipeline will:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>DocumentCleaner &#8211; Cleans and preprocesses the raw Haystack documents (removes extra whitespace, normalizes text)<\/li>\n\n\n<li>document_embedder &#8211; Generates vector embeddings for each document using an embedding model (likely OpenAI&#8217;s), converting text into numerical representations for semantic search<\/li>\n\n\n<li>DocumentWriter &#8211; Writes the cleaned documents along with their embeddings to the Couchbase document store<\/li>\n\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">This transforms raw news articles into searchable vector representations stored in Couchbase for later semantic retrieval in the RAG system.<\/p>\n\n\n\n<pre class=\"wp-block-code language-python\"><code>\n\n# Process documents: split into chunks, generate embeddings, and store in document store\n# Create indexing pipeline\nindexing_pipeline = Pipeline()\nindexing_pipeline.add_component(&quot;cleaner&quot;, DocumentCleaner())\nindexing_pipeline.add_component(&quot;embedder&quot;, document_embedder)\nindexing_pipeline.add_component(&quot;writer&quot;, DocumentWriter(document_store=document_store))\n\nindexing_pipeline.connect(&quot;cleaner.documents&quot;, &quot;embedder.documents&quot;)\nindexing_pipeline.connect(&quot;embedder.documents&quot;, &quot;writer.documents&quot;)\n\n\n\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Execute the pipeline for processing and indexing BCC news documents:<\/p>\n\n\n\n<pre class=\"wp-block-code language-python\"><code># Run the indexing pipeline\nif haystack_documents:\n    result = indexing_pipeline.run({&quot;cleaner&quot;: {&quot;documents&quot;: haystack_documents[:1200]}})\n    print(f&quot;Indexed {result[&#039;writer&#039;][&#039;documents_written&#039;]} document chunks&quot;)\nelse:\n    print(&quot;No documents created. Skipping indexing.&quot;)\n\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Large language models are AI systems that are trained to understand and generate human language. We&#8217;ll be using OpenAI&#8217;s <code>gpt-4o<\/code> model to process user queries and generate meaningful responses based on the retrieved context from our Couchbase document store. This model is a key component of our RAG system, allowing it to go beyond simple keyword matching and truly understand the intent behind a query. By integrating OpenAI&#8217;s LLM, we equip our RAG system with the ability to interpret complex queries, understand the nuances of language, and provide more accurate and contextually relevant responses.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The language model&#8217;s ability to understand context and generate coherent responses is what makes our RAG system truly intelligent. It can not only find the right information but also present it in a way that is useful and understandable to the user.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The LLM is configured using Haystack&#8217;s OpenAI generator component with your OpenAI API key for seamless integration with their services.<\/p>\n\n\n\n<pre class=\"wp-block-code language-python\"><code>try:\n    # Set up the LLM generator\n    generator = OpenAIGenerator(\n        api_key=Secret.from_token(OPENAI_API_KEY),\n        model=&quot;gpt-4o&quot;\n    )\n    logging.info(&quot;Successfully created the OpenAI generator&quot;)\nexcept Exception as e:\n    raise ValueError(f&quot;Error creating OpenAI generator: {str(e)}&quot;)\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">In this section, we&#8217;ll create a RAG pipeline using Haystack components. This pipeline serves as the foundation for our RAG system, enabling semantic search capabilities and efficient retrieval of relevant information.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The RAG pipeline provides a complete workflow that allows us to:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Perform semantic searches based on user queries<\/li>\n\n\n<li>Retrieve the most relevant documents or chunks<\/li>\n\n\n<li>Generate contextually appropriate responses using our LLM<\/li>\n\n<\/ol>\n\n\n\n<pre class=\"wp-block-code language-python\"><code># Define RAG prompt template\nprompt_template = &quot;&quot;&quot;\nGiven these documents, answer the question.nDocuments:\n{% for doc in documents %}\n    {{ doc.content }}\n{% endfor %}\n\nnQuestion: {{question}}\nnAnswer:\n&quot;&quot;&quot;\n\n# Create the RAG pipeline\nrag_pipeline = Pipeline()\n\n# Add components to the pipeline\nrag_pipeline.add_component(\n    &quot;query_embedder&quot;,\n    rag_embedder,\n)\nrag_pipeline.add_component(&quot;retriever&quot;, CouchbaseQueryEmbeddingRetriever(document_store=document_store))\nrag_pipeline.add_component(&quot;prompt_builder&quot;, PromptBuilder(template=prompt_template))\nrag_pipeline.add_component(&quot;llm&quot;,generator)\nrag_pipeline.add_component(&quot;answer_builder&quot;, AnswerBuilder())\n\n# Connect RAG components\nrag_pipeline.connect(&quot;query_embedder&quot;, &quot;retriever.query_embedding&quot;)\nrag_pipeline.connect(&quot;retriever.documents&quot;, &quot;prompt_builder.documents&quot;)\nrag_pipeline.connect(&quot;prompt_builder.prompt&quot;, &quot;llm.prompt&quot;)\nrag_pipeline.connect(&quot;llm.replies&quot;, &quot;answer_builder.replies&quot;)\nrag_pipeline.connect(&quot;llm.meta&quot;, &quot;answer_builder.meta&quot;)\nrag_pipeline.connect(&quot;retriever&quot;, &quot;answer_builder.documents&quot;)\n\nprint(&quot;Successfully created RAG pipeline&quot;)\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s test our RAG system by performing a semantic search on a sample query. In this example, we&#8217;ll use a question about Pep Guardiola&#8217;s reaction to Manchester City&#8217;s recent form. The RAG system will:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Process the natural language query<\/li>\n\n\n<li>Search through our document store for relevant information<\/li>\n\n\n<li>Retrieve the most semantically similar documents<\/li>\n\n\n<li>Generate a comprehensive response using the LLM<\/li>\n\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">This demonstrates how our system combines the power of vector search with language model capabilities to provide accurate, contextual answers based on the information in our database.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Note:<\/strong> By default, without any Hyperscale or Composite Vector Index, Couchbase falls back to linear brute-force search that compares the query vector against every document in the collection. This works for small datasets but can become slow as the dataset grows.<\/p>\n\n\n\n<pre class=\"wp-block-code language-python\"><code># Sample query from the dataset\n\nquery = &quot;What is latest news on the death of Charles Breslin?&quot;\n\ntry:\n    # Perform the semantic search using the RAG pipeline\n    start_time = time.time()\n    result = rag_pipeline.run({\n        &quot;query_embedder&quot;: {&quot;text&quot;: query},\n        &quot;retriever&quot;: {&quot;top_k&quot;: 5},\n        &quot;prompt_builder&quot;: {&quot;question&quot;: query},\n        &quot;answer_builder&quot;: {&quot;query&quot;: query},\n        },\n     include_outputs_from={&quot;retriever&quot;, &quot;query_embedder&quot;}\n    )\n    search_elapsed_time = time.time() - start_time\n    # Get the generated answer\n    answer: GeneratedAnswer = result[&quot;answer_builder&quot;][&quot;answers&quot;][0]\n\n    # Print retrieved documents\n    print(&quot;=== Retrieved Documents ===&quot;)\n    retrieved_docs = result[&quot;retriever&quot;][&quot;documents&quot;]\n    for idx, doc in enumerate(retrieved_docs, start=1):\n        print(f&quot;Id: {doc.id} Title: {doc.meta[&#039;title&#039;]}&quot;)\n\n    # Print final results\n    print(&quot;n=== Final Answer ===&quot;)\n    print(f&quot;Question: {answer.query}&quot;)\n    print(f&quot;Answer: {answer.data}&quot;)\n    print(&quot;nSources:&quot;)\n    for doc in answer.documents:\n        print(f&quot;-&gt; {doc.meta[&#039;title&#039;]}&quot;)\n    # Display search results\n    print(f&quot;nLinear Vector Search Results (completed in {search_elapsed_time:.2f} seconds):&quot;)\n    #print(result[&quot;generator&quot;][&quot;replies&quot;][0])\n\nexcept Exception as e:\n    raise RuntimeError(f&quot;Error performing RAG search: {e}&quot;)\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">While the above RAG system works effectively, you can significantly improve query performance by enabling Couchbase Capella&#8217;s Hyperscale or Composite Vector Indexes.<\/p>\n\n\n\n<h3 id=\"h-hyperscale-vector-indexes\" class=\"wp-block-heading\">Hyperscale Vector Indexes<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Specifically designed for vector searches<\/li>\n\n\n<li>Perform vector similarity and semantic searches faster than other index types<\/li>\n\n\n<li>Scale to billions of vectors while keeping most of the structure in an optimized on-disk format<\/li>\n\n\n<li>Maintain high accuracy even for vectors with a large number of dimensions<\/li>\n\n\n<li>Support concurrent searches and inserts for constantly changing datasets<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Use this type of index when you primarily query vector values and need low-latency similarity search at scale. In general, Hyperscale Vector Indexes are the best starting point for most vector search workloads.<\/p>\n\n\n\n<h3 id=\"h-composite-vector-indexes\" class=\"wp-block-heading\">Composite Vector Indexes<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Combine scalar filters with a single vector column in the same index definition<\/li>\n\n\n<li>Designed for searches that apply one vector value alongside scalar attributes that remove large portions of the dataset before similarity scoring<\/li>\n\n\n<li>Consume a moderate amount of memory and can index Tens of million to billion of documents<\/li>\n\n\n<li>Excel when your queries must return a small, highly targeted result set<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Use Composite Vector Indexes when you want to perform searches that blend scalar predicates and vector similarity so that the scalar filters tighten the candidate set.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For an in-depth comparison and tuning guidance, review the <a href=\"https:\/\/docs.couchbase.com\/cloud\/vector-index\/use-vector-indexes.html\">Couchbase vector index documentation<\/a> and the <a href=\"https:\/\/docs.couchbase.com\/cloud\/vector-index\/vectors-and-indexes-overview.html\">overview of Capella vector indexes<\/a>.<\/p>\n\n\n\n<h3 id=\"h-understanding-index-configuration-couchbase-8-0-feature\" class=\"wp-block-heading\">Understanding Index Configuration (Couchbase 8.0 Feature)<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>index_description<\/code> parameter controls how Couchbase optimizes vector storage and search performance through centroids and quantization:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Format: <code>'IVF[&lt;centroids&gt;],{PQ|SQ}&lt;settings&gt;'<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Centroids (IVF &#8211; Inverted File):<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Controls how the dataset is subdivided for faster searches<\/li>\n\n\n<li>More centroids = faster search, slower training<\/li>\n\n\n<li>Fewer centroids = slower search, faster training<\/li>\n\n\n<li>If omitted (like <code>IVF,SQ8<\/code>), Couchbase auto-selects based on dataset size<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Quantization Options:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>SQ (Scalar Quantization): <code>SQ4<\/code>, <code>SQ6<\/code>, <code>SQ8<\/code> (4, 6, or 8 bits per dimension)<\/li>\n\n\n<li>PQ (Product Quantization): <code>PQ&lt;subquantizers&gt;x&lt;bits&gt;<\/code> (e.g., <code>PQ32x8<\/code>)<\/li>\n\n\n<li>Higher values = better accuracy, larger index size<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Common Examples:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>IVF,SQ8<\/code> \u2013 Auto centroids, 8-bit scalar quantization (good default)<\/li>\n\n\n<li><code>IVF1000,SQ6<\/code> \u2013 1000 centroids, 6-bit scalar quantization<\/li>\n\n\n<li><code>IVF,PQ32x8<\/code> \u2013 Auto centroids, 32 subquantizers with 8 bits<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">For detailed configuration options, see the <a href=\"https:\/\/docs.couchbase.com\/server\/current\/vector-index\/hyperscale-vector-index.html#algo_settings\">Quantization &amp; Centroid Settings<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In the code below, we demonstrate creating a Hyperscale index for optimal performance. You can adapt the same flow to create a COMPOSITE index by replacing the index type and options.<\/p>\n\n\n\n<pre class=\"wp-block-code language-python\"><code># Create a Hyperscale Vector Index for optimized vector search\ntry:\n    hyperscale_index_name = f&quot;{INDEX_NAME}_hyperscale&quot;\n\n    # Use the cluster connection to create the Hyperscale index\n    scope = cluster.bucket(CB_BUCKET_NAME).scope(SCOPE_NAME)\n    \n    options = {\n        &quot;dimension&quot;: 3072,  # text-embedding-3-large dimension\n        &quot;similarity&quot;: &quot;L2&quot;,\n    }\n    \n    scope.query(\n        f&quot;&quot;&quot;\n        CREATE VECTOR INDEX {hyperscale_index_name}\n        ON {COLLECTION_NAME} (embedding VECTOR)\n        WITH {json.dumps(options)}\n        &quot;&quot;&quot;,\n    QueryOptions(\n        timeout=timedelta(seconds=300)\n    )).execute()\n    print(f&quot;Successfully created Hyperscale index: {hyperscale_index_name}&quot;)\nexcept Exception as e:\n    print(f&quot;Hyperscale index may already exist or error occurred: {str(e)}&quot;)\n\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The example below runs the same RAG query, but now uses the Hyperscale index created above. You&#8217;ll notice improved performance as the index efficiently retrieves data. If you create a Composite index, the workflow is identical \u2014 Haystack automatically routes queries through the scalar filters before performing the vector similarity search.<\/p>\n\n\n\n<pre class=\"wp-block-code language-python\"><code># Test the optimized Hyperscale vector search\nquery = &quot;What is latest news on the death of Charles Breslin?&quot;\n\ntry:\n    # The RAG pipeline will automatically use the optimized Hyperscale index\n    # Perform the semantic search with Hyperscale optimization\n    start_time = time.time()\n    result = rag_pipeline.run({\n        &quot;query_embedder&quot;: {&quot;text&quot;: query},\n        &quot;retriever&quot;: {&quot;top_k&quot;: 4},\n        &quot;prompt_builder&quot;: {&quot;question&quot;: query},\n        &quot;answer_builder&quot;: {&quot;query&quot;: query},\n        },\n     include_outputs_from={&quot;retriever&quot;, &quot;query_embedder&quot;}\n    )\n    search_elapsed_time = time.time() - start_time\n    # Get the generated answer\n    answer: GeneratedAnswer = result[&quot;answer_builder&quot;][&quot;answers&quot;][0]\n\n    # Print retrieved documents\n    print(&quot;=== Retrieved Documents ===&quot;)\n    retrieved_docs = result[&quot;retriever&quot;][&quot;documents&quot;]\n    for idx, doc in enumerate(retrieved_docs, start=0):\n        print(f&quot;Id: {doc.id} Title: {doc.meta[&#039;title&#039;]}&quot;)\n\n    # Print final results\n    print(&quot;n=== Final Answer ===&quot;)\n    print(f&quot;Question: {answer.query}&quot;)\n    print(f&quot;Answer: {answer.data}&quot;)\n    print(&quot;nSources:&quot;)\n    for doc in answer.documents:\n        print(f&quot;-&gt; {doc.meta[&#039;title&#039;]}&quot;)\n    # Display search results\n    print(f&quot;nOptimized Hyperscale Vector Search Results (completed in {search_elapsed_time:.2f} seconds):&quot;)\n    #print(result[&quot;generator&quot;][&quot;replies&quot;][0])\n\nexcept Exception as e:\n    raise RuntimeError(f&quot;Error performing optimized semantic search: {e}&quot;)\n\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">In this tutorial, we&#8217;ve built a Retrieval Augmented Generation (RAG) system using Haystack with OpenAI models and Couchbase Capella&#8217;s Hyperscale and Composite Vector Indexes. Using the BBC News dataset, we demonstrated how modern vector indexes make it possible to answer up-to-date questions that extend beyond an LLM&#8217;s original training data.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The key components of our RAG system include:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Couchbase Capella Hyperscale &amp; Composite Vector Indexes<\/strong> for high-performance storage and retrieval of document embeddings<\/li>\n\n\n<li><strong>Haystack<\/strong> as the framework for building modular RAG pipelines with flexible component connections<\/li>\n\n\n<li><strong>OpenAI Services<\/strong> for generating embeddings (<code>text-embedding-3-large<\/code>) and LLM responses (<code>gpt-4o<\/code>)<\/li>\n\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">This approach grounds LLM responses in specific, current information from our knowledge base while taking advantage of Couchbase&#8217;s advanced vector index options for performance and scale. Haystack&#8217;s modular pipeline model keeps the solution extensible as you layer in additional data sources or services.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>View Source In this guide, we will walk you through building a Retrieval Augmented Generation (RAG) application with Haystack orchestrating OpenAI models and Couchbase Capella. We will use the gpt-4o model for response generation and the text-embedding-3-large model for generating embeddings. This notebook demonstrates how to build a RAG system using: We leverage Couchbase&#8217;s Hyperscale and Composite Vector Indexes to enable efficient semantic search at scale. Hyperscale indexes prioritize high-throughput vector similarity across billions of vectors with a compact on-disk footprint, while Composite indexes blend scalar predicates with a vector column to narrow candidate sets before similarity search. For a deeper dive into how these indexes work, see the overview [&hellip;]<\/p>\n","protected":false},"author":0,"featured_media":0,"menu_order":0,"template":"","meta":{"_acf_changed":false,"_acf":"","inline_featured_image":false,"footnotes":""},"tutorial-languages":[606],"tutorial-tags":[607,612,620,611,609],"tutorial-technologies":[613],"tutorial-types":[555],"class_list":["post-10287","tutorials","type-tutorials","status-publish","hentry","tutorial-languages-python","tutorial-tags-artificial-intelligence","tutorial-tags-composite-vector-index","tutorial-tags-haystack","tutorial-tags-hyperscale-vector-index","tutorial-tags-openai","tutorial-technologies-vector-search","tutorial-types-tutorial"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v28.9 (Yoast SEO v28.9) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>RAG with OpenAI, Haystack, and Couchbase Hyperscale &amp; Composite Vector Indexes - Couchbase<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.couchbase.com\/ja\/developers\/tutorials\/openai-haystack-rag-with-hyperscale-or-composite-vector-index\/\" \/>\n<meta property=\"og:locale\" content=\"ja_JP\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"RAG with OpenAI, Haystack, and Couchbase Hyperscale &amp; Composite Vector Indexes\" \/>\n<meta property=\"og:description\" content=\"View Source In this guide, we will walk you through building a Retrieval Augmented Generation (RAG) application with Haystack orchestrating OpenAI models and Couchbase Capella. We will use the gpt-4o model for response generation and the text-embedding-3-large model for generating embeddings. This notebook demonstrates how to build a RAG system using: We leverage Couchbase&#8217;s Hyperscale and Composite Vector Indexes to enable efficient semantic search at scale. Hyperscale indexes prioritize high-throughput vector similarity across billions of vectors with a compact on-disk footprint, while Composite indexes blend scalar predicates with a vector column to narrow candidate sets before similarity search. For a deeper dive into how these indexes work, see the overview [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.couchbase.com\/ja\/developers\/tutorials\/openai-haystack-rag-with-hyperscale-or-composite-vector-index\/\" \/>\n<meta property=\"og:site_name\" content=\"Couchbase\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/Couchbase\/\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.couchbase.com\/wp-content\/uploads\/2026\/10\/Cloud-2.png\" \/>\n\t<meta property=\"og:image:width\" content=\"2548\" \/>\n\t<meta property=\"og:image:height\" content=\"1171\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:site\" content=\"@couchbase\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"20\u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/ja\\\/developers\\\/tutorials\\\/openai-haystack-rag-with-hyperscale-or-composite-vector-index\\\/\",\"url\":\"https:\\\/\\\/www.couchbase.com\\\/ja\\\/developers\\\/tutorials\\\/openai-haystack-rag-with-hyperscale-or-composite-vector-index\\\/\",\"name\":\"RAG with OpenAI, Haystack, and Couchbase Hyperscale & Composite Vector Indexes - Couchbase\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/ja\\\/#website\"},\"datePublished\":\"2025-12-09T10:13:28+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/ja\\\/developers\\\/tutorials\\\/openai-haystack-rag-with-hyperscale-or-composite-vector-index\\\/#breadcrumb\"},\"inLanguage\":\"ja\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.couchbase.com\\\/ja\\\/developers\\\/tutorials\\\/openai-haystack-rag-with-hyperscale-or-composite-vector-index\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/ja\\\/developers\\\/tutorials\\\/openai-haystack-rag-with-hyperscale-or-composite-vector-index\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.couchbase.com\\\/ko\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"RAG with OpenAI, Haystack, and Couchbase Hyperscale &#038; Composite Vector Indexes\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/ja\\\/#website\",\"url\":\"https:\\\/\\\/www.couchbase.com\\\/ja\\\/\",\"name\":\"Couchbase\",\"description\":\"The Operational Data Platform for AI\u2122\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/ja\\\/#organization\"},\"alternateName\":\"Couchbase, Inc.\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.couchbase.com\\\/ja\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"ja\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/ja\\\/#organization\",\"name\":\"Couchbase\",\"alternateName\":\"Couchbase, Inc.\",\"url\":\"https:\\\/\\\/www.couchbase.com\\\/ja\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ja\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/ja\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.couchbase.com\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/Couchbase_Logo_Couchbase_Token_Red-1.png\",\"contentUrl\":\"https:\\\/\\\/www.couchbase.com\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/Couchbase_Logo_Couchbase_Token_Red-1.png\",\"width\":1129,\"height\":1129,\"caption\":\"Couchbase\"},\"image\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/ja\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/Couchbase\\\/\",\"https:\\\/\\\/x.com\\\/couchbase\",\"https:\\\/\\\/www.youtube.com\\\/c\\\/CouchbaseServer\",\"https:\\\/\\\/www.linkedin.com\\\/company\\\/couchbase\\\/\",\"https:\\\/\\\/github.com\\\/couchbase\\\/\",\"https:\\\/\\\/en.wikipedia.org\\\/wiki\\\/Couchbase,_Inc.\"],\"description\":\"Couchbase is a database software company headquartered in San Jose, California, providing an operational data platform for AI used by hundreds of global enterprises.\",\"legalName\":\"Couchbase, Inc.\",\"foundingDate\":\"2011-01-01\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"RAG with OpenAI, Haystack, and Couchbase Hyperscale & Composite Vector Indexes - Couchbase","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.couchbase.com\/ja\/developers\/tutorials\/openai-haystack-rag-with-hyperscale-or-composite-vector-index\/","og_locale":"ja_JP","og_type":"article","og_title":"RAG with OpenAI, Haystack, and Couchbase Hyperscale & Composite Vector Indexes","og_description":"View Source In this guide, we will walk you through building a Retrieval Augmented Generation (RAG) application with Haystack orchestrating OpenAI models and Couchbase Capella. We will use the gpt-4o model for response generation and the text-embedding-3-large model for generating embeddings. This notebook demonstrates how to build a RAG system using: We leverage Couchbase&#8217;s Hyperscale and Composite Vector Indexes to enable efficient semantic search at scale. Hyperscale indexes prioritize high-throughput vector similarity across billions of vectors with a compact on-disk footprint, while Composite indexes blend scalar predicates with a vector column to narrow candidate sets before similarity search. For a deeper dive into how these indexes work, see the overview [&hellip;]","og_url":"https:\/\/www.couchbase.com\/ja\/developers\/tutorials\/openai-haystack-rag-with-hyperscale-or-composite-vector-index\/","og_site_name":"Couchbase","article_publisher":"https:\/\/www.facebook.com\/Couchbase\/","og_image":[{"width":2548,"height":1171,"url":"https:\/\/www.couchbase.com\/wp-content\/uploads\/2026\/10\/Cloud-2.png","type":"image\/png"}],"twitter_card":"summary_large_image","twitter_site":"@couchbase","twitter_misc":{"Est. reading time":"20\u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.couchbase.com\/ja\/developers\/tutorials\/openai-haystack-rag-with-hyperscale-or-composite-vector-index\/","url":"https:\/\/www.couchbase.com\/ja\/developers\/tutorials\/openai-haystack-rag-with-hyperscale-or-composite-vector-index\/","name":"RAG with OpenAI, Haystack, and Couchbase Hyperscale & Composite Vector Indexes - Couchbase","isPartOf":{"@id":"https:\/\/www.couchbase.com\/ja\/#website"},"datePublished":"2025-12-09T10:13:28+00:00","breadcrumb":{"@id":"https:\/\/www.couchbase.com\/ja\/developers\/tutorials\/openai-haystack-rag-with-hyperscale-or-composite-vector-index\/#breadcrumb"},"inLanguage":"ja","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.couchbase.com\/ja\/developers\/tutorials\/openai-haystack-rag-with-hyperscale-or-composite-vector-index\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.couchbase.com\/ja\/developers\/tutorials\/openai-haystack-rag-with-hyperscale-or-composite-vector-index\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.couchbase.com\/ko\/"},{"@type":"ListItem","position":2,"name":"RAG with OpenAI, Haystack, and Couchbase Hyperscale &#038; Composite Vector Indexes"}]},{"@type":"WebSite","@id":"https:\/\/www.couchbase.com\/ja\/#website","url":"https:\/\/www.couchbase.com\/ja\/","name":"Couchbase","description":"The Operational Data Platform for AI\u2122","publisher":{"@id":"https:\/\/www.couchbase.com\/ja\/#organization"},"alternateName":"Couchbase, Inc.","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.couchbase.com\/ja\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"ja"},{"@type":"Organization","@id":"https:\/\/www.couchbase.com\/ja\/#organization","name":"Couchbase","alternateName":"Couchbase, Inc.","url":"https:\/\/www.couchbase.com\/ja\/","logo":{"@type":"ImageObject","inLanguage":"ja","@id":"https:\/\/www.couchbase.com\/ja\/#\/schema\/logo\/image\/","url":"https:\/\/www.couchbase.com\/wp-content\/uploads\/2026\/11\/Couchbase_Logo_Couchbase_Token_Red-1.png","contentUrl":"https:\/\/www.couchbase.com\/wp-content\/uploads\/2026\/11\/Couchbase_Logo_Couchbase_Token_Red-1.png","width":1129,"height":1129,"caption":"Couchbase"},"image":{"@id":"https:\/\/www.couchbase.com\/ja\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/Couchbase\/","https:\/\/x.com\/couchbase","https:\/\/www.youtube.com\/c\/CouchbaseServer","https:\/\/www.linkedin.com\/company\/couchbase\/","https:\/\/github.com\/couchbase\/","https:\/\/en.wikipedia.org\/wiki\/Couchbase,_Inc."],"description":"Couchbase\u306f\u30ab\u30ea\u30d5\u30a9\u30eb\u30cb\u30a2\u5dde\u30b5\u30f3\u30ce\u30bc\u306b\u672c\u793e\u3092\u7f6e\u304f\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u30bd\u30d5\u30c8\u30a6\u30a7\u30a2\u4f01\u696d\u3067\u3001\u6570\u767e\u306e\u30b0\u30ed\u30fc\u30d0\u30eb\u4f01\u696d\u304c\u4f7f\u7528\u3059\u308bAI\u7528\u306e\u904b\u7528\u30c7\u30fc\u30bf\u30d7\u30e9\u30c3\u30c8\u30d5\u30a9\u30fc\u30e0\u3092\u63d0\u4f9b\u3057\u3066\u3044\u307e\u3059\u3002.","legalName":"Couchbase, Inc.","foundingDate":"2011-01-01"}]}},"permalink_manager":null,"_links":{"self":[{"href":"https:\/\/www.couchbase.com\/ja\/wp-json\/wp\/v2\/tutorials\/10287","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.couchbase.com\/ja\/wp-json\/wp\/v2\/tutorials"}],"about":[{"href":"https:\/\/www.couchbase.com\/ja\/wp-json\/wp\/v2\/types\/tutorials"}],"version-history":[{"count":0,"href":"https:\/\/www.couchbase.com\/ja\/wp-json\/wp\/v2\/tutorials\/10287\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.couchbase.com\/ja\/wp-json\/wp\/v2\/media?parent=10287"}],"wp:term":[{"taxonomy":"tutorial-languages","embeddable":true,"href":"https:\/\/www.couchbase.com\/ja\/wp-json\/wp\/v2\/tutorial-languages?post=10287"},{"taxonomy":"tutorial-tags","embeddable":true,"href":"https:\/\/www.couchbase.com\/ja\/wp-json\/wp\/v2\/tutorial-tags?post=10287"},{"taxonomy":"tutorial-technologies","embeddable":true,"href":"https:\/\/www.couchbase.com\/ja\/wp-json\/wp\/v2\/tutorial-technologies?post=10287"},{"taxonomy":"tutorial-types","embeddable":true,"href":"https:\/\/www.couchbase.com\/ja\/wp-json\/wp\/v2\/tutorial-types?post=10287"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}