{"id":10341,"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-search-vector-index\/"},"modified":"2025-11-30T21:49:45","modified_gmt":"2025-12-01T05:49:45","slug":"python-haystack-pdf-chat-with-search-vector-index","status":"publish","type":"tutorials","link":"https:\/\/www.couchbase.com\/fr\/developers\/tutorials\/python-haystack-pdf-chat-with-search-vector-index\/","title":{"rendered":"Build PDF Chat App With Haystack, OpenAI and Couchbase Search 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 Search Vector Index (SVI)<\/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<p class=\"wp-block-paragraph\">This tutorial demonstrates the <strong>Search Vector Index<\/strong>, which is ideal for:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Hybrid search<\/strong> scenarios combining full-text and vector search<\/li>\n\n\n<li><strong>Rich text search<\/strong> with vector similarity<\/li>\n\n\n<li><strong>Complex filtering<\/strong> using FTS queries<\/li>\n\n\n<li><strong>Couchbase 7.6+<\/strong> compatibility<\/li>\n\n<\/ul>\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>Construct a <a href=\"https:\/\/docs.couchbase.com\/cloud\/vector-search\/vector-search.html\">Couchbase Search Vector Index<\/a>.<\/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\">Haystack-Couchbase Vector Store<\/a> to store the vectors into Couchbase.<\/li>\n\n\n<li>We will use <a href=\"https:\/\/openai.com\">OpenAI<\/a> for generating Embeddings and querying the LLM.<\/li>\n\n\n<li>Automatically create Search Vector Index with vector support from a JSON configuration file.<\/li>\n\n\n<li>Craft an elegant UI with Streamlit. 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 7.6+ with <a href=\"https:\/\/docs.couchbase.com\/server\/current\/fts\/fts-introduction.html\">Search Service<\/a>. Vector Search in Couchbase is only supported at Couchbase Version 7.6+.<\/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<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. Make sure to add the <a href=\"https:\/\/docs.couchbase.com\/server\/current\/fts\/fts-introduction.html\">Search Service<\/a>.<\/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-search-index-creation\" class=\"wp-block-heading\">Automatic Search Index Creation<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">The application automatically creates the Search Vector Index (SVI) index with vector support on startup. The index definition is loaded from the <code>sampleSearchIndex.json<\/code> file included in the repository, which is then customized with your bucket, scope, and collection names from the environment variables.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If automatic creation fails or you prefer to create the index manually, you can use the following instructions:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\n<p><a href=\"https:\/\/docs.couchbase.com\/cloud\/search\/import-search-index.html\">Couchbase Capella<\/a><\/p>\n<ul>\n<li>Copy the index definition from <code>sampleSearchIndex.json<\/code> to a new file.<\/li>\n<li>Update <code>sourceName<\/code> to match your bucket name.<\/li>\n<li>Update the <code>types<\/code> key to match your <code>scope_name.collection_name<\/code> (e.g., <code>pdf_data.pdf_chunks<\/code>).<\/li>\n<li>Import the file in Capella using the instructions in the documentation.<\/li>\n<li>Click on Create Index to create the index.<\/li>\n<\/ul>\n<\/li>\n\n\n<li>\n<p><a href=\"https:\/\/docs.couchbase.com\/server\/current\/search\/import-search-index.html\">Couchbase Server<\/a><\/p>\n<ul>\n<li>Click on Search -&gt; Add Index -&gt; Import.<\/li>\n<li>Copy the contents of <code>sampleSearchIndex.json<\/code>.<\/li>\n<li>Update <code>sourceName<\/code> and <code>types<\/code> key as mentioned above (e.g., <code>pdf_data.pdf_chunks<\/code>).<\/li>\n<li>Paste the updated JSON in the Import screen.<\/li>\n<li>Click on Create Index to create the index.<\/li>\n<\/ul>\n<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">You may also create a vector index using Search UI on both <a href=\"https:\/\/docs.couchbase.com\/cloud\/vector-search\/create-vector-search-index-ui.html\">Couchbase Capella<\/a> and <a href=\"https:\/\/docs.couchbase.com\/server\/current\/vector-search\/create-vector-search-index-ui.html\">Couchbase Self Managed Server<\/a>.<\/p>\n\n\n\n<h5 id=\"h-index-definition\" class=\"wp-block-heading\">Index Definition<\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">Here, we are creating the index on the documents with the following configuration:<\/p>\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>Text field<\/strong>: <code>content<\/code> for document text content<\/li>\n\n\n<li><strong>Metadata field<\/strong>: <code>meta<\/code> with dynamic mapping to account for varying document structures<\/li>\n\n\n<li><strong>Similarity metric<\/strong>: <code>dot_product<\/code> (optimized for OpenAI embeddings)<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">The index definition is stored in <code>sampleSearchIndex.json<\/code> and is automatically loaded and customized by the application.<\/p>\n\n\n\n<pre class=\"wp-block-code language-json\"><code>{\n  &quot;name&quot;: &quot;sample-index&quot;,\n  &quot;type&quot;: &quot;fulltext-index&quot;,\n  &quot;params&quot;: {\n    &quot;doc_config&quot;: {\n      &quot;docid_prefix_delim&quot;: &quot;&quot;,\n      &quot;docid_regexp&quot;: &quot;&quot;,\n      &quot;mode&quot;: &quot;scope.collection.type_field&quot;,\n      &quot;type_field&quot;: &quot;type&quot;\n    },\n    &quot;mapping&quot;: {\n      &quot;default_analyzer&quot;: &quot;standard&quot;,\n      &quot;default_datetime_parser&quot;: &quot;dateTimeOptional&quot;,\n      &quot;default_field&quot;: &quot;_all&quot;,\n      &quot;default_mapping&quot;: {\n        &quot;dynamic&quot;: true,\n        &quot;enabled&quot;: false\n      },\n      &quot;default_type&quot;: &quot;_default&quot;,\n      &quot;docvalues_dynamic&quot;: false,\n      &quot;index_dynamic&quot;: true,\n      &quot;store_dynamic&quot;: false,\n      &quot;type_field&quot;: &quot;_type&quot;,\n      &quot;types&quot;: {\n        &quot;pdf_data.pdf_chunks&quot;: {\n          &quot;dynamic&quot;: true,\n          &quot;enabled&quot;: true,\n          &quot;properties&quot;: {\n            &quot;embedding&quot;: {\n              &quot;enabled&quot;: true,\n              &quot;dynamic&quot;: false,\n              &quot;fields&quot;: [\n                {\n                  &quot;dims&quot;: 1536,\n                  &quot;index&quot;: true,\n                  &quot;name&quot;: &quot;embedding&quot;,\n                  &quot;similarity&quot;: &quot;dot_product&quot;,\n                  &quot;type&quot;: &quot;vector&quot;,\n                  &quot;vector_index_optimized_for&quot;: &quot;recall&quot;\n                }\n              ]\n            },\n            &quot;meta&quot;: {\n              &quot;dynamic&quot;: true,\n              &quot;enabled&quot;: true\n            },\n            &quot;content&quot;: {\n              &quot;enabled&quot;: true,\n              &quot;dynamic&quot;: false,\n              &quot;fields&quot;: [\n                {\n                  &quot;index&quot;: true,\n                  &quot;name&quot;: &quot;text&quot;,\n                  &quot;store&quot;: true,\n                  &quot;type&quot;: &quot;text&quot;\n                }\n              ]\n            }\n          }\n        }\n      }\n    },\n    &quot;store&quot;: {\n      &quot;indexType&quot;: &quot;scorch&quot;,\n      &quot;segmentVersion&quot;: 16\n    }\n  },\n  &quot;sourceType&quot;: &quot;gocbcore&quot;,\n  &quot;sourceName&quot;: &quot;sample_bucket&quot;,\n  &quot;sourceParams&quot;: {},\n  &quot;planParams&quot;: {\n    &quot;maxPartitionsPerPIndex&quot;: 64,\n    &quot;indexPartitions&quot;: 16,\n    &quot;numReplicas&quot;: 0\n  }\n}\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>Note<\/strong>: The application automatically replaces <code>sample_bucket<\/code> with your actual bucket name and <code>pdf_data.pdf_chunks<\/code> with your actual <code>scope_name.collection_name<\/code> from the environment variables.<\/p>\n<\/blockquote>\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;\n    DB_USERNAME = &quot;&lt;couchbase_username&gt;&quot;\n    DB_PASSWORD = &quot;&lt;couchbase_password&gt;&quot;\n    DB_BUCKET = &quot;&lt;bucket_name&gt;&quot;\n    DB_SCOPE = &quot;&lt;scope_name&gt;&quot;\n    DB_COLLECTION = &quot;&lt;collection_name&gt;&quot;\n    INDEX_NAME = &quot;&lt;vector_index_name&gt;&quot;\n    OPENAI_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> and <code>INDEX_NAME = sample-index<\/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, collection, and SVI 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_search_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>Note<\/strong>: The Search Vector Index is created automatically on startup. If the index already exists, the application will detect it and continue without errors.<\/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\" class=\"wp-block-heading\">Vector Search with Couchbase<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Couchbase is a NoSQL database that provides a powerful Vector Search capability. It allows you to store and search through high-dimensional vector representations (embeddings) of textual data, such as PDF content.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The PDF Chat app uses LangChain 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\/python-sdk\/current\/howtos\/full-text-searching-with-sdk.html#vector-search\">Couchbase&#8217;s Vector Search<\/a> capability is utilized, which supports search indexes. A dedicated search index is created for the PDF embeddings and their corresponding text content, configured with the necessary indexing parameters (bucket, scope, collection, index name).<\/li>\n\n\n<li>The app queries this search index using the user&#8217;s query embedding. Couchbase&#8217;s Vector Search calculates the <a href=\"https:\/\/www.couchbase.com\/blog\/vector-similarity-search\/\">similarity<\/a> (e.g., dot product) between the query embedding and the indexed PDF embeddings, enabling fast retrieval of the nearest neighbor embeddings.<\/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 Vector Search supports advanced indexing techniques, such as <a href=\"https:\/\/docs.couchbase.com\/python-sdk\/current\/howtos\/full-text-searching-with-sdk.html#scoped-vs-global-indexes\">scoped indexes<\/a>, <a href=\"https:\/\/docs.couchbase.com\/server\/current\/fts\/fts-creating-index-from-REST-dynamic.html\">dynamic indexing<\/a> and <a href=\"https:\/\/docs.couchbase.com\/python-sdk\/current\/howtos\/full-text-searching-with-sdk.html#combining-fts-and-vector-queries\">hybrid search<\/a>, allowing for efficient management, better scaling of the vector store and multiple types of search supported.<\/li>\n\n\n<li>The search index facilitates fast and accurate retrieval, 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 Vector Search integrates seamlessly with Haystack&#8217;s <a href=\"https:\/\/haystack.deepset.ai\/integrations\/couchbase-document-store\">CouchbaseSearchVectorStore<\/a> 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 using the Search Vector Index approach. The whole code is written in <code>chat_with_pdf_with_search_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 Vector Search via Search Vector Index (SVI) is required for PDF Upload as well as during chat (For Retrieval). We will use the Haystack <strong>CouchbaseSearchDocumentStore<\/strong> to connect to the Couchbase cluster with Search Vector Index support. The connection is established in the <code>get_document_store<\/code> function.<\/p>\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 CouchbaseSearchDocumentStore, CouchbasePasswordAuthenticator, CouchbaseClusterOptions\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&quot;&quot;&quot;\n    return CouchbaseSearchDocumentStore(\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        vector_search_index=os.getenv(&quot;INDEX_NAME&quot;),\n    )\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">We will define the bucket, scope, collection and index names from <a href=\"#setup-environment-config\">Environment Variables<\/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>Key Point<\/strong>: We use <code>CouchbaseSearchDocumentStore<\/code> which leverages the Search Service for vector search capabilities. This is different from the query-based approach that uses <code>CouchbaseQueryDocumentStore<\/code>.<\/p>\n<\/blockquote>\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 CouchbaseDocumentStore 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\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<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 CouchbaseSearchEmbeddingRetriever\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;, CouchbaseSearchEmbeddingRetriever(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>CouchbaseSearchEmbeddingRetriever<\/code> which queries the Search Vector Index for vector search. This retriever leverages the Search Service for finding semantically similar documents.<\/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 Search Vector Index, Haystack, and OpenAI. This application demonstrates the power of combining vector search capabilities 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 Search Vector Index 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 Search 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 Search Vector Index (SVI). 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 [&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-10341","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 Search 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\/fr\/developers\/tutorials\/python-haystack-pdf-chat-with-search-vector-index\/\" \/>\n<meta property=\"og:locale\" content=\"fr_FR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Build PDF Chat App With Haystack, OpenAI and Couchbase Search Vector Index\" \/>\n<meta property=\"og:description\" content=\"Introduction Welcome to this comprehensive guide on constructing an AI-enhanced Chat Application using Couchbase Search Vector Index (SVI). 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 [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.couchbase.com\/fr\/developers\/tutorials\/python-haystack-pdf-chat-with-search-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 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/fr\\\/developers\\\/tutorials\\\/python-haystack-pdf-chat-with-search-vector-index\\\/\",\"url\":\"https:\\\/\\\/www.couchbase.com\\\/fr\\\/developers\\\/tutorials\\\/python-haystack-pdf-chat-with-search-vector-index\\\/\",\"name\":\"Build PDF Chat App With Haystack, OpenAI and Couchbase Search Vector Index - Couchbase\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/fr\\\/#website\"},\"datePublished\":\"2025-12-01T05:49:45+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/fr\\\/developers\\\/tutorials\\\/python-haystack-pdf-chat-with-search-vector-index\\\/#breadcrumb\"},\"inLanguage\":\"fr-FR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.couchbase.com\\\/fr\\\/developers\\\/tutorials\\\/python-haystack-pdf-chat-with-search-vector-index\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/fr\\\/developers\\\/tutorials\\\/python-haystack-pdf-chat-with-search-vector-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 Search Vector Index\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/fr\\\/#website\",\"url\":\"https:\\\/\\\/www.couchbase.com\\\/fr\\\/\",\"name\":\"Couchbase\",\"description\":\"The Operational Data Platform for AI\u2122\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/fr\\\/#organization\"},\"alternateName\":\"Couchbase, Inc.\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.couchbase.com\\\/fr\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"fr-FR\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/fr\\\/#organization\",\"name\":\"Couchbase\",\"alternateName\":\"Couchbase, Inc.\",\"url\":\"https:\\\/\\\/www.couchbase.com\\\/fr\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"fr-FR\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/fr\\\/#\\\/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\\\/fr\\\/#\\\/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 Search 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\/fr\/developers\/tutorials\/python-haystack-pdf-chat-with-search-vector-index\/","og_locale":"fr_FR","og_type":"article","og_title":"Build PDF Chat App With Haystack, OpenAI and Couchbase Search Vector Index","og_description":"Introduction Welcome to this comprehensive guide on constructing an AI-enhanced Chat Application using Couchbase Search Vector Index (SVI). 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 [&hellip;]","og_url":"https:\/\/www.couchbase.com\/fr\/developers\/tutorials\/python-haystack-pdf-chat-with-search-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 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.couchbase.com\/fr\/developers\/tutorials\/python-haystack-pdf-chat-with-search-vector-index\/","url":"https:\/\/www.couchbase.com\/fr\/developers\/tutorials\/python-haystack-pdf-chat-with-search-vector-index\/","name":"Build PDF Chat App With Haystack, OpenAI and Couchbase Search Vector Index - Couchbase","isPartOf":{"@id":"https:\/\/www.couchbase.com\/fr\/#website"},"datePublished":"2025-12-01T05:49:45+00:00","breadcrumb":{"@id":"https:\/\/www.couchbase.com\/fr\/developers\/tutorials\/python-haystack-pdf-chat-with-search-vector-index\/#breadcrumb"},"inLanguage":"fr-FR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.couchbase.com\/fr\/developers\/tutorials\/python-haystack-pdf-chat-with-search-vector-index\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.couchbase.com\/fr\/developers\/tutorials\/python-haystack-pdf-chat-with-search-vector-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 Search Vector Index"}]},{"@type":"WebSite","@id":"https:\/\/www.couchbase.com\/fr\/#website","url":"https:\/\/www.couchbase.com\/fr\/","name":"Couchbase","description":"The Operational Data Platform for AI\u2122","publisher":{"@id":"https:\/\/www.couchbase.com\/fr\/#organization"},"alternateName":"Couchbase, Inc.","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.couchbase.com\/fr\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"fr-FR"},{"@type":"Organization","@id":"https:\/\/www.couchbase.com\/fr\/#organization","name":"Couchbase","alternateName":"Couchbase, Inc.","url":"https:\/\/www.couchbase.com\/fr\/","logo":{"@type":"ImageObject","inLanguage":"fr-FR","@id":"https:\/\/www.couchbase.com\/fr\/#\/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\/fr\/#\/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 est une soci\u00e9t\u00e9 de logiciels de bases de donn\u00e9es dont le si\u00e8ge social est situ\u00e9 \u00e0 San Jose, en Californie, et qui fournit une plateforme op\u00e9rationnelle de donn\u00e9es pour l\u2019IA utilis\u00e9e par des centaines d\u2019entreprises mondiales.","legalName":"Couchbase, Inc.","foundingDate":"2011-01-01"}]}},"acf":[],"permalink_manager":null,"_links":{"self":[{"href":"https:\/\/www.couchbase.com\/fr\/wp-json\/wp\/v2\/tutorials\/10341","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.couchbase.com\/fr\/wp-json\/wp\/v2\/tutorials"}],"about":[{"href":"https:\/\/www.couchbase.com\/fr\/wp-json\/wp\/v2\/types\/tutorials"}],"version-history":[{"count":0,"href":"https:\/\/www.couchbase.com\/fr\/wp-json\/wp\/v2\/tutorials\/10341\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.couchbase.com\/fr\/wp-json\/wp\/v2\/media?parent=10341"}],"wp:term":[{"taxonomy":"tutorial-languages","embeddable":true,"href":"https:\/\/www.couchbase.com\/fr\/wp-json\/wp\/v2\/tutorial-languages?post=10341"},{"taxonomy":"tutorial-tags","embeddable":true,"href":"https:\/\/www.couchbase.com\/fr\/wp-json\/wp\/v2\/tutorial-tags?post=10341"},{"taxonomy":"tutorial-technologies","embeddable":true,"href":"https:\/\/www.couchbase.com\/fr\/wp-json\/wp\/v2\/tutorial-technologies?post=10341"},{"taxonomy":"tutorial-types","embeddable":true,"href":"https:\/\/www.couchbase.com\/fr\/wp-json\/wp\/v2\/tutorial-types?post=10341"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}