{"id":10340,"date":"2025-11-30T21:49:45","date_gmt":"2025-12-01T05:49:45","guid":{"rendered":"https:\/\/www.couchbase.com\/developers\/tutorials\/python-haystack-pdf-chat-with-hyperscale-index\/"},"modified":"2025-11-30T21:49:45","modified_gmt":"2025-12-01T05:49:45","slug":"python-haystack-pdf-chat-with-hyperscale-index","status":"publish","type":"tutorials","link":"https:\/\/www.couchbase.com\/de\/developers\/tutorials\/python-haystack-pdf-chat-with-hyperscale-index\/","title":{"rendered":"Build PDF Chat App With Haystack, OpenAI and Couchbase Hyperscale Vector Index"},"content":{"rendered":"\n<h3 id=\"h-introduction\" class=\"wp-block-heading\">Introduction<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Welcome to this comprehensive guide on constructing an AI-enhanced Chat Application using <strong>Couchbase&#8217;s Hyperscale Vector Index<\/strong>. We will create a dynamic chat interface capable of delving into PDF documents to extract and provide summaries, key facts, and answers to your queries. By the end of this tutorial, you&#8217;ll have a powerful tool at your disposal, transforming the way you interact with and utilize the information contained within PDFs.<\/p>\n\n\n\n<h4 id=\"h-choosing-between-hyperscale-and-composite-vector-indexes\" class=\"wp-block-heading\">Choosing Between Hyperscale and Composite Vector Indexes<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Couchbase supports multiple types of vector indexes for different use cases. This tutorial uses <strong>Hyperscale Vector Index<\/strong>, but you should be aware of the alternatives:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Hyperscale Vector Index<\/strong> (used in this tutorial):<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Best for <strong>pure vector similarity search<\/strong> at massive scale<\/li>\n\n\n<li>Optimized for RAG and chatbot applications<\/li>\n\n\n<li>Handles billions of documents with sub-second query latency<\/li>\n\n\n<li>Ideal when you need fast semantic search without metadata filtering<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Composite Vector Index<\/strong>:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Best for <strong>vector search with metadata filtering<\/strong><\/li>\n\n\n<li>Combines vector fields with scalar fields (e.g., date, category, user_id)<\/li>\n\n\n<li>Enables pre-filtering before vector search for more efficient queries<\/li>\n\n\n<li>Ideal when you need to filter documents by attributes before semantic search<\/li>\n\n\n<li>Example use case: &#8220;Find similar documents from last month&#8221; or &#8220;Search within user&#8217;s documents&#8221;<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Search Vector Index<\/strong>:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Best for <strong>hybrid search<\/strong> combining keywords, geospatial, and semantic search<\/li>\n\n\n<li>Flexible full-text search combined with vector similarity<\/li>\n\n\n<li>Complex filtering using FTS queries<\/li>\n\n\n<li>Compatible with Couchbase 7.6+<\/li>\n\n<\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\"><strong>For this PDF chat demo, we use Hyperscale Vector Index<\/strong> for optimal performance in pure RAG applications. If your use case requires filtering by metadata (e.g., searching only in specific user&#8217;s documents, or documents from a certain date range), consider using Composite Vector Index instead.<\/p>\n<\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\">To learn more about choosing the right vector index, refer to the <a href=\"https:\/\/docs.couchbase.com\/cloud\/vector-index\/use-vector-indexes.html\">official Couchbase vector index documentation<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This tutorial will demonstrate how to:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Create a <a href=\"https:\/\/docs.couchbase.com\/cloud\/vector-index\/hyperscale-vector-index.html\">Couchbase Hyperscale Vector Index<\/a> for high-performance Vector Search.<\/li>\n\n\n<li>Chunk PDFs into Vectors with <a href=\"https:\/\/haystack.deepset.ai\/\">Haystack<\/a> and use <a href=\"https:\/\/haystack.deepset.ai\/integrations\/couchbase-document-store\">Couchbase Vector Store<\/a> to store the vectors into Couchbase.<\/li>\n\n\n<li>Use large language models via the <a href=\"https:\/\/aws.amazon.com\/what-is\/retrieval-augmented-generation\/\">RAG framework<\/a> for contextual insights. We will use <a href=\"https:\/\/openai.com\">OpenAI<\/a> for generating Embeddings and querying the LLM.<\/li>\n\n\n<li>Automatically create Hyperscale vector index after document upload.<\/li>\n\n\n<li>Use a Streamlit interface to see it working in action. All these components come together to create a seamless, AI-powered chat experience.<\/li>\n\n<\/ul>\n\n\n\n<h3 id=\"h-prerequisites\" class=\"wp-block-heading\">Prerequisites<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.python.org\/downloads\/\">Python<\/a> 3.10 or higher installed.<\/li>\n\n\n<li>Ensure that the Python version is <a href=\"https:\/\/docs.couchbase.com\/python-sdk\/current\/project-docs\/compatibility.html#python-version-compat\">compatible<\/a> with the Couchbase SDK.<\/li>\n\n\n<li>Couchbase Cluster (Self Managed or Capella) version <strong>8.0+<\/strong>. Hyperscale Vector Index is recommended for Couchbase 8.0+.<\/li>\n\n\n<li><a href=\"https:\/\/streamlit.io\/\">Streamlit<\/a> installed via pip install streamlit.<\/li>\n\n<\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">Note that this tutorial is designed to work with the latest Couchbase-haystack SDK version (2.1.0+). It will not work with the older versions.<\/p>\n<\/blockquote>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\"><strong>Important<\/strong>: This tutorial uses Hyperscale vector index, which are optimized for high-performance vector search at scale. For Couchbase 7.6+, consider using the Search Vector Index based approach instead.<\/p>\n<\/blockquote>\n\n\n\n<h3 id=\"h-quick-start-guide\" class=\"wp-block-heading\">Quick Start Guide:<\/h3>\n\n\n\n<h4 id=\"h-cloning-repo\" class=\"wp-block-heading\">Cloning Repo<\/h4>\n\n\n\n<pre class=\"wp-block-code language-shell\"><code>git clone https:\/\/github.com\/couchbase-examples\/haystack-demo.git\n<\/code><\/pre>\n\n\n\n<h4 id=\"h-install-dependencies\" class=\"wp-block-heading\">Install Dependencies<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Any dependencies should be installed through <code>pip<\/code>, the default package manager for Python. You may use <a href=\"https:\/\/docs.python.org\/3\/tutorial\/venv.html\">virtual environment<\/a> as well.<\/p>\n\n\n\n<pre class=\"wp-block-code language-shell\"><code>python -m pip install -r requirements.txt\n<\/code><\/pre>\n\n\n\n<h4 id=\"h-setup-database-configuration\" class=\"wp-block-heading\">Setup Database Configuration<\/h4>\n\n\n\n<h5 id=\"h-capella-setup\" class=\"wp-block-heading\">Capella Setup<\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">To know more about connecting to your Capella cluster, please follow the <a href=\"https:\/\/docs.couchbase.com\/cloud\/get-started\/connect.html\">instructions<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Specifically, you need to do the following:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Create the <a href=\"https:\/\/docs.couchbase.com\/cloud\/clusters\/manage-database-users.html\">database credentials<\/a> to access cluster via SDK<\/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<h5 id=\"h-self-managed-setup\" class=\"wp-block-heading\">Self Managed Setup<\/h5>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Follow <a href=\"\/tutorial-couchbase-installation-options\">Couchbase Installation Options<\/a> for installing the latest Couchbase Database Server Instance.<\/li>\n\n<\/ul>\n\n\n\n<h4 id=\"h-create-bucket\" class=\"wp-block-heading\">Create Bucket<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>For this tutorial, we will use a specific bucket, scope, and collection. However, you may use any name of your choice but make sure to update names in all the steps.<\/li>\n\n\n<li>Create a bucket named <code>sample-bucket<\/code>. We will use the <code>pdf_data<\/code> scope and <code>pdf_chunks<\/code> collection of this bucket.<\/li>\n\n<\/ul>\n\n\n\n<h4 id=\"h-automatic-hyperscale-vector-index-creation\" class=\"wp-block-heading\">Automatic Hyperscale Vector Index Creation<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Good news!<\/strong> The application automatically creates the Hyperscale vector index <strong>after you upload your first PDF<\/strong>. This is because Hyperscale indexes require training data (documents with embeddings) to be created successfully.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The application will:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Upload and process your PDF documents<\/li>\n\n\n<li>Generate embeddings for document chunks<\/li>\n\n\n<li>Store the documents with embeddings in Couchbase<\/li>\n\n\n<li>Automatically create the Hyperscale vector index using SQL++<\/li>\n\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>No manual index creation required!<\/strong> The index is created with the following configuration:<\/p>\n\n\n\n<pre class=\"wp-block-code language-sql\"><code>CREATE VECTOR INDEX idx_&lt;collection_name&gt;_vector\nON `&lt;bucket_name&gt;`.`&lt;scope_name&gt;`.`&lt;collection_name&gt;`(embedding VECTOR) \nWITH {\n  &quot;dimension&quot;: 1536,\n  &quot;similarity&quot;: &quot;DOT&quot;\n}\n<\/code><\/pre>\n\n\n\n<h5 id=\"h-index-parameters\" class=\"wp-block-heading\">Index Parameters<\/h5>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Vector field<\/strong>: <code>embedding<\/code> with 1536 dimensions (matching OpenAI&#8217;s text-embedding-ada-002\/003 models)<\/li>\n\n\n<li><strong>Similarity metric<\/strong>: <code>DOT<\/code> for dot product similarity (optimized for OpenAI embeddings)<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">The application uses <code>CouchbaseQueryDocumentStore<\/code> which leverages SQL++ queries with the <code>APPROX_VECTOR_DISTANCE()<\/code> function for fast approximate nearest neighbor (ANN) search.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\"><strong>Note<\/strong>: If automatic creation fails, the application will attempt to create the index on first query as a fallback. If you prefer manual control, you can create the index yourself using the SQL++ query above after uploading documents.<\/p>\n<\/blockquote>\n\n\n\n<h5 id=\"h-alternative-using-composite-vector-index\" class=\"wp-block-heading\">Alternative: Using Composite Vector Index<\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">If your application needs to filter documents by metadata before performing vector search, you can use a <strong>Composite Vector Index<\/strong> instead. The same code works with minimal changes!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Creating a Composite Vector Index:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code language-sql\"><code>CREATE INDEX idx_&lt;collection_name&gt;_composite \nON `&lt;bucket_name&gt;`.`&lt;scope_name&gt;`.`&lt;collection_name&gt;`(embedding VECTOR) \nWITH {\n  &quot;dimension&quot;: 1536,\n  &quot;similarity&quot;: &quot;DOT&quot;\n}\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Key Difference<\/strong>: Notice the keyword is <code>INDEX<\/code> (not <code>VECTOR INDEX<\/code>). Composite indexes combine vector fields with other scalar fields.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>When to Use Composite Vector Index:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>You need to filter by metadata (e.g., <code>user_id<\/code>, <code>date<\/code>, <code>category<\/code>) before vector search<\/li>\n\n\n<li>Example: &#8220;Find similar documents uploaded by user X in the last 30 days&#8221;<\/li>\n\n\n<li>Enables efficient pre-filtering to reduce the search space<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Code Compatibility:<\/strong>\nThe same <code>CouchbaseQueryDocumentStore<\/code> and application code works with both Hyperscale and Composite indexes! The only difference is:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>The SQL++ statement used to create the index<\/li>\n\n\n<li>How you query it (Composite allows WHERE clauses for filtering)<\/li>\n\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">To learn more about Composite Vector Indexes, refer to the <a href=\"https:\/\/docs.couchbase.com\/cloud\/vector-index\/composite-vector-index.html\">official documentation<\/a>.<\/p>\n\n\n\n<h4 id=\"h-setup-environment-config\" class=\"wp-block-heading\">Setup Environment Config<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Copy the <code>secrets.example.toml<\/code> file in <code>.streamlit<\/code> folder and rename it to <code>secrets.toml<\/code> and replace the placeholders with the actual values for your environment. All configuration for communication with the database is read from the environment variables.<\/p>\n\n\n\n<pre class=\"wp-block-code language-bash\"><code>DB_CONN_STR = &quot;&lt;couchbase_cluster_connection_string&gt;&quot;\nDB_USERNAME = &quot;&lt;couchbase_username&gt;&quot;\nDB_PASSWORD = &quot;&lt;couchbase_password&gt;&quot;\nDB_BUCKET = &quot;&lt;bucket_name&gt;&quot;\nDB_SCOPE = &quot;&lt;scope_name&gt;&quot;\nDB_COLLECTION = &quot;&lt;collection_name&gt;&quot;\nOPENAI_API_KEY = &quot;&lt;openai_api_key&gt;&quot;\n<\/code><\/pre>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/openai.com\">OpenAI<\/a> API Key is required for usage in generating embedding and querying LLM.<\/p>\n<\/blockquote>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">The <a href=\"https:\/\/docs.couchbase.com\/python-sdk\/current\/howtos\/managing-connections.html#connection-strings\">connection string<\/a> expects the <code>couchbases:\/\/<\/code> or <code>couchbase:\/\/<\/code> part.<\/p>\n<\/blockquote>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">For this tutorial, <code>DB_BUCKET = sample-bucket<\/code>, <code>DB_SCOPE = pdf_data<\/code>, <code>DB_COLLECTION = pdf_chunks<\/code>.<\/p>\n<\/blockquote>\n\n\n\n<h4 id=\"h-running-the-application\" class=\"wp-block-heading\">Running the Application<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">After starting Couchbase server and installing dependencies, our application is ready to run. The application will automatically create the scope and collection on startup.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In the projects root directory, run the following command<\/p>\n\n\n\n<pre class=\"wp-block-code language-sh\"><code>streamlit run chat_with_pdf_with_query_vector_index.py\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The application will run on your local machine at <a href=\"http:\/\/localhost:8501\">http:\/\/localhost:8501<\/a>.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\"><strong>Important<\/strong>: Upload a PDF first! The Hyperscale vector index will be automatically created after you upload and process your first PDF document. The index creation requires training data (documents with embeddings) to work properly.<\/p>\n<\/blockquote>\n\n\n\n<h4 id=\"h-using-pdf-chat-app\" class=\"wp-block-heading\">Using PDF Chat App<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">On the left sidebar, you&#8217;ll find an option to upload a PDF document you want to use with this PDF Chat App. Depending on the size of the PDF, the upload process may take some time.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><img decoding=\"async\" src=\"main_screen_default_view.png\" alt=\"Main Screen Default View\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In the main area, there&#8217;s a chat screen where you can ask questions about the uploaded PDF document. You will receive two responses: one with context from the PDF (Couchbase Logo &#8211; <img decoding=\"async\" src=\"image.ico\" alt=\"couchbase\" width=\"16\"> ) , and one without the PDF context (Bot Logo &#8211; \ud83e\udd16). This demonstrates how the Retrieval Augmented Generation (RAG) model enhances the answers provided by the language model using the PDF content.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><img decoding=\"async\" src=\"main_screen_message_view.png\" alt=\"Main Screen With Message View\"><\/p>\n\n\n\n<h3 id=\"h-concepts\" class=\"wp-block-heading\">Concepts<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The PDF Chat application leverages two powerful concepts: <a href=\"https:\/\/aws.amazon.com\/what-is\/retrieval-augmented-generation\/\">Retrieval-Augmented Generation (RAG)<\/a> and <a href=\"https:\/\/www.couchbase.com\/products\/vector-search\/\">Vector Search<\/a>. Together, these techniques enable efficient and context-aware interactions with PDF documents.<\/p>\n\n\n\n<h4 id=\"h-retrievalaugmented-generation-rag\" class=\"wp-block-heading\">Retrieval-Augmented Generation (RAG)<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">RAG is like having two helpers:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Retriever<\/strong>: This helper looks through all the PDF documents to find the most relevant information based on your question or prompt.<\/li>\n\n\n<li><strong>Generator<\/strong>: This helper is like a large language model (e.g., GPT-4, Gemini) that can understand natural language and generate human-like responses.<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Here&#8217;s how RAG works:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>You ask a question or provide a prompt to the app.<\/li>\n\n\n<li>The Retriever helper goes through the PDF documents and finds the most relevant passages or sections related to your question using Vector Search.<\/li>\n\n\n<li>The Generator helper takes those relevant passages and your original question, and uses them to generate a clear and contextual answer.<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">This enhances the context from PDF and LLM is able to give relevant results from the PDF rather than giving generalized results.<\/p>\n\n\n\n<h4 id=\"h-vector-search-with-couchbase-hyperscale\" class=\"wp-block-heading\">Vector Search with Couchbase Hyperscale<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Couchbase is a NoSQL database that provides a powerful Hyperscale Vector Search capability. It allows you to store and search through high-dimensional vector representations (embeddings) of textual data at massive scale.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The PDF Chat app uses Haystack to convert the text from the PDF documents into embeddings. These embeddings are then stored in a Couchbase bucket, along with the corresponding text.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">When a user asks a question or provides a prompt:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The app converts the user&#8217;s query into an embedding using Haystack&#8217;s embedding models (e.g., OpenAI&#8217;s embeddings).<\/li>\n\n\n<li><a href=\"https:\/\/docs.couchbase.com\/cloud\/vector-index\/hyperscale-vector-index.html\">Couchbase&#8217;s Hyperscale Vector Index<\/a> is utilized for high-performance vector search. The Hyperscale index is automatically created for the PDF embeddings and their corresponding text content.<\/li>\n\n\n<li>The app queries this index using SQL++ with the <code>APPROX_VECTOR_DISTANCE()<\/code> function and the user&#8217;s query embedding. Couchbase&#8217;s Hyperscale Vector Search calculates the <a href=\"https:\/\/docs.couchbase.com\/cloud\/vector-index\/vectors-and-indexes-overview.html\">similarity<\/a> (e.g., dot product) between the query embedding and the indexed PDF embeddings using approximate nearest neighbor (ANN) search, enabling ultra-fast retrieval.<\/li>\n\n\n<li>The nearest neighbor embeddings represent the most semantically similar passages or sections from the PDF documents compared to the user&#8217;s query.<\/li>\n\n\n<li>The app retrieves the text content associated with these nearest neighbor embeddings, providing the necessary context for generating a relevant response.<\/li>\n\n\n<li>Couchbase&#8217;s Hyperscale Vector Index is optimized for:\n<ul>\n<li><strong>Massive scale<\/strong>: Billions of documents with sub-second query latency<\/li>\n<li><strong>Pure vector search<\/strong>: Optimized specifically for RAG and semantic search applications<\/li>\n<li><strong>SQL++ integration<\/strong>: Leverage familiar SQL++ syntax for vector queries<\/li>\n<\/ul>\n<\/li>\n\n\n<li>The Hyperscale index facilitates fast and accurate retrieval at scale, enabling the app to provide context-aware and relevant responses to the user&#8217;s queries, even when the phrasing or terminology differs from the PDF content.<\/li>\n\n\n<li>Couchbase&#8217;s Hyperscale Vector Search integrates seamlessly with Haystack&#8217;s <code>CouchbaseQueryDocumentStore<\/code> class, abstracting away the complexities of vector similarity calculations.<\/li>\n\n<\/ul>\n\n\n\n<h4 id=\"h-haystack\" class=\"wp-block-heading\">Haystack<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Haystack is a powerful library that simplifies the process of building applications with <a href=\"https:\/\/en.wikipedia.org\/wiki\/Large_language_model\">large language models<\/a> (LLMs) and vector stores like Couchbase.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In the PDF Chat app, Haystack is used for several tasks:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Loading and processing PDF documents<\/strong>: Haystack&#8217;s <a href=\"https:\/\/docs.haystack.deepset.ai\/docs\/pypdftodocument\"><em>PyPDFToDocument<\/em><\/a> component can convert PDF files into Haystack Document objects, which can hold various types of content, including text, metadata, and embeddings.<\/li>\n\n\n<li><strong>Text preprocessing<\/strong>: Haystack&#8217;s <a href=\"https:\/\/docs.haystack.deepset.ai\/docs\/documentcleaner\"><em>DocumentCleaner<\/em><\/a> removes unwanted characters and formatting from the extracted text, while <a href=\"https:\/\/docs.haystack.deepset.ai\/docs\/documentsplitter\"><em>DocumentSplitter<\/em><\/a> splits the text from the PDF documents into smaller chunks or passages, which are more suitable for embedding and retrieval.<\/li>\n\n\n<li><strong>Embedding generation<\/strong>: Haystack&#8217;s <a href=\"https:\/\/docs.haystack.deepset.ai\/docs\/openaidocumentembedder\"><em>OpenAIDocumentEmbedder<\/em><\/a> and <a href=\"https:\/\/docs.haystack.deepset.ai\/docs\/openaitextembedder\"><em>OpenAITextEmbedder<\/em><\/a> components convert text into vector embeddings using OpenAI&#8217;s embedding models, enabling semantic search capabilities.<\/li>\n\n\n<li><strong>Text generation<\/strong>: Haystack&#8217;s <a href=\"https:\/\/docs.haystack.deepset.ai\/docs\/openaigenerator\"><em>OpenAIGenerator<\/em><\/a> component interfaces with OpenAI&#8217;s language models to generate human-like responses based on the retrieved context and user queries.<\/li>\n\n\n<li><strong>Document storage<\/strong>: Haystack&#8217;s <a href=\"https:\/\/docs.haystack.deepset.ai\/docs\/documentwriter\"><em>DocumentWriter<\/em><\/a> component handles the storage of processed documents and their embeddings into the vector store.<\/li>\n\n\n<li><strong>Vector store integration<\/strong>: Haystack provides a <a href=\"https:\/\/haystack.deepset.ai\/integrations\/couchbase-document-store\">CouchbaseDocumentStore<\/a> class that seamlessly integrates with Couchbase&#8217;s Vector Search, allowing the app to store and search through the embeddings and their corresponding text.<\/li>\n\n\n<li><strong>Pipelines<\/strong>: Haystack uses <a href=\"https:\/\/docs.haystack.deepset.ai\/docs\/pipelines\">Pipelines<\/a> to combine different components for various tasks. In this app, we have an indexing pipeline for processing and storing documents, and a RAG pipeline for retrieval and generation.<\/li>\n\n\n<li><strong>Prompt Building<\/strong>: Haystack&#8217;s <a href=\"https:\/\/docs.haystack.deepset.ai\/docs\/promptbuilder\"><em>PromptBuilder<\/em><\/a> component allows you to create custom prompts that guide the language model&#8217;s behavior and output.<\/li>\n\n\n<li><strong>Answer Building<\/strong>: Haystack&#8217;s <a href=\"https:\/\/docs.haystack.deepset.ai\/docs\/answerbuilder\"><em>AnswerBuilder<\/em><\/a> component structures the final response by combining the generated text with metadata and source information.<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">By combining Vector Search with Couchbase, RAG, and Haystack, the PDF Chat app can efficiently ingest PDF documents, convert their content into searchable embeddings, retrieve relevant information based on user queries and conversation context, and generate context-aware and informative responses using large language models.<\/p>\n\n\n\n<h3 id=\"h-let-us-understand-the-flow\" class=\"wp-block-heading\">Let us Understand the Flow<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">To begin this tutorial, clone the repo and open it up in the IDE of your choice. Now you can learn how to create the PDF Chat App. The whole code is written in <code>chat_with_pdf_with_query_vector_index.py<\/code> file.<\/p>\n\n\n\n<h4 id=\"h-app-flow\" class=\"wp-block-heading\">App Flow<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">The fundamental workflow of the application is as follows: The user initiates the process from the Main Page&#8217;s sidebar by uploading a PDF. This action triggers the <code>save_to_vector_store<\/code> function, which subsequently uploads the PDF into the Couchbase vector store. Following this, the user can now chat with the LLM.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">On the Chat Area, the user can pose questions. These inquiries are processed by the Chat API, which consults the LLM for responses, aided by the context provided by RAG. The assistant then delivers the answer, and the user has the option to ask additional questions.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><img decoding=\"async\" src=\"python_app_flow.png\" alt=\"App Flow\"><\/p>\n\n\n\n<h3 id=\"h-connecting-to-couchbase\" class=\"wp-block-heading\">Connecting to Couchbase<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The first step is connecting to Couchbase. Couchbase Hyperscale Vector Search is required for PDF Upload as well as during chat (For Retrieval). We will use the Haystack <strong>CouchbaseQueryDocumentStore<\/strong> to connect to the Couchbase cluster with Hyperscale vector search support. The connection is established in the <code>get_document_store<\/code> function.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\"><strong>Note<\/strong>: The same <code>CouchbaseQueryDocumentStore<\/code> configuration works with both <strong>Hyperscale<\/strong> and <strong>Composite<\/strong> vector indexes! You only need to change the SQL++ statement when creating the index.<\/p>\n<\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\">The connection string and credentials are read from the environment variables. We perform some basic required checks for the environment variable not being set in the <code>secrets.toml<\/code>, and then proceed to connect to the Couchbase cluster. We connect to the cluster using <a href=\"https:\/\/docs.couchbase.com\/python-sdk\/current\/hello-world\/start-using-sdk.html#connect\">connect<\/a> method.<\/p>\n\n\n\n<pre class=\"wp-block-code language-python\"><code>from couchbase_haystack import (\n    CouchbaseQueryDocumentStore,\n    CouchbasePasswordAuthenticator,\n    CouchbaseClusterOptions,\n    QueryVectorSearchType,\n    QueryVectorSearchSimilarity,\n    CouchbaseQueryOptions\n)\nfrom couchbase.n1ql import QueryScanConsistency\nfrom datetime import timedelta\n\n@st.cache_resource(show_spinner=&quot;Connecting to Vector Store&quot;)\ndef get_document_store():\n    &quot;&quot;&quot;Return the Couchbase document store using CouchbaseQueryDocumentStore.&quot;&quot;&quot;\n    return CouchbaseQueryDocumentStore(\n        cluster_connection_string=Secret.from_env_var(&quot;DB_CONN_STR&quot;),\n        authenticator=CouchbasePasswordAuthenticator(\n            username=Secret.from_env_var(&quot;DB_USERNAME&quot;),\n            password=Secret.from_env_var(&quot;DB_PASSWORD&quot;)\n        ),\n        cluster_options=CouchbaseClusterOptions(profile=&#039;wan_development&#039;),\n        bucket=os.getenv(&quot;DB_BUCKET&quot;),\n        scope=os.getenv(&quot;DB_SCOPE&quot;),\n        collection=os.getenv(&quot;DB_COLLECTION&quot;),\n        search_type=QueryVectorSearchType.ANN,\n        similarity=QueryVectorSearchSimilarity.DOT,\n        nprobes=10,\n        query_options=CouchbaseQueryOptions(\n            timeout=timedelta(seconds=60),\n            scan_consistency=QueryScanConsistency.NOT_BOUNDED\n        )\n    )\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">We will define the bucket, scope, and collection names from <a href=\"#setup-environment-config\">Environment Variables<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Configuration Parameters:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>search_type=QueryVectorSearchType.ANN<\/code>: Uses approximate nearest neighbor search for fast retrieval<\/li>\n\n\n<li><code>similarity=QueryVectorSearchSimilarity.DOT<\/code>: Uses dot product similarity (optimized for OpenAI embeddings)<\/li>\n\n\n<li><code>nprobes=10<\/code>: Controls the search accuracy\/speed tradeoff (higher = more accurate but slower)<\/li>\n\n\n<li><code>query_options<\/code>: Configures query timeout and consistency settings<\/li>\n\n<\/ul>\n\n\n\n<h3 id=\"h-initialize-couchbase-vector-store\" class=\"wp-block-heading\">Initialize Couchbase Vector Store<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">We will now initialize the CouchbaseQueryDocumentStore which will be used for storing and retrieving document embeddings.<\/p>\n\n\n\n<pre class=\"wp-block-code language-python\"><code># Initialize document store\ndocument_store = get_document_store()\n<\/code><\/pre>\n\n\n\n<h3 id=\"h-uploading-and-ingesting-pdf\" class=\"wp-block-heading\">Uploading And Ingesting PDF<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>save_to_vector_store<\/code> function takes care of uploading the PDF file in vector format to the Couchbase Database using the Haystack indexing pipeline. It converts the PDF to documents, cleans them, splits text into small chunks, generates embeddings for those chunks, and ingests the chunks and their embeddings into the Couchbase vector store.<\/p>\n\n\n\n<h4 id=\"h-upload-pdf\" class=\"wp-block-heading\">Upload PDF<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">This part of code creates a file uploader on sidebar using Streamlit library. After PDF is uploaded, <code>save_to_vector_store<\/code> function is called to further process the PDF.<\/p>\n\n\n\n<pre class=\"wp-block-code language-python\"><code>with st.form(&quot;upload pdf&quot;):\n    uploaded_file = st.file_uploader(&quot;Choose a PDF.&quot;, help=&quot;The document will be deleted after one hour of inactivity (TTL).&quot;, type=&quot;pdf&quot;)\n    submitted = st.form_submit_button(&quot;Upload&quot;)\n    if submitted:\n        save_to_vector_store(uploaded_file, indexing_pipeline)\n<\/code><\/pre>\n\n\n\n<h4 id=\"h-read-load-and-process-uploaded-pdf\" class=\"wp-block-heading\">Read, Load, and Process Uploaded PDF<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>save_to_vector_store<\/code> function ensures that the uploaded PDF file is properly handled, loaded, and prepared for storage in the vector store. It first checks if a file was actually uploaded. Then the uploaded file is saved to a temporary file.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The indexing pipeline takes care of converting the PDF to documents, cleaning them, splitting them into chunks, generating embeddings, and storing them in the Couchbase vector store.<\/p>\n\n\n\n<pre class=\"wp-block-code language-python\"><code>def save_to_vector_store(uploaded_file, indexing_pipeline):\n    &quot;&quot;&quot;Process the PDF &amp; store it in Couchbase Vector Store&quot;&quot;&quot;\n    if uploaded_file is not None:\n        temp_dir = tempfile.TemporaryDirectory()\n        temp_file_path = os.path.join(temp_dir.name, uploaded_file.name)\n        \n        with open(temp_file_path, &quot;wb&quot;) as f:\n            f.write(uploaded_file.getvalue())\n        result = indexing_pipeline.run({&quot;converter&quot;: {&quot;sources&quot;: [temp_file_path]}})\n        \n        st.info(f&quot;PDF loaded into vector store: {result[&#039;writer&#039;][&#039;documents_written&#039;]} documents indexed&quot;)\n<\/code><\/pre>\n\n\n\n<h4 id=\"h-indexing-pipeline\" class=\"wp-block-heading\">Indexing Pipeline<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">The indexing pipeline is created to handle the entire process of ingesting PDFs into the vector store. It includes the following components:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>PyPDFToDocument: Converts PDF files to Haystack Document objects.<\/li>\n\n\n<li>DocumentCleaner: Cleans the extracted text from the PDF.<\/li>\n\n\n<li>DocumentSplitter: Splits the cleaned text into smaller chunks.<\/li>\n\n\n<li>OpenAIDocumentEmbedder: Generates embeddings for the document chunks.<\/li>\n\n\n<li>DocumentWriter: Writes the processed documents and their embeddings to the Couchbase vector store.<\/li>\n\n<\/ol>\n\n\n\n<pre class=\"wp-block-code language-python\"><code>from haystack import Pipeline\nfrom haystack.components.converters import PyPDFToDocument\nfrom haystack.components.preprocessors import DocumentCleaner, DocumentSplitter\nfrom haystack.components.embedders import OpenAIDocumentEmbedder, OpenAITextEmbedder\nfrom haystack.components.generators import OpenAIGenerator\nfrom haystack.components.builders import PromptBuilder, AnswerBuilder\nfrom haystack.components.writers import DocumentWriter\n\nindexing_pipeline = Pipeline()\nindexing_pipeline.add_component(&quot;converter&quot;, PyPDFToDocument())\nindexing_pipeline.add_component(&quot;cleaner&quot;, DocumentCleaner())\nindexing_pipeline.add_component(&quot;splitter&quot;, DocumentSplitter(split_by=&quot;word&quot;, split_length=250, split_overlap=50))\nindexing_pipeline.add_component(&quot;embedder&quot;, OpenAIDocumentEmbedder())\nindexing_pipeline.add_component(&quot;writer&quot;, DocumentWriter(document_store=document_store))\n\nindexing_pipeline.connect(&quot;converter.documents&quot;, &quot;cleaner.documents&quot;)\nindexing_pipeline.connect(&quot;cleaner.documents&quot;, &quot;splitter.documents&quot;)\nindexing_pipeline.connect(&quot;splitter.documents&quot;, &quot;embedder.documents&quot;)\nindexing_pipeline.connect(&quot;embedder.documents&quot;, &quot;writer.documents&quot;)\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">After the documents are written to Couchbase, the application automatically creates the Hyperscale vector index using SQL++.<\/p>\n\n\n\n<h4 id=\"h-chat-with-pdf\" class=\"wp-block-heading\">Chat With PDF<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">After uploading the PDF into Couchbase, we are now ready to utilize the power of Couchbase Vector Search, RAG and LLM to get context based answers to our questions. When the user asks a question. The assistant (LLM) is called here with RAG context, the response from the assistant is sent back to the user.<\/p>\n\n\n\n<h4 id=\"h-rag-pipeline\" class=\"wp-block-heading\">RAG Pipeline<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">We create a RAG (Retrieval-Augmented Generation) pipeline using Haystack components. This pipeline handles the entire process of retrieving relevant context from the vector store and generating responses using the LLM.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The OpenAIGenerator is a crucial component in our RAG pipeline, responsible for generating human-like responses based on the retrieved context and user questions. Here&#8217;s a more detailed explanation of its configuration and role:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>API Key: The OpenAIGenerator uses the OPENAI_API_KEY from the environment variables to authenticate with the OpenAI API.<\/li>\n\n\n<li>Model: It&#8217;s configured to use the &#8220;gpt-5&#8221; model, which is a powerful language model capable of understanding context and generating coherent, relevant responses.<\/li>\n\n\n<li>Role in the Pipeline: The OpenAIGenerator receives a prompt constructed by the PromptBuilder, which includes the user&#8217;s question and relevant context retrieved from the vector store. It then generates a response based on this input.<\/li>\n\n\n<li>Integration: The generator&#8217;s output is connected to the AnswerBuilder component, which formats the final response for display to the user.<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">By using the OpenAIGenerator, we leverage state-of-the-art natural language processing capabilities to provide accurate, context-aware answers to user queries about the uploaded PDF content.<\/p>\n\n\n\n<pre class=\"wp-block-code language-python\"><code>from haystack.components.embedders import OpenAITextEmbedder\nfrom couchbase_haystack import CouchbaseQueryEmbeddingRetriever\nfrom haystack.components.builders import PromptBuilder, AnswerBuilder\n\nrag_pipeline = Pipeline()\nrag_pipeline.add_component(&quot;query_embedder&quot;, OpenAITextEmbedder())\nrag_pipeline.add_component(&quot;retriever&quot;, CouchbaseQueryEmbeddingRetriever(document_store=document_store))\nrag_pipeline.add_component(&quot;prompt_builder&quot;, PromptBuilder(template=&quot;&quot;&quot;\nYou are a helpful bot. If you cannot answer based on the context provided, respond with a generic answer. Answer the question as truthfully as possible using the context below:\n{% for doc in documents %}\n    {{ doc.content }}\n{% endfor %}\n\nQuestion: {{question}}\n&quot;&quot;&quot;))\nrag_pipeline.add_component(\n    &quot;llm&quot;,\n    OpenAIGenerator(\n        api_key=OPENAI_API_KEY,\n        model=&quot;gpt-5&quot;,\n    ),\n)\nrag_pipeline.add_component(&quot;answer_builder&quot;, AnswerBuilder())\n\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<\/code><\/pre>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\"><strong>Key Point<\/strong>: We use <code>CouchbaseQueryEmbeddingRetriever<\/code> which queries the Hyperscale vector index using SQL++ with the <code>APPROX_VECTOR_DISTANCE()<\/code> function.<\/p>\n<\/blockquote>\n\n\n\n<h4 id=\"h-user-asks-a-question\" class=\"wp-block-heading\">User Asks A Question<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">This section creates an interactive chat interface where users can ask questions based on the uploaded PDF. The key steps are:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Display a chat input box with the prompt &#8220;Ask a question based on the PDF&#8221;.<\/li>\n\n\n<li>When the user submits a question:\n<ul>\n<li>Display the user&#8217;s question in the chat interface.<\/li>\n<li>Add the user&#8217;s question to the chat history.<\/li>\n<li>Run the RAG pipeline to generate a response.<\/li>\n<li>Display the response in the chat interface.<\/li>\n<li>Add the assistant&#8217;s response to the chat history.<\/li>\n<\/ul>\n<\/li>\n\n<\/ol>\n\n\n\n<pre class=\"wp-block-code language-python\"><code>if question := st.chat_input(&quot;Ask a question based on the PDF&quot;):\n    st.chat_message(&quot;user&quot;).markdown(question)\n    st.session_state.messages.append({&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: question, &quot;avatar&quot;: &quot;\ud83d\udc64&quot;})\n\n    # RAG response\n    with st.chat_message(&quot;assistant&quot;, avatar=couchbase_logo):\n        message_placeholder = st.empty()\n        rag_result = rag_pipeline.run(\n            {\n                &quot;query_embedder&quot;: {&quot;text&quot;: question},\n                &quot;retriever&quot;: {&quot;top_k&quot;: 3},\n                &quot;prompt_builder&quot;: {&quot;question&quot;: question},\n                &quot;answer_builder&quot;: {&quot;query&quot;: question},\n            }\n        )\n        rag_response = rag_result[&quot;answer_builder&quot;][&quot;answers&quot;][0].data\n        message_placeholder.markdown(rag_response)\n    st.session_state.messages.append({&quot;role&quot;: &quot;assistant&quot;, &quot;content&quot;: rag_response, &quot;avatar&quot;: couchbase_logo})\n\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This setup allows users to have a conversational experience, asking questions related to the uploaded PDF, with responses generated by the RAG pipeline. Both the user&#8217;s questions and the assistant&#8217;s responses are displayed in the chat interface, along with their respective roles and avatars.<\/p>\n\n\n\n<h4 id=\"h-stream-answer-without-context\" class=\"wp-block-heading\">Stream Answer without context<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Similar to last section, we will get answer from LLM of the user question. Answers from here are also shown in the UI to showcase difference on how using RAG gives better and more context enabled results.<\/p>\n\n\n\n<pre class=\"wp-block-code language-python\"><code># stream the response from the pure LLM\n\n# Add placeholder for streaming the response\n    with st.chat_message(&quot;ai&quot;, avatar=&quot;\ud83e\udd16&quot;):\n        message_placeholder_pure_llm = st.empty()\n        pure_llm_result = rag_pipeline.run(\n            {\n                &quot;prompt_builder&quot;: {&quot;question&quot;: question},\n                &quot;llm&quot;: {},\n                &quot;answer_builder&quot;: {&quot;query&quot;: question},\n                &quot;query_embedder&quot;: {&quot;text&quot;: question}\n            }\n        )\n        pure_llm_response = pure_llm_result[&quot;answer_builder&quot;][&quot;answers&quot;][0].data\n        message_placeholder_pure_llm.markdown(pure_llm_response)\n    st.session_state.messages.append({&quot;role&quot;: &quot;assistant&quot;, &quot;content&quot;: pure_llm_response, &quot;avatar&quot;: &quot;\ud83e\udd16&quot;})\n<\/code><\/pre>\n\n\n\n<h4 id=\"h-conclusion\" class=\"wp-block-heading\">Conclusion<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Congratulations! You&#8217;ve successfully built a PDF Chat application using Couchbase Hyperscale Vector Index, Haystack, and OpenAI. This application demonstrates the power of combining high-performance vector search with large language models to create an intelligent, context-aware chat interface for PDF documents.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Through this tutorial, you&#8217;ve learned how to:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Set up a Couchbase cluster with Hyperscale vector search capabilities.<\/li>\n\n\n<li>Use Haystack to process and index PDF documents.<\/li>\n\n\n<li>Implement a Retrieval-Augmented Generation (RAG) pipeline.<\/li>\n\n\n<li>Create an interactive chat interface using Streamlit.<\/li>\n\n\n<li>Compare responses from RAG and pure LLM approaches.<\/li>\n\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">We hope this tutorial has given you a solid foundation for building AI-powered document interaction systems with Couchbase Hyperscale Vector Index and Haystack. Happy coding!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction Welcome to this comprehensive guide on constructing an AI-enhanced Chat Application using Couchbase&#8217;s Hyperscale Vector Index. We will create a dynamic chat interface capable of delving into PDF documents to extract and provide summaries, key facts, and answers to your queries. By the end of this tutorial, you&#8217;ll have a powerful tool at your [&hellip;]<\/p>\n","protected":false},"author":0,"featured_media":0,"menu_order":0,"template":"","meta":{"_acf_changed":false,"inline_featured_image":false,"_acf":"","footnotes":""},"tutorial-languages":[606],"tutorial-tags":[620,609,642],"tutorial-technologies":[548,613],"tutorial-types":[555],"class_list":["post-10340","tutorials","type-tutorials","status-publish","hentry","tutorial-languages-python","tutorial-tags-haystack","tutorial-tags-openai","tutorial-tags-streamlit","tutorial-technologies-kv","tutorial-technologies-vector-search","tutorial-types-tutorial"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v28.8 (Yoast SEO v28.9) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Build PDF Chat App With Haystack, OpenAI and Couchbase Hyperscale Vector Index - 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\/de\/developers\/tutorials\/python-haystack-pdf-chat-with-hyperscale-index\/\" \/>\n<meta property=\"og:locale\" content=\"de_DE\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Build PDF Chat App With Haystack, OpenAI and Couchbase Hyperscale Vector Index\" \/>\n<meta property=\"og:description\" content=\"Introduction Welcome to this comprehensive guide on constructing an AI-enhanced Chat Application using Couchbase&#8217;s Hyperscale Vector Index. We will create a dynamic chat interface capable of delving into PDF documents to extract and provide summaries, key facts, and answers to your queries. By the end of this tutorial, you&#8217;ll have a powerful tool at your [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.couchbase.com\/de\/developers\/tutorials\/python-haystack-pdf-chat-with-hyperscale-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\u00a0Minuten\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/de\\\/developers\\\/tutorials\\\/python-haystack-pdf-chat-with-hyperscale-index\\\/\",\"url\":\"https:\\\/\\\/www.couchbase.com\\\/de\\\/developers\\\/tutorials\\\/python-haystack-pdf-chat-with-hyperscale-index\\\/\",\"name\":\"Build PDF Chat App With Haystack, OpenAI and Couchbase Hyperscale Vector Index - Couchbase\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/de\\\/#website\"},\"datePublished\":\"2025-12-01T05:49:45+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/de\\\/developers\\\/tutorials\\\/python-haystack-pdf-chat-with-hyperscale-index\\\/#breadcrumb\"},\"inLanguage\":\"de\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.couchbase.com\\\/de\\\/developers\\\/tutorials\\\/python-haystack-pdf-chat-with-hyperscale-index\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/de\\\/developers\\\/tutorials\\\/python-haystack-pdf-chat-with-hyperscale-index\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.couchbase.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Build PDF Chat App With Haystack, OpenAI and Couchbase Hyperscale Vector Index\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/de\\\/#website\",\"url\":\"https:\\\/\\\/www.couchbase.com\\\/de\\\/\",\"name\":\"Couchbase\",\"description\":\"The Operational Data Platform for AI\u2122\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/de\\\/#organization\"},\"alternateName\":\"Couchbase, Inc.\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.couchbase.com\\\/de\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"de\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/de\\\/#organization\",\"name\":\"Couchbase\",\"alternateName\":\"Couchbase, Inc.\",\"url\":\"https:\\\/\\\/www.couchbase.com\\\/de\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"de\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/de\\\/#\\\/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\\\/de\\\/#\\\/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":"Build PDF Chat App With Haystack, OpenAI and Couchbase Hyperscale Vector Index - 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\/de\/developers\/tutorials\/python-haystack-pdf-chat-with-hyperscale-index\/","og_locale":"de_DE","og_type":"article","og_title":"Build PDF Chat App With Haystack, OpenAI and Couchbase Hyperscale Vector Index","og_description":"Introduction Welcome to this comprehensive guide on constructing an AI-enhanced Chat Application using Couchbase&#8217;s Hyperscale Vector Index. We will create a dynamic chat interface capable of delving into PDF documents to extract and provide summaries, key facts, and answers to your queries. By the end of this tutorial, you&#8217;ll have a powerful tool at your [&hellip;]","og_url":"https:\/\/www.couchbase.com\/de\/developers\/tutorials\/python-haystack-pdf-chat-with-hyperscale-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\u00a0Minuten"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.couchbase.com\/de\/developers\/tutorials\/python-haystack-pdf-chat-with-hyperscale-index\/","url":"https:\/\/www.couchbase.com\/de\/developers\/tutorials\/python-haystack-pdf-chat-with-hyperscale-index\/","name":"Build PDF Chat App With Haystack, OpenAI and Couchbase Hyperscale Vector Index - Couchbase","isPartOf":{"@id":"https:\/\/www.couchbase.com\/de\/#website"},"datePublished":"2025-12-01T05:49:45+00:00","breadcrumb":{"@id":"https:\/\/www.couchbase.com\/de\/developers\/tutorials\/python-haystack-pdf-chat-with-hyperscale-index\/#breadcrumb"},"inLanguage":"de","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.couchbase.com\/de\/developers\/tutorials\/python-haystack-pdf-chat-with-hyperscale-index\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.couchbase.com\/de\/developers\/tutorials\/python-haystack-pdf-chat-with-hyperscale-index\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.couchbase.com\/"},{"@type":"ListItem","position":2,"name":"Build PDF Chat App With Haystack, OpenAI and Couchbase Hyperscale Vector Index"}]},{"@type":"WebSite","@id":"https:\/\/www.couchbase.com\/de\/#website","url":"https:\/\/www.couchbase.com\/de\/","name":"Couchbase","description":"The Operational Data Platform for AI\u2122","publisher":{"@id":"https:\/\/www.couchbase.com\/de\/#organization"},"alternateName":"Couchbase, Inc.","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.couchbase.com\/de\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"de"},{"@type":"Organization","@id":"https:\/\/www.couchbase.com\/de\/#organization","name":"Couchbase","alternateName":"Couchbase, Inc.","url":"https:\/\/www.couchbase.com\/de\/","logo":{"@type":"ImageObject","inLanguage":"de","@id":"https:\/\/www.couchbase.com\/de\/#\/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\/de\/#\/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 ist ein in San Jose, Kalifornien, ans\u00e4ssiges Unternehmen f\u00fcr Datenbanksoftware, das eine operative Datenplattform f\u00fcr KI bereitstellt, die von Hunderten von globalen Unternehmen eingesetzt wird.","legalName":"Couchbase, Inc.","foundingDate":"2011-01-01"}]}},"acf":[],"permalink_manager":null,"_links":{"self":[{"href":"https:\/\/www.couchbase.com\/de\/wp-json\/wp\/v2\/tutorials\/10340","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.couchbase.com\/de\/wp-json\/wp\/v2\/tutorials"}],"about":[{"href":"https:\/\/www.couchbase.com\/de\/wp-json\/wp\/v2\/types\/tutorials"}],"version-history":[{"count":0,"href":"https:\/\/www.couchbase.com\/de\/wp-json\/wp\/v2\/tutorials\/10340\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.couchbase.com\/de\/wp-json\/wp\/v2\/media?parent=10340"}],"wp:term":[{"taxonomy":"tutorial-languages","embeddable":true,"href":"https:\/\/www.couchbase.com\/de\/wp-json\/wp\/v2\/tutorial-languages?post=10340"},{"taxonomy":"tutorial-tags","embeddable":true,"href":"https:\/\/www.couchbase.com\/de\/wp-json\/wp\/v2\/tutorial-tags?post=10340"},{"taxonomy":"tutorial-technologies","embeddable":true,"href":"https:\/\/www.couchbase.com\/de\/wp-json\/wp\/v2\/tutorial-technologies?post=10340"},{"taxonomy":"tutorial-types","embeddable":true,"href":"https:\/\/www.couchbase.com\/de\/wp-json\/wp\/v2\/tutorial-types?post=10340"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}