{"id":20786004,"url":"https://github.com/thomassuedbroecker/simple-qa-pipeline","last_synced_at":"2026-05-15T20:31:04.964Z","repository":{"id":186378085,"uuid":"675070916","full_name":"thomassuedbroecker/simple-qa-pipeline","owner":"thomassuedbroecker","description":"This project contains a simple example implementation for a simple question-answering pipeline using inside-search (IBM Cloud Watson Discovery) and prompt (IBM watsonx with prompt-lab).","archived":false,"fork":false,"pushed_at":"2024-02-21T15:49:40.000Z","size":8616,"stargazers_count":3,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-21T06:50:18.687Z","etag":null,"topics":["bash","prompt","python","watson-discovery","watsonx"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/thomassuedbroecker.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-08-05T17:13:06.000Z","updated_at":"2025-07-05T01:50:26.000Z","dependencies_parsed_at":"2023-11-29T19:30:54.110Z","dependency_job_id":"c3e67204-3a9e-4cd5-9a21-94332a618e23","html_url":"https://github.com/thomassuedbroecker/simple-qa-pipeline","commit_stats":null,"previous_names":["thomassuedbroecker/simple-qa-pipeline"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/thomassuedbroecker/simple-qa-pipeline","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thomassuedbroecker%2Fsimple-qa-pipeline","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thomassuedbroecker%2Fsimple-qa-pipeline/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thomassuedbroecker%2Fsimple-qa-pipeline/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thomassuedbroecker%2Fsimple-qa-pipeline/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thomassuedbroecker","download_url":"https://codeload.github.com/thomassuedbroecker/simple-qa-pipeline/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thomassuedbroecker%2Fsimple-qa-pipeline/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33078898,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-15T20:25:35.270Z","status":"ssl_error","status_checked_at":"2026-05-15T20:25:34.732Z","response_time":103,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bash","prompt","python","watson-discovery","watsonx"],"created_at":"2024-11-17T14:50:02.815Z","updated_at":"2026-05-15T20:31:04.949Z","avatar_url":"https://github.com/thomassuedbroecker.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Simple `question-answering pipeline` using inside search and prompt with a Large Langauge Model.\n\nThis project contains a simple example implementation for a simple `question-answering pipeline` using an `inside-search` (`IBM Cloud Watson Discovery`) and a `prompt` (`IBM watsonx` with `prompt-lab`) to create an answer.\n\nRelated blog post: [IBM watsonx and a simple question-answering pipeline using Python and FastAPI](https://wp.me/paelj4-21Y)\n\n## 1. Objective\n\nThe objective is to implement an elementary `question-answering pipeline` example by showing how to consume existing REST APIs and create a REST API with [`FastAPI`](https://github.com/tiangolo/FastAPI) and `Python` because `Python` is well-known in the AI world.\n\n\u003eNote: An excellent and detailed example implementation for a `question-answering pipeline` in the [`question-answering project`](https://github.com/nheidloff/question-answering). That project contains many more details and integrations; the `question-answering pipeline` is implemented in Java.\nThe project also provides an example implementation for an experiment execution for the question-answering pipeline the service for the execution is called `experiment-runner` and is implemented in Python. [Niklas Heidloff](https://heidloff.net) has written many awesome blog posts about AI and this [`question-answering project`](https://github.com/nheidloff/question-answering). I recommend briefly looking at the related blog posts to this project.\n\n## 2. Simplified Architecture\n\nThe `simple-qa-pipeline` creates an answer to a question using a [Large Language Model]() inside [watsonx with the Prompt lab](https://dataplatform.cloud.ibm.com/docs/content/wsj/getting-started/welcome-main.html?context=wx\u0026audience=wdp) and it searches for documents with Watson Discovery to provide the context.\n\n![](/images/simple-pipeline-pipeline.drawio.png)\n\n## 3. Run the `simple-qa-pipeline` locally\n\n### 3.1. Get the source code and create a virtual Python environment\n\n* Clone project\n\n```\ngit clone https://github.com/thomassuedbroecker/simple-pipeline.git\n```\n\n* Create a virtual Python environment\n\n```sh\ncd simple-pipeline/code\npython3 -m venv simple-pipeline-env-3\nsource ./simple-pipeline-env-3/bin/activate\n```\n\n* Install needed Python libs and create a `requirements.txt` file\n\n```sh\npython3 -m pip install --upgrade pip\npython3 -m pip install \"fastapi[all]\"\npython3 -m pip install requests\npython3 -m pip install pydantic\npython3 -m pip install torch\npython3 -m pip install accelerate\npython3 -m pip install typing\npython3 -m pip install transformers\n#python3 -m pip install git+https://github.com/huggingface/transformers\n```\n\n* Save your configuration in requirements.txt\n\n```sh\npython3 -m pip install --upgrade pip\npython3 -m pip freeze \u003e requirements.txt\ndeactivate\n```\n\n* Install from configuration from requirements.txt\n\n```sh\npython3 -m pip install -r requirements.txt\n```\n\n### 3.2. Configure the `simple-qa-pipeline` to access the needed REST API by using environment variables\n\n* Create `.env` file\n\n```sh\ncat ./.env-template \u003e ./.env\n```\n\n* Outline of the environment file\n\n```sh\n# Discovery\nexport DISCOVERY_API_KEY=\nexport DISCOVERY_URL=https://api.us-east.discovery.watson.cloud.ibm.com/instances/\nexport DISCOVERY_COLLECTION_ID=\nexport DISCOVERY_PROJECT=\nexport DISCOVERY_INSTANCE=\n# watsonx\nexport WATSONX_URL=\"https://us-south.ml.cloud.ibm.com/ml/v1-beta/generation/text\"\nexport WATSONX_LLM_NAME=google/flan-ul2\nexport WATSONX_MIN_NEW_TOKENS=1\nexport WATSONX_MAX_NEW_TOKENS=300\nexport WATSONX_PROMPT=\"Document:\\n\\n\u003c\u003cCONTEXT\u003e\u003e\\n\\nQuestion:\\n\\n\u003c\u003cQUESTION\u003e\u003e\\n\\nAnswer:\\n\\n\"\nexport WATSONX_PROJECT_ID=\nexport WATSONX_VERSION=\"2023-05-29\"\n# Watsonx deployment (Watson Studio Deployment)\nexport WATSONX_DEPLOYMENT_ID=\nexport WATSONX_DEPLOYMENT_URL=https://[XXX]${WATSONX_DEPLOYMENT_ID}[YYY]\nexport WATSONX_DEPLOYMENT_VERSION=2021-05-01\n# Custom Model\nexport CUSTOM_MODEL_PROMPT=\"Code:\\n\\n\u003c\u003cCONTEXT\u003e\u003e\\n\\nQuestion:\\n\\n\u003c\u003cQUESTION\u003e\u003e\\n\\nAnswer:\\n\\n\"\n# IBM Cloud\nexport IBMCLOUD_APIKEY=\n# APP\nexport APP_USER=admin\nexport APP_APIKEY=admin\nexport APPLOG=INFO\n```\n\n### 3.3 Run `simple-qa-pipeline` server\n\n```sh\ncd code\nsource ./simple-pipeline-env-3/bin/activate\nsource ./.env\npython3 simple-qa-pipeline.py\n```\n\n* Open Swagger UI with the API documentation\n\n```sh\nopen http://localhost:8081/docs\n```\n\n![](/images/watsonx-05.png)\n\n### 3.4. Run a small test\n\n* Question: `\"What is your name?\"`\n* Context:  `\"My name is Thomas.\"`\n\n* Invoke the REST API endpoint `get_simple_answer` in the Swagger UI with the given values.\n* Open the `watsonx Prompt lab` and insert the following prompt.\n\n```\nDocument:\n\nMy name is Thomas.\n\nQuestion:\n\nWhat is your name?\n\nAnswer:\n\n\n```\n\nThe following gif shows how the simple test works.\n\n![](/images/watsonx-04.gif)\n\n### 3.5. Setup the related IBM Cloud instance\n\nThis example uses [IBM Cloud](https://cloud.ibm.com/).\n\n### 3.5.1 Watson Discovery service instance\n\nThere is no [`Lite plan`](https://www.ibm.com/cloud/free) available, but when you create a new IBM Cloud Account, you a [`free trial period`](https://www.ibm.com/products/watson-discovery), you can use.\n\n* [Create a Watson Discovery instance](https://cloud.ibm.com/docs/discovery-data?topic=discovery-data-getting-started)\n* Extract the project ID and collection ID\n  * If you need additional help, you can visit my blog post [Show the collection IDs of IBM Cloud Watson Discovery projects using cURL](https://suedbroecker.net/2023/05/12/show-the-collection-ids-of-ibm-cloud-watson-discovery-projects-using-curl/)\n\n### 3.5.2 watsonx instance\n\n1. Visit the [watsonx link](https://www.ibm.com/watsonx) and get a free trial.\n2. A `Sandbox project` will be created for you called `Sandbox`\n3. The watsonx documentation is available on [IBM Cloud](https://dataplatform.cloud.ibm.com/docs/content/wsj/getting-started/welcome-main.html?context=wx\u0026audience=wdp)\n4. [Open Prompt lab](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/fm-prompt-lab.html?context=wx\u0026audience=wdp)\n5. Open view code\n![](/images/watsonx-01.gif)\n6. [Create an IBM Cloud API key](https://www.ibm.com/docs/en/app-connect/container?topic=servers-creating-cloud-api-key)\n\n![](/images/watsonx-03.gif))\n\n* With watsonx sandbox project creation following services will be instantiated in your IBM Cloud Account:\n\n  * [Watson Studio](https://www.ibm.com/products/watson-studio)\n  * [Watson Machine Learning](https://cloud.ibm.com/catalog/services/watson-machine-learning)\n  * [Cloud Object Storage](https://cloud.ibm.com/docs/cloud-object-storage?topic=cloud-object-storage-getting-started-cloud-object-storage)\n  The gif below shows how you can access watsonx from your Watson Studion in your IBM Cloud Account.\n  ![](/images/watsonx-03.gif)\n\n* Simplified dependencies of the created Watonx environment\n\n![](/images/simple-pipeline-watsonx-dependencies.drawio.png)\n\n## 4. Useful tools\n\n  * [`curl-converter`](https://curlconverter.com/)\n\n## 5. Summary\n\nWith [`FastAPI`](https://github.com/tiangolo/fastapi) and `Python` was easy and fasted to implement the `simple-qa-pipeline`.\nWith the automated created Swagger documentation, manually testing the `REST API` for the `simple-qa-pipeline` was easy.\nWe can download the OpenAPI spec directly and use its `REST API` in other integration scenarios like BYOS with Watson Assistant.\n\nThe good REST API documentation from IBM Cloud and watsonx made it easy to use them even without the SDK.\n\n## 6. Additional resources\n\n* [VS Code Python debugging](https://code.visualstudio.com/docs/python/debugging)\n* [OpenAPI Swagger `array of strings`](https://stackoverflow.com/questions/39281532/specify-an-array-of-strings-as-body-parameter-in-swagger-api)\n* [OpenAPI Swagger `array of objects`](https://stackoverflow.com/questions/63738715/how-to-define-an-array-of-objects-in-openapi-3-0)\n* [OpenAPI Swagger `authentication`](https://swagger.io/docs/specification/authentication/)\n* [OpenAPI Swagger `apikey authentication`](https://github.com/watson-developer-cloud/assistant-toolkit/blob/master/integrations/extensions/starter-kits/language-model-watsonx/watsonx-openapi.json#L14)\n* [Required properties](https://stackoverflow.com/questions/40113049/how-to-specify-if-a-field-is-optional-or-required-in-openapi-swagger)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthomassuedbroecker%2Fsimple-qa-pipeline","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthomassuedbroecker%2Fsimple-qa-pipeline","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthomassuedbroecker%2Fsimple-qa-pipeline/lists"}