From 417c1e353c6b8732ba6d29394adee397d2a6c38d Mon Sep 17 00:00:00 2001
From: minmin-intel <minmin.hou@intel.com>
Date: Wed, 14 Aug 2024 10:25:45 -0700
Subject: [PATCH 01/39] initial code and readme for hierarchical agent example

---
 HierarchicalAgenticRAG/README.md              |  49 +++
 .../openai/docker-compose-agent-openai.yaml   |  56 +++
 .../openai/launch_agent_service_openai.sh     |  10 +
 HierarchicalAgenticRAG/tools/pycragapi.py     | 332 ++++++++++++++++++
 .../tools/supervisor_agent_tools.yaml         |  56 +++
 HierarchicalAgenticRAG/tools/tools.py         |  50 +++
 .../tools/worker_agent_tools.yaml             |   2 +
 7 files changed, 555 insertions(+)
 create mode 100644 HierarchicalAgenticRAG/README.md
 create mode 100644 HierarchicalAgenticRAG/docker/openai/docker-compose-agent-openai.yaml
 create mode 100644 HierarchicalAgenticRAG/docker/openai/launch_agent_service_openai.sh
 create mode 100644 HierarchicalAgenticRAG/tools/pycragapi.py
 create mode 100644 HierarchicalAgenticRAG/tools/supervisor_agent_tools.yaml
 create mode 100644 HierarchicalAgenticRAG/tools/tools.py
 create mode 100644 HierarchicalAgenticRAG/tools/worker_agent_tools.yaml

diff --git a/HierarchicalAgenticRAG/README.md b/HierarchicalAgenticRAG/README.md
new file mode 100644
index 0000000000..9f8bc21a57
--- /dev/null
+++ b/HierarchicalAgenticRAG/README.md
@@ -0,0 +1,49 @@
+# Hierarchical Agentic RAG
+## Overview
+architecture diagram
+## Advantages of Agentic RAG
+TODO
+## Getting started
+1. Build agent docker image
+First, clone the opea GenAIComps repo
+```
+export WORKDIR=<your-work-directory>
+cd $WORKDIR
+git clone https://github.com/opea-project/GenAIComps.git
+```
+Then build the agent docker image. Both the supervisor agent and the worker agent will use the same docker image, but when we launch the two agents we will specify different strategies and register different tools.
+```
+cd GenAIComps
+docker build -t opea/comps-agent-langchain:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/agent/langchain/docker/Dockerfile .
+```
+2. Lanuch tool services
+In this example, we will use some of the mock APIs provided in the Meta CRAG KDD Challenge to demonstrate the benefits of gaining additional context from mock knowledge graphs.
+```
+docker run -d -p=8080:8000 docker.io/aicrowd/kdd-cup-24-crag-mock-api:v0
+```
+3. Set up environment for this example
+First, clone this repo
+```
+cd $WORKDIR
+git clone https://github.com/opea-project/GenAIExamples.git
+```
+Second, set up env vars
+```
+export TOOLSET_PATH=$WORKDIR/GenAIExamples/HierarchicalAgenticRAG/tools/
+# optional: OPANAI_API_KEY
+export OPENAI_API_KEY=<your-openai-key>
+```
+3. Launch agent services
+The configurations of the supervisor agent and the worker agent are defined in the docker-compose yaml file. We currently use openAI GPT-4o-mini as LLM, and we plan to add support for llama3.1-70B-instruct (served by TGI-Gaudi) in a subsequent release.
+To use openai llm, run command below.
+```
+cd docker/openai/
+bash launch_agent_service_openai.sh
+```
+
+
+## Validate services
+
+## Consume agent endpoint
+
+## How to register your own tools with agent
\ No newline at end of file
diff --git a/HierarchicalAgenticRAG/docker/openai/docker-compose-agent-openai.yaml b/HierarchicalAgenticRAG/docker/openai/docker-compose-agent-openai.yaml
new file mode 100644
index 0000000000..e52fcded79
--- /dev/null
+++ b/HierarchicalAgenticRAG/docker/openai/docker-compose-agent-openai.yaml
@@ -0,0 +1,56 @@
+services:
+  worker-docgrader-agent:
+    image: opea/comps-agent-langchain:latest
+    container_name: docgrader-agent-endpoint
+    volumes:
+      - ${WORKDIR}/GenAIComps/comps/agent/langchain/:/home/user/comps/agent/langchain/
+      - ${TOOLSET_PATH}:/home/user/tools/
+    ports:
+      - "9095:9095"
+    ipc: host
+    environment:
+      ip_address: ${ip_address}
+      strategy: docgrader
+      recursion_limit: ${recursion_limit}
+      llm_engine: openai
+      OPENAI_API_KEY: ${OPENAI_API_KEY}
+      model: ${model}
+      temperature: ${temperature}
+      max_new_tokens: ${max_new_tokens}
+      streaming: false
+      tools: /home/user/tools/worker_agent_tools.yaml
+      require_human_feedback: false
+      no_proxy: ${no_proxy}
+      http_proxy: ${http_proxy}
+      https_proxy: ${https_proxy}
+      LANGCHAIN_API_KEY: ${LANGCHAIN_API_KEY}
+      LANGCHAIN_TRACING_V2: ${LANGCHAIN_TRACING_V2}
+      LANGCHAIN_PROJECT: "opea-worker-agent-service"
+    
+  supervisor-react-agent:
+    image: opea/comps-agent-langchain:latest
+    container_name: react-agent-endpoint
+    volumes:
+      - ${WORKDIR}/GenAIComps/comps/agent/langchain/:/home/user/comps/agent/langchain/
+      - ${TOOLSET_PATH}:/home/user/tools/
+    ports:
+      - "9090:9090"
+    ipc: host
+    environment:
+      ip_address: ${ip_address}
+      strategy: react_langgraph
+      recursion_limit: ${recursion_limit}
+      llm_engine: openai
+      OPENAI_API_KEY: ${OPENAI_API_KEY}
+      model: ${model}
+      temperature: ${temperature}
+      max_new_tokens: ${max_new_tokens}
+      streaming: ${streaming}
+      tools: /home/user/tools/supervisor_agent_tools.yaml
+      require_human_feedback: false
+      no_proxy: ${no_proxy}
+      http_proxy: ${http_proxy}
+      https_proxy: ${https_proxy}
+      LANGCHAIN_API_KEY: ${LANGCHAIN_API_KEY}
+      LANGCHAIN_TRACING_V2: ${LANGCHAIN_TRACING_V2}
+      LANGCHAIN_PROJECT: "opea-supervisor-agent-service"
diff --git a/HierarchicalAgenticRAG/docker/openai/launch_agent_service_openai.sh b/HierarchicalAgenticRAG/docker/openai/launch_agent_service_openai.sh
new file mode 100644
index 0000000000..12bcda4c2f
--- /dev/null
+++ b/HierarchicalAgenticRAG/docker/openai/launch_agent_service_openai.sh
@@ -0,0 +1,10 @@
+export ip_address=$(hostname -I | awk '{print $1}')
+export recursion_limit=10
+export model="gpt-4o-mini-2024-07-18"
+export temperature=0
+export max_new_tokens=512
+export OPENAI_API_KEY=${OPENAI_API_KEY}
+export WORKER_AGENT_URL="http://$ip_address:9095/v1/chat/completions"
+export CRAG_SERVER=http://${ip_address}:8080
+
+docker compose -f docker-compose-agent-openai.yaml up -d
\ No newline at end of file
diff --git a/HierarchicalAgenticRAG/tools/pycragapi.py b/HierarchicalAgenticRAG/tools/pycragapi.py
new file mode 100644
index 0000000000..90fe1b7f14
--- /dev/null
+++ b/HierarchicalAgenticRAG/tools/pycragapi.py
@@ -0,0 +1,332 @@
+# Copyright (c) Meta Platforms, Inc. and affiliates.
+# All rights reserved.
+
+# This source code is licensed under the license found in the
+# LICENSE file in the root directory of this source tree.
+
+import json
+import os
+from typing import List
+
+import requests
+
+
+class CRAG(object):
+    """
+    A client for interacting with the CRAG server, offering methods to query various domains such as Open, Movie, Finance, Music, and Sports. Each method corresponds to an API endpoint on the CRAG server.
+
+    Attributes:
+        server (str): The base URL of the CRAG server. Defaults to "http://127.0.0.1:8080".
+
+    Methods:
+        open_search_entity_by_name(query: str) -> dict: Search for entities by name in the Open domain.
+        open_get_entity(entity: str) -> dict: Retrieve detailed information about an entity in the Open domain.
+        movie_get_person_info(person_name: str) -> dict: Get information about a person related to movies.
+        movie_get_movie_info(movie_name: str) -> dict: Get information about a movie.
+        movie_get_year_info(year: str) -> dict: Get information about movies released in a specific year.
+        movie_get_movie_info_by_id(movie_id: int) -> dict: Get movie information by its unique ID.
+        movie_get_person_info_by_id(person_id: int) -> dict: Get person information by their unique ID.
+        finance_get_company_name(query: str) -> dict: Search for company names in the finance domain.
+        finance_get_ticker_by_name(query: str) -> dict: Retrieve the ticker symbol for a given company name.
+        finance_get_price_history(ticker_name: str) -> dict: Get the price history for a given ticker symbol.
+        finance_get_detailed_price_history(ticker_name: str) -> dict: Get detailed price history for a ticker symbol.
+        finance_get_dividends_history(ticker_name: str) -> dict: Get dividend history for a ticker symbol.
+        finance_get_market_capitalization(ticker_name: str) -> dict: Retrieve market capitalization for a ticker symbol.
+        finance_get_eps(ticker_name: str) -> dict: Get earnings per share (EPS) for a ticker symbol.
+        finance_get_pe_ratio(ticker_name: str) -> dict: Get the price-to-earnings (PE) ratio for a ticker symbol.
+        finance_get_info(ticker_name: str) -> dict: Get financial information for a ticker symbol.
+        music_search_artist_entity_by_name(artist_name: str) -> dict: Search for music artists by name.
+        music_search_song_entity_by_name(song_name: str) -> dict: Search for songs by name.
+        music_get_billboard_rank_date(rank: int, date: str = None) -> dict: Get Billboard ranking for a specific rank and date.
+        music_get_billboard_attributes(date: str, attribute: str, song_name: str) -> dict: Get attributes of a song from Billboard rankings.
+        music_grammy_get_best_artist_by_year(year: int) -> dict: Get the Grammy Best New Artist for a specific year.
+        music_grammy_get_award_count_by_artist(artist_name: str) -> dict: Get the total Grammy awards won by an artist.
+        music_grammy_get_award_count_by_song(song_name: str) -> dict: Get the total Grammy awards won by a song.
+        music_grammy_get_best_song_by_year(year: int) -> dict: Get the Grammy Song of the Year for a specific year.
+        music_grammy_get_award_date_by_artist(artist_name: str) -> dict: Get the years an artist won a Grammy award.
+        music_grammy_get_best_album_by_year(year: int) -> dict: Get the Grammy Album of the Year for a specific year.
+        music_grammy_get_all_awarded_artists() -> dict: Get all artists awarded the Grammy Best New Artist.
+        music_get_artist_birth_place(artist_name: str) -> dict: Get the birthplace of an artist.
+        music_get_artist_birth_date(artist_name: str) -> dict: Get the birth date of an artist.
+        music_get_members(band_name: str) -> dict: Get the member list of a band.
+        music_get_lifespan(artist_name: str) -> dict: Get the lifespan of an artist.
+        music_get_song_author(song_name: str) -> dict: Get the author of a song.
+        music_get_song_release_country(song_name: str) -> dict: Get the release country of a song.
+        music_get_song_release_date(song_name: str) -> dict: Get the release date of a song.
+        music_get_artist_all_works(artist_name: str) -> dict: Get all works by an artist.
+        sports_soccer_get_games_on_date(team_name: str, date: str) -> dict: Get soccer games on a specific date.
+        sports_nba_get_games_on_date(team_name: str, date: str) -> dict: Get NBA games on a specific date.
+        sports_nba_get_play_by_play_data_by_game_ids(game_ids: List[str]) -> dict: Get NBA play by play data for a set of game ids.
+
+    Note:
+        Each method performs a POST request to the corresponding API endpoint and returns the response as a JSON dictionary.
+    """    
+    def __init__(self):
+        self.server = os.environ.get('CRAG_SERVER', "http://127.0.0.1:8080")
+    
+    def open_search_entity_by_name(self, query:str):
+        url = self.server + '/open/search_entity_by_name'
+        headers={'accept': "application/json"}
+        data = {'query': query}
+        result = requests.post(url, json=data, headers=headers)
+        return json.loads(result.text)
+
+    def open_get_entity(self, entity:str):
+        url = self.server + '/open/get_entity'
+        headers={'accept': "application/json"}
+        data = {'query': entity}
+        result = requests.post(url, json=data, headers=headers)
+        return json.loads(result.text)
+
+    def movie_get_person_info(self, person_name:str):
+        url = self.server + '/movie/get_person_info'
+        headers={'accept': "application/json"}
+        data = {'query': person_name}
+        result = requests.post(url, json=data, headers=headers)
+        return json.loads(result.text)
+
+    def movie_get_movie_info(self, movie_name:str):
+        url = self.server + '/movie/get_movie_info'
+        headers={'accept': "application/json"}
+        data = {'query': movie_name}
+        result = requests.post(url, json=data, headers=headers)
+        return json.loads(result.text)
+
+    def movie_get_year_info(self, year:str):
+        url = self.server + '/movie/get_year_info'
+        headers={'accept': "application/json"}
+        data = {'query': year}
+        result = requests.post(url, json=data, headers=headers)
+        return json.loads(result.text)
+
+    def movie_get_movie_info_by_id(self, movid_id:int):
+        url = self.server + '/movie/get_movie_info_by_id'
+        headers={'accept': "application/json"}
+        data = {'query': movid_id}
+        result = requests.post(url, json=data, headers=headers)
+        return json.loads(result.text)
+
+    def movie_get_person_info_by_id(self, person_id:int):
+        url = self.server + '/movie/get_person_info_by_id'
+        headers={'accept': "application/json"}
+        data = {'query': person_id}
+        result = requests.post(url, json=data, headers=headers)
+        return json.loads(result.text)
+    
+    def finance_get_company_name(self, query:str):
+        url = self.server + '/finance/get_company_name'
+        headers={'accept': "application/json"}
+        data = {'query': query}
+        result = requests.post(url, json=data, headers=headers)
+        return json.loads(result.text)
+
+    def finance_get_ticker_by_name(self, query:str):
+        url = self.server + '/finance/get_ticker_by_name'
+        headers={'accept': "application/json"}
+        data = {'query': query}
+        result = requests.post(url, json=data, headers=headers)
+        return json.loads(result.text)
+
+    def finance_get_price_history(self, ticker_name:str):
+        url = self.server + '/finance/get_price_history'
+        headers={'accept': "application/json"}
+        data = {'query': ticker_name}
+        result = requests.post(url, json=data, headers=headers)
+        return json.loads(result.text)
+
+    def finance_get_detailed_price_history(self, ticker_name:str):
+        url = self.server + '/finance/get_detailed_price_history'
+        headers={'accept': "application/json"}
+        data = {'query': ticker_name}
+        result = requests.post(url, json=data, headers=headers)
+        return json.loads(result.text)
+
+    def finance_get_dividends_history(self, ticker_name:str):
+        url = self.server + '/finance/get_dividends_history'
+        headers={'accept': "application/json"}
+        data = {'query': ticker_name}
+        result = requests.post(url, json=data, headers=headers)
+        return json.loads(result.text)
+    
+    def finance_get_market_capitalization(self, ticker_name:str):
+        url = self.server + '/finance/get_market_capitalization'
+        headers={'accept': "application/json"}
+        data = {'query': ticker_name}
+        result = requests.post(url, json=data, headers=headers)
+        return json.loads(result.text)
+
+    def finance_get_eps(self, ticker_name:str):
+        url = self.server + '/finance/get_eps'
+        headers={'accept': "application/json"}
+        data = {'query': ticker_name}
+        result = requests.post(url, json=data, headers=headers)
+        return json.loads(result.text)
+
+    def finance_get_pe_ratio(self, ticker_name:str):
+        url = self.server + '/finance/get_pe_ratio'
+        headers={'accept': "application/json"}
+        data = {'query': ticker_name}
+        result = requests.post(url, json=data, headers=headers)
+        return json.loads(result.text)
+
+    def finance_get_info(self, ticker_name:str):
+        url = self.server + '/finance/get_info'
+        headers={'accept': "application/json"}
+        data = {'query': ticker_name}
+        result = requests.post(url, json=data, headers=headers)
+        return json.loads(result.text)
+
+    def music_search_artist_entity_by_name(self, artist_name:str):
+        url = self.server + '/music/search_artist_entity_by_name'
+        headers={'accept': "application/json"}
+        data = {'query': artist_name}
+        result = requests.post(url, json=data, headers=headers)
+        return json.loads(result.text)
+
+    def music_search_song_entity_by_name(self, song_name:str):
+        url = self.server + '/music/search_song_entity_by_name'
+        headers={'accept': "application/json"}
+        data = {'query': song_name}
+        result = requests.post(url, json=data, headers=headers)
+        return json.loads(result.text)
+
+    def music_get_billboard_rank_date(self, rank:int, date:str=None):
+        url = self.server + '/music/get_billboard_rank_date'
+        headers={'accept': "application/json"}
+        data = {'rank': rank, 'date': date}
+        result = requests.post(url, json=data, headers=headers)
+        return json.loads(result.text)
+
+    def music_get_billboard_attributes(self, date:str, attribute:str, song_name:str):
+        url = self.server + '/music/get_billboard_attributes'
+        headers={'accept': "application/json"}
+        data = {'date': date, 'attribute': attribute, 'song_name': song_name}
+        result = requests.post(url, json=data, headers=headers)
+        return json.loads(result.text)
+
+    def music_grammy_get_best_artist_by_year(self, year:int):
+        url = self.server + '/music/grammy_get_best_artist_by_year'
+        headers={'accept': "application/json"}
+        data = {'query': year}
+        result = requests.post(url, json=data, headers=headers)
+        return json.loads(result.text)
+
+    def music_grammy_get_award_count_by_artist(self, artist_name:str):
+        url = self.server + '/music/grammy_get_award_count_by_artist'
+        headers={'accept': "application/json"}
+        data = {'query': artist_name}
+        result = requests.post(url, json=data, headers=headers)
+        return json.loads(result.text)
+
+    def music_grammy_get_award_count_by_song(self, song_name:str):
+        url = self.server + '/music/grammy_get_award_count_by_song'
+        headers={'accept': "application/json"}
+        data = {'query': song_name}
+        result = requests.post(url, json=data, headers=headers)
+        return json.loads(result.text)
+
+    def music_grammy_get_best_song_by_year(self, year:int):
+        url = self.server + '/music/grammy_get_best_song_by_year'
+        headers={'accept': "application/json"}
+        data = {'query': year}
+        result = requests.post(url, json=data, headers=headers)
+        return json.loads(result.text)
+
+    def music_grammy_get_award_date_by_artist(self, artist_name:str):
+        url = self.server + '/music/grammy_get_award_date_by_artist'
+        headers={'accept': "application/json"}
+        data = {'query': artist_name}
+        result = requests.post(url, json=data, headers=headers)
+        return json.loads(result.text)
+
+    def music_grammy_get_best_album_by_year(self, year:int):
+        url = self.server + '/music/grammy_get_best_album_by_year'
+        headers={'accept': "application/json"}
+        data = {'query': year}
+        result = requests.post(url, json=data, headers=headers)
+        return json.loads(result.text)
+
+    def music_grammy_get_all_awarded_artists(self):
+        url = self.server + '/music/grammy_get_all_awarded_artists'
+        headers={'accept': "application/json"}
+        result = requests.post(url, headers=headers)
+        return json.loads(result.text)
+
+    def music_get_artist_birth_place(self, artist_name:str):
+        url = self.server + '/music/get_artist_birth_place'
+        headers={'accept': "application/json"}
+        data = {'query': artist_name}
+        result = requests.post(url, json=data, headers=headers)
+        return json.loads(result.text)
+
+    def music_get_artist_birth_date(self, artist_name:str):
+        url = self.server + '/music/get_artist_birth_date'
+        headers={'accept': "application/json"}
+        data = {'query': artist_name}
+        result = requests.post(url, json=data, headers=headers)
+        return json.loads(result.text)
+
+    def music_get_members(self, band_name:str):
+        url = self.server + '/music/get_members'
+        headers={'accept': "application/json"}
+        data = {'query': band_name}
+        result = requests.post(url, json=data, headers=headers)
+        return json.loads(result.text)
+
+    def music_get_lifespan(self, artist_name:str):
+        url = self.server + '/music/get_lifespan'
+        headers={'accept': "application/json"}
+        data = {'query': artist_name}
+        result = requests.post(url, json=data, headers=headers)
+        return json.loads(result.text)
+
+    def music_get_song_author(self, song_name:str):
+        url = self.server + '/music/get_song_author'
+        headers={'accept': "application/json"}
+        data = {'query': song_name}
+        result = requests.post(url, json=data, headers=headers)
+        return json.loads(result.text)
+
+    def music_get_song_release_country(self, song_name:str):
+        url = self.server + '/music/get_song_release_country'
+        headers={'accept': "application/json"}
+        data = {'query': song_name}
+        result = requests.post(url, json=data, headers=headers)
+        return json.loads(result.text)
+
+    def music_get_song_release_date(self, song_name:str):
+        url = self.server + '/music/get_song_release_date'
+        headers={'accept': "application/json"}
+        data = {'query': song_name}
+        result = requests.post(url, json=data, headers=headers)
+        return json.loads(result.text)
+
+    def music_get_artist_all_works(self, song_name:str):
+        url = self.server + '/music/get_artist_all_works'
+        headers={'accept': "application/json"}
+        data = {'query': song_name}
+        result = requests.post(url, json=data, headers=headers)
+        return json.loads(result.text)
+
+    def sports_soccer_get_games_on_date(self, date:str, team_name:str=None):
+        url = self.server + '/sports/soccer/get_games_on_date'
+        headers={'accept': "application/json"}
+        data = {'team_name': team_name, 'date': date}
+        result = requests.post(url, json=data, headers=headers)
+        return json.loads(result.text)
+
+    def sports_nba_get_games_on_date(self, date:str, team_name:str=None):
+        url = self.server + '/sports/nba/get_games_on_date'
+        headers={'accept': "application/json"}
+        data = {'team_name': team_name, 'date': date}
+        result = requests.post(url, json=data, headers=headers)
+        return json.loads(result.text)
+
+    def sports_nba_get_play_by_play_data_by_game_ids(self, game_ids:List[str]):
+        url = self.server + '/sports/nba/get_play_by_play_data_by_game_ids'
+        headers={'accept': "application/json"}
+        data = {'game_ids': game_ids}
+        result = requests.post(url, json=data, headers=headers)
+        return json.loads(result.text)
+
+    
\ No newline at end of file
diff --git a/HierarchicalAgenticRAG/tools/supervisor_agent_tools.yaml b/HierarchicalAgenticRAG/tools/supervisor_agent_tools.yaml
new file mode 100644
index 0000000000..c2ef47f0ec
--- /dev/null
+++ b/HierarchicalAgenticRAG/tools/supervisor_agent_tools.yaml
@@ -0,0 +1,56 @@
+search_knowledge_base:
+  description: Search knowledge base for a given query. Returns text related to the query.
+  callable_api: tools.py:search_knowledge_base
+  args_schema:
+    query:
+      type: str
+      description: query
+  return_output: retrieved_data
+
+get_artist_birth_place:
+  description: Get the birth place of an artist.
+  callable_api: tools.py:get_artist_birth_place
+  args_schema:
+    artist_name:
+      type: str
+      description: artist name
+  return_output: birth_place
+
+get_billboard_rank_date:
+  description: Get Billboard ranking for a specific rank and date.
+  callable_api: tools.py:get_billboard_rank_date
+  args_schema:
+    rank:
+      type: int
+      description: song name
+    date:
+      type: str
+      description: date
+  return_output: billboard_info
+
+get_song_release_date:
+  description: Get the release date of a song.
+  callable_api: tools.py:get_song_release_date
+  args_schema:
+    song_name:
+      type: str
+      description: song name
+  return_output: release_date
+
+get_members:
+  description: Get the member list of a band.
+  callable_api: tools.py:get_members
+  args_schema:
+    band_name:
+      type: str
+      description: band name
+  return_output: members
+
+get_grammy_best_artist_by_year
+  description: Get the Grammy Best New Artist for a specific year.
+  callable_api: tools.py:get_grammy_best_artist_by_year
+  args_schema:
+    year:
+      type: int
+      description: year
+  return_output: grammy_best_new_artist
\ No newline at end of file
diff --git a/HierarchicalAgenticRAG/tools/tools.py b/HierarchicalAgenticRAG/tools/tools.py
new file mode 100644
index 0000000000..68e1a331d6
--- /dev/null
+++ b/HierarchicalAgenticRAG/tools/tools.py
@@ -0,0 +1,50 @@
+from langchain_core.tools import tool
+import requests
+import os
+from pycragapi import CRAG
+
+@tool
+def search_knowledge_base(query: str) -> str:
+    '''Search the knowledge base for a specific query.'''
+    # use worker agent (DocGrader) to search the knowledge base
+    url = os.environ.get('WORKER_AGENT_URL')
+    proxies = {"http": ""}
+    payload = {
+        "query":query,
+        } 
+    response = requests.post(url, json=payload, proxies=proxies)
+    return response.json()["text"]
+    
+
+@tool
+def get_grammy_best_artist_by_year(year: int) -> dict:
+    '''Get the Grammy Best New Artist for a specific year.'''
+    api = CRAG()
+    year = int(year)
+    return api.music_grammy_get_best_artist_by_year(year)
+
+
+@tool
+def get_members(band_name: str) -> dict:
+    '''Get the member list of a band.'''
+    api = CRAG()
+    return api.music_get_members(band_name)
+
+@tool
+def get_artist_birth_place(artist_name: str) -> dict:
+    '''Get the birthplace of an artist.'''
+    api = CRAG()
+    return api.music_get_artist_birth_place(artist_name)
+
+@tool
+def get_billboard_rank_date(rank: int, date: str = None) -> dict:
+    '''Get Billboard ranking for a specific rank and date.'''
+    api = CRAG()
+    rank = int(rank)
+    return api.music_get_billboard_rank_date(rank, date)
+
+@tool
+def get_song_release_date(song_name: str) -> dict:
+    '''Get the release date of a song.'''
+    api = CRAG()
+    return api.music_get_song_release_date(song_name)
diff --git a/HierarchicalAgenticRAG/tools/worker_agent_tools.yaml b/HierarchicalAgenticRAG/tools/worker_agent_tools.yaml
new file mode 100644
index 0000000000..7b472bca7d
--- /dev/null
+++ b/HierarchicalAgenticRAG/tools/worker_agent_tools.yaml
@@ -0,0 +1,2 @@
+duckduckgo_search:
+  callable_api: ddg-search
\ No newline at end of file

From 814bbab8df3ee3acb0958df77ac65778d2b39d4f Mon Sep 17 00:00:00 2001
From: minmin-intel <minmin.hou@intel.com>
Date: Wed, 14 Aug 2024 11:27:49 -0700
Subject: [PATCH 02/39] agent test with openai llm passed

---
 HierarchicalAgenticRAG/README.md              | 29 ++++++++++++++++---
 .../openai/docker-compose-agent-openai.yaml   |  4 +++
 .../openai/launch_agent_service_openai.sh     |  4 +--
 .../tools/supervisor_agent_tools.yaml         |  2 +-
 HierarchicalAgenticRAG/tools/tools.py         | 15 +++++-----
 5 files changed, 39 insertions(+), 15 deletions(-)

diff --git a/HierarchicalAgenticRAG/README.md b/HierarchicalAgenticRAG/README.md
index 9f8bc21a57..132f876dd3 100644
--- a/HierarchicalAgenticRAG/README.md
+++ b/HierarchicalAgenticRAG/README.md
@@ -1,8 +1,11 @@
 # Hierarchical Agentic RAG
 ## Overview
 architecture diagram
-## Advantages of Agentic RAG
+### Advantages of Agentic RAG
 TODO
+### Supported APIs
+Currently we support OpenAI chat completion compatible API. We are working to support OpenAI assistants APIs.
+
 ## Getting started
 1. Build agent docker image
 First, clone the opea GenAIComps repo
@@ -33,7 +36,7 @@ export TOOLSET_PATH=$WORKDIR/GenAIExamples/HierarchicalAgenticRAG/tools/
 # optional: OPANAI_API_KEY
 export OPENAI_API_KEY=<your-openai-key>
 ```
-3. Launch agent services
+4. Launch agent services
 The configurations of the supervisor agent and the worker agent are defined in the docker-compose yaml file. We currently use openAI GPT-4o-mini as LLM, and we plan to add support for llama3.1-70B-instruct (served by TGI-Gaudi) in a subsequent release.
 To use openai llm, run command below.
 ```
@@ -43,7 +46,25 @@ bash launch_agent_service_openai.sh
 
 
 ## Validate services
+First look at logs of the agent docker containers:
+```
+docker logs docgrader-agent-endpoint
+docker logs react-agent-endpoint
+```
+You should see something like "HTTP server setup successful" if the docker containers are started successfully.</p>
 
-## Consume agent endpoint
+Second, validate worker agent:
+```
+curl http://${ip_address}:9095/v1/chat/completions -X POST -H "Content-Type: application/json" -d '{
+     "query": "Most recent album by Taylor Swift"
+    }'
+``` 
+Third, validate supervisor agent:
+```
+curl http://${ip_address}:9090/v1/chat/completions -X POST -H "Content-Type: application/json" -d '{
+     "query": "Most recent album by Taylor Swift"
+    }'
+```
 
-## How to register your own tools with agent
\ No newline at end of file
+## How to register your own tools with agent
+You can take a look at the tools yaml and python files in this example. For more details, please refer to the "Provide your own tools" section in the instructions [here](https://github.com/minmin-intel/GenAIComps/tree/agent-comp-dev/comps/agent/langchain#4-provide-your-own-tools). 
\ No newline at end of file
diff --git a/HierarchicalAgenticRAG/docker/openai/docker-compose-agent-openai.yaml b/HierarchicalAgenticRAG/docker/openai/docker-compose-agent-openai.yaml
index e52fcded79..f22558dd4d 100644
--- a/HierarchicalAgenticRAG/docker/openai/docker-compose-agent-openai.yaml
+++ b/HierarchicalAgenticRAG/docker/openai/docker-compose-agent-openai.yaml
@@ -26,6 +26,7 @@ services:
       LANGCHAIN_API_KEY: ${LANGCHAIN_API_KEY}
       LANGCHAIN_TRACING_V2: ${LANGCHAIN_TRACING_V2}
       LANGCHAIN_PROJECT: "opea-worker-agent-service"
+      port: 9095
     
   supervisor-react-agent:
     image: opea/comps-agent-langchain:latest
@@ -54,3 +55,6 @@ services:
       LANGCHAIN_API_KEY: ${LANGCHAIN_API_KEY}
       LANGCHAIN_TRACING_V2: ${LANGCHAIN_TRACING_V2}
       LANGCHAIN_PROJECT: "opea-supervisor-agent-service"
+      CRAG_SERVER: $CRAG_SERVER
+      WORKER_AGENT_URL: $WORKER_AGENT_URL
+      port: 9090
diff --git a/HierarchicalAgenticRAG/docker/openai/launch_agent_service_openai.sh b/HierarchicalAgenticRAG/docker/openai/launch_agent_service_openai.sh
index 12bcda4c2f..97be30d12d 100644
--- a/HierarchicalAgenticRAG/docker/openai/launch_agent_service_openai.sh
+++ b/HierarchicalAgenticRAG/docker/openai/launch_agent_service_openai.sh
@@ -1,10 +1,10 @@
 export ip_address=$(hostname -I | awk '{print $1}')
-export recursion_limit=10
+export recursion_limit=12
 export model="gpt-4o-mini-2024-07-18"
 export temperature=0
 export max_new_tokens=512
 export OPENAI_API_KEY=${OPENAI_API_KEY}
-export WORKER_AGENT_URL="http://$ip_address:9095/v1/chat/completions"
+export WORKER_AGENT_URL="http://${ip_address}:9095/v1/chat/completions"
 export CRAG_SERVER=http://${ip_address}:8080
 
 docker compose -f docker-compose-agent-openai.yaml up -d
\ No newline at end of file
diff --git a/HierarchicalAgenticRAG/tools/supervisor_agent_tools.yaml b/HierarchicalAgenticRAG/tools/supervisor_agent_tools.yaml
index c2ef47f0ec..7983774fa0 100644
--- a/HierarchicalAgenticRAG/tools/supervisor_agent_tools.yaml
+++ b/HierarchicalAgenticRAG/tools/supervisor_agent_tools.yaml
@@ -46,7 +46,7 @@ get_members:
       description: band name
   return_output: members
 
-get_grammy_best_artist_by_year
+get_grammy_best_artist_by_year:
   description: Get the Grammy Best New Artist for a specific year.
   callable_api: tools.py:get_grammy_best_artist_by_year
   args_schema:
diff --git a/HierarchicalAgenticRAG/tools/tools.py b/HierarchicalAgenticRAG/tools/tools.py
index 68e1a331d6..5bd87f8e1d 100644
--- a/HierarchicalAgenticRAG/tools/tools.py
+++ b/HierarchicalAgenticRAG/tools/tools.py
@@ -1,13 +1,12 @@
-from langchain_core.tools import tool
 import requests
 import os
-from pycragapi import CRAG
+from tools.pycragapi import CRAG
 
-@tool
 def search_knowledge_base(query: str) -> str:
     '''Search the knowledge base for a specific query.'''
     # use worker agent (DocGrader) to search the knowledge base
     url = os.environ.get('WORKER_AGENT_URL')
+    print(url)
     proxies = {"http": ""}
     payload = {
         "query":query,
@@ -16,7 +15,7 @@ def search_knowledge_base(query: str) -> str:
     return response.json()["text"]
     
 
-@tool
+
 def get_grammy_best_artist_by_year(year: int) -> dict:
     '''Get the Grammy Best New Artist for a specific year.'''
     api = CRAG()
@@ -24,26 +23,26 @@ def get_grammy_best_artist_by_year(year: int) -> dict:
     return api.music_grammy_get_best_artist_by_year(year)
 
 
-@tool
+
 def get_members(band_name: str) -> dict:
     '''Get the member list of a band.'''
     api = CRAG()
     return api.music_get_members(band_name)
 
-@tool
+
 def get_artist_birth_place(artist_name: str) -> dict:
     '''Get the birthplace of an artist.'''
     api = CRAG()
     return api.music_get_artist_birth_place(artist_name)
 
-@tool
+
 def get_billboard_rank_date(rank: int, date: str = None) -> dict:
     '''Get Billboard ranking for a specific rank and date.'''
     api = CRAG()
     rank = int(rank)
     return api.music_get_billboard_rank_date(rank, date)
 
-@tool
+
 def get_song_release_date(song_name: str) -> dict:
     '''Get the release date of a song.'''
     api = CRAG()

From 497f5dc65b4e57f3a0d58e1d948852fb7b7885ad Mon Sep 17 00:00:00 2001
From: minmin-intel <minmin.hou@intel.com>
Date: Wed, 14 Aug 2024 16:05:32 -0700
Subject: [PATCH 03/39] update readme and add test

---
 HierarchicalAgenticRAG/README.md              |  31 ++++--
 .../assets/hierarchical_agentic_rag_arch.png  | Bin 0 -> 70399 bytes
 .../test_hierarchicalagenticrag_on_openai.sh  |  89 ++++++++++++++++++
 3 files changed, 110 insertions(+), 10 deletions(-)
 create mode 100644 HierarchicalAgenticRAG/assets/hierarchical_agentic_rag_arch.png
 create mode 100644 HierarchicalAgenticRAG/tests/test_hierarchicalagenticrag_on_openai.sh

diff --git a/HierarchicalAgenticRAG/README.md b/HierarchicalAgenticRAG/README.md
index 132f876dd3..4970d0b59b 100644
--- a/HierarchicalAgenticRAG/README.md
+++ b/HierarchicalAgenticRAG/README.md
@@ -1,13 +1,23 @@
 # Hierarchical Agentic RAG
 ## Overview
-architecture diagram
-### Advantages of Agentic RAG
-TODO
-### Supported APIs
-Currently we support OpenAI chat completion compatible API. We are working to support OpenAI assistants APIs.
+This example showcases a hierarchical multi-agent system for question-answering applications. The architecture diagram is shown below. The supervisor agent interfaces with the user and dispatch tasks to the worker agent and other tools to gather information and come up with answers. The worker agent uses the retrieval tool to generate answers to the queries posted by the supervisor agent. Other tools used by the supervisor agent may include APIs to interface knowledge graphs, SQL databases, external knowledge bases, etc.
+![Architecture Overview](assets/hierarchical_agentic_rag_arch.png)
+### Why Agentic RAG?
+1. Improve relevancy of retrieved context.
+Agent can rephrase user queries, decompose user queries, and iterate to get the most relevant context for answering user's questions.
+2. Use tools to get additional knowledge.
+For example, knowledge graphs and SQL databases can be exposed as APIs for Agents to gather knowledge that may be missing in the retrieval vector database.
+3. Hierarchical agent can further improve performance.
+Expert worker agents, such as retrieval agent, knowledge graph agent, SQL agent, etc., can provide high-quality output for different aspects of a complex query, and the supervisor agent can aggregate the information together to provide a comprehensive answer.
+
+### Roadmap
+* v0.9: Worker agent uses open-source websearch tool (duckduckgo), agents use OpenAI GPT-4o-mini as llm backend.
+* v1.0: Worker agent uses OPEA retrieval megaservice as tool, 
+* v1.0 or later: agents use open-source llm backend.
+* v1.1 or later: add safeguards
 
 ## Getting started
-1. Build agent docker image
+1. Build agent docker image </br>
 First, clone the opea GenAIComps repo
 ```
 export WORKDIR=<your-work-directory>
@@ -19,12 +29,12 @@ Then build the agent docker image. Both the supervisor agent and the worker agen
 cd GenAIComps
 docker build -t opea/comps-agent-langchain:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/agent/langchain/docker/Dockerfile .
 ```
-2. Lanuch tool services
+2. Lanuch tool services </br>
 In this example, we will use some of the mock APIs provided in the Meta CRAG KDD Challenge to demonstrate the benefits of gaining additional context from mock knowledge graphs.
 ```
 docker run -d -p=8080:8000 docker.io/aicrowd/kdd-cup-24-crag-mock-api:v0
 ```
-3. Set up environment for this example
+3. Set up environment for this example </br>
 First, clone this repo
 ```
 cd $WORKDIR
@@ -36,7 +46,7 @@ export TOOLSET_PATH=$WORKDIR/GenAIExamples/HierarchicalAgenticRAG/tools/
 # optional: OPANAI_API_KEY
 export OPENAI_API_KEY=<your-openai-key>
 ```
-4. Launch agent services
+4. Launch agent services</br>
 The configurations of the supervisor agent and the worker agent are defined in the docker-compose yaml file. We currently use openAI GPT-4o-mini as LLM, and we plan to add support for llama3.1-70B-instruct (served by TGI-Gaudi) in a subsequent release.
 To use openai llm, run command below.
 ```
@@ -44,11 +54,12 @@ cd docker/openai/
 bash launch_agent_service_openai.sh
 ```
 
-
 ## Validate services
 First look at logs of the agent docker containers:
 ```
 docker logs docgrader-agent-endpoint
+```
+```
 docker logs react-agent-endpoint
 ```
 You should see something like "HTTP server setup successful" if the docker containers are started successfully.</p>
diff --git a/HierarchicalAgenticRAG/assets/hierarchical_agentic_rag_arch.png b/HierarchicalAgenticRAG/assets/hierarchical_agentic_rag_arch.png
new file mode 100644
index 0000000000000000000000000000000000000000..3bebb1d9972e58813811c0fd997d52f015e60fa3
GIT binary patch
diff --git a/HierarchicalAgenticRAG/tests/test_hierarchicalagenticrag_on_openai.sh b/HierarchicalAgenticRAG/tests/test_hierarchicalagenticrag_on_openai.sh
new file mode 100644
index 0000000000..58b556a93d
--- /dev/null
+++ b/HierarchicalAgenticRAG/tests/test_hierarchicalagenticrag_on_openai.sh
@@ -0,0 +1,89 @@
+#!/bin/bash
+# Copyright (C) 2024 Intel Corporation
+# SPDX-License-Identifier: Apache-2.0
+
+set -e
+echo "IMAGE_REPO=${IMAGE_REPO}"
+echo "OPENAI_API_KEY=${OPENAI_API_KEY}"
+
+WORKPATH=$(dirname "$PWD")
+WORKDIR=$WORKPATH/../../
+echo "WORKDIR=${WORKDIR}"
+export ip_address=$(hostname -I | awk '{print $1}')
+
+function build_agent_docker_image() {
+    cd $WORKDIR
+    if [ ! -d "GenAIComps" ] ; then
+        git clone https://github.com/opea-project/GenAIComps.git
+    fi
+    cd GenAIComps
+    local CUR=$(git branch --show-current)
+    echo "Check out agent component, Current Branch is ${CUR}"
+    if [ "${CUR}" != "PR480" ] ; then
+        git fetch origin pull/314/head:PR480; git checkout PR480
+    fi
+    docker build -t opea/comps-agent-langchain:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/agent/langchain/docker/Dockerfile .
+}
+
+function start_services() {
+    echo "Starting CRAG server"
+    docker run -d -p=8080:8000 docker.io/aicrowd/kdd-cup-24-crag-mock-api:v0
+    echo "Starting Agent services"
+    export TOOLSET_PATH=$WORKDIR/GenAIExamples/HierarchicalAgenticRAG/tools/
+    cd $WORKDIR/GenAIExamples/HierarchicalAgenticRAG/docker/openai
+    bash launch_agent_service_openai.sh
+}
+
+function validate() {
+    local CONTENT="$1"
+    local EXPECTED_RESULT="$2"
+    local SERVICE_NAME="$3"
+
+    if echo "$CONTENT" | grep -q "$EXPECTED_RESULT"; then
+        echo "[ $SERVICE_NAME ] Content is as expected: $CONTENT"
+        echo 0
+    else
+        echo "[ $SERVICE_NAME ] Content does not match the expected result: $CONTENT"
+        echo 1
+    fi
+}
+
+
+function run_tests() {
+    echo "----------------Test worker agent----------------"
+    local CONTENT=$(curl http://${ip_address}:9095/v1/chat/completions -X POST -H "Content-Type: application/json" -d '{
+     "query": "Most recent album by Taylor Swift"
+    }')
+    local EXIT_CODE=$(validate "$CONTENT" "Taylor" "docgrader-agent-endpoint")
+    docker logs docgrader-agent-endpoint
+    if [ "$EXIT_CODE" == "1" ]; then
+        exit 1
+    fi
+
+    echo "----------------Test supervisor agent ----------------"
+    local CONTENT=$(curl http://${ip_address}:9090/v1/chat/completions -X POST -H "Content-Type: application/json" -d '{
+     "query": "Most recent album by Taylor Swift"
+    }')
+    local EXIT_CODE=$(validate "$CONTENT" "Taylor" "react-agent-endpoint")
+    docker logs react-agent-endpoint
+    if [ "$EXIT_CODE" == "1" ]; then
+        exit 1
+    fi
+
+}
+
+function stop_services() {
+    echo "Stopping CRAG server"
+    docker stop $(docker ps -q --filter ancestor=docker.io/aicrowd/kdd-cup-24-crag-mock-api:v0)
+    echo "Stopping Agent services"
+    docker stop $(docker ps -q --filter ancestor=opea/comps-agent-langchain:latest)
+}
+
+function main() {
+    build_agent_docker_image
+    start_services
+    run_tests
+    stop_services
+}
+
+main
\ No newline at end of file

From ae7517032da05d36bcbff918541c400e031697b8 Mon Sep 17 00:00:00 2001
From: minmin-intel <minmin.hou@intel.com>
Date: Wed, 14 Aug 2024 17:22:46 -0700
Subject: [PATCH 04/39] update test

---
 .../test_hierarchicalagenticrag_on_openai.sh      | 15 +++------------
 1 file changed, 3 insertions(+), 12 deletions(-)

diff --git a/HierarchicalAgenticRAG/tests/test_hierarchicalagenticrag_on_openai.sh b/HierarchicalAgenticRAG/tests/test_hierarchicalagenticrag_on_openai.sh
index 58b556a93d..befbc2ca77 100644
--- a/HierarchicalAgenticRAG/tests/test_hierarchicalagenticrag_on_openai.sh
+++ b/HierarchicalAgenticRAG/tests/test_hierarchicalagenticrag_on_openai.sh
@@ -17,10 +17,11 @@ function build_agent_docker_image() {
         git clone https://github.com/opea-project/GenAIComps.git
     fi
     cd GenAIComps
+    echo PWD: $(pwd)
     local CUR=$(git branch --show-current)
     echo "Check out agent component, Current Branch is ${CUR}"
     if [ "${CUR}" != "PR480" ] ; then
-        git fetch origin pull/314/head:PR480; git checkout PR480
+        git fetch origin pull/480/head:PR480; git checkout PR480
     fi
     docker build -t opea/comps-agent-langchain:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/agent/langchain/docker/Dockerfile .
 }
@@ -50,18 +51,8 @@ function validate() {
 
 
 function run_tests() {
-    echo "----------------Test worker agent----------------"
-    local CONTENT=$(curl http://${ip_address}:9095/v1/chat/completions -X POST -H "Content-Type: application/json" -d '{
-     "query": "Most recent album by Taylor Swift"
-    }')
-    local EXIT_CODE=$(validate "$CONTENT" "Taylor" "docgrader-agent-endpoint")
-    docker logs docgrader-agent-endpoint
-    if [ "$EXIT_CODE" == "1" ]; then
-        exit 1
-    fi
-
     echo "----------------Test supervisor agent ----------------"
-    local CONTENT=$(curl http://${ip_address}:9090/v1/chat/completions -X POST -H "Content-Type: application/json" -d '{
+    local CONTENT=$(http_proxy="" curl http://${ip_address}:9090/v1/chat/completions -X POST -H "Content-Type: application/json" -d '{
      "query": "Most recent album by Taylor Swift"
     }')
     local EXIT_CODE=$(validate "$CONTENT" "Taylor" "react-agent-endpoint")

From 6e71cd92f8f198f89f78f64549b50064e7dad94f Mon Sep 17 00:00:00 2001
From: "pre-commit-ci[bot]"
 <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Date: Thu, 15 Aug 2024 15:54:21 +0000
Subject: [PATCH 05/39] [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci
---
 HierarchicalAgenticRAG/README.md              |  55 ++-
 .../openai/docker-compose-agent-openai.yaml   |   5 +-
 .../openai/launch_agent_service_openai.sh     |   5 +-
 .../test_hierarchicalagenticrag_on_openai.sh  |   2 +-
 HierarchicalAgenticRAG/tools/pycragapi.py     | 316 +++++++++---------
 .../tools/supervisor_agent_tools.yaml         |   5 +-
 HierarchicalAgenticRAG/tools/tools.py         |  27 +-
 .../tools/worker_agent_tools.yaml             |   5 +-
 8 files changed, 229 insertions(+), 191 deletions(-)

diff --git a/HierarchicalAgenticRAG/README.md b/HierarchicalAgenticRAG/README.md
index 4970d0b59b..0be92f1e07 100644
--- a/HierarchicalAgenticRAG/README.md
+++ b/HierarchicalAgenticRAG/README.md
@@ -1,76 +1,100 @@
 # Hierarchical Agentic RAG
+
 ## Overview
+
 This example showcases a hierarchical multi-agent system for question-answering applications. The architecture diagram is shown below. The supervisor agent interfaces with the user and dispatch tasks to the worker agent and other tools to gather information and come up with answers. The worker agent uses the retrieval tool to generate answers to the queries posted by the supervisor agent. Other tools used by the supervisor agent may include APIs to interface knowledge graphs, SQL databases, external knowledge bases, etc.
 ![Architecture Overview](assets/hierarchical_agentic_rag_arch.png)
+
 ### Why Agentic RAG?
+
 1. Improve relevancy of retrieved context.
-Agent can rephrase user queries, decompose user queries, and iterate to get the most relevant context for answering user's questions.
+   Agent can rephrase user queries, decompose user queries, and iterate to get the most relevant context for answering user's questions.
 2. Use tools to get additional knowledge.
-For example, knowledge graphs and SQL databases can be exposed as APIs for Agents to gather knowledge that may be missing in the retrieval vector database.
+   For example, knowledge graphs and SQL databases can be exposed as APIs for Agents to gather knowledge that may be missing in the retrieval vector database.
 3. Hierarchical agent can further improve performance.
-Expert worker agents, such as retrieval agent, knowledge graph agent, SQL agent, etc., can provide high-quality output for different aspects of a complex query, and the supervisor agent can aggregate the information together to provide a comprehensive answer.
+   Expert worker agents, such as retrieval agent, knowledge graph agent, SQL agent, etc., can provide high-quality output for different aspects of a complex query, and the supervisor agent can aggregate the information together to provide a comprehensive answer.
 
 ### Roadmap
-* v0.9: Worker agent uses open-source websearch tool (duckduckgo), agents use OpenAI GPT-4o-mini as llm backend.
-* v1.0: Worker agent uses OPEA retrieval megaservice as tool, 
-* v1.0 or later: agents use open-source llm backend.
-* v1.1 or later: add safeguards
+
+- v0.9: Worker agent uses open-source websearch tool (duckduckgo), agents use OpenAI GPT-4o-mini as llm backend.
+- v1.0: Worker agent uses OPEA retrieval megaservice as tool,
+- v1.0 or later: agents use open-source llm backend.
+- v1.1 or later: add safeguards
 
 ## Getting started
+
 1. Build agent docker image </br>
-First, clone the opea GenAIComps repo
+   First, clone the opea GenAIComps repo
+
 ```
 export WORKDIR=<your-work-directory>
 cd $WORKDIR
 git clone https://github.com/opea-project/GenAIComps.git
 ```
+
 Then build the agent docker image. Both the supervisor agent and the worker agent will use the same docker image, but when we launch the two agents we will specify different strategies and register different tools.
+
 ```
 cd GenAIComps
 docker build -t opea/comps-agent-langchain:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/agent/langchain/docker/Dockerfile .
 ```
-2. Lanuch tool services </br>
-In this example, we will use some of the mock APIs provided in the Meta CRAG KDD Challenge to demonstrate the benefits of gaining additional context from mock knowledge graphs.
+
+2. Launch tool services </br>
+   In this example, we will use some of the mock APIs provided in the Meta CRAG KDD Challenge to demonstrate the benefits of gaining additional context from mock knowledge graphs.
+
 ```
 docker run -d -p=8080:8000 docker.io/aicrowd/kdd-cup-24-crag-mock-api:v0
 ```
+
 3. Set up environment for this example </br>
-First, clone this repo
+   First, clone this repo
+
 ```
 cd $WORKDIR
 git clone https://github.com/opea-project/GenAIExamples.git
 ```
+
 Second, set up env vars
+
 ```
 export TOOLSET_PATH=$WORKDIR/GenAIExamples/HierarchicalAgenticRAG/tools/
 # optional: OPANAI_API_KEY
 export OPENAI_API_KEY=<your-openai-key>
 ```
+
 4. Launch agent services</br>
-The configurations of the supervisor agent and the worker agent are defined in the docker-compose yaml file. We currently use openAI GPT-4o-mini as LLM, and we plan to add support for llama3.1-70B-instruct (served by TGI-Gaudi) in a subsequent release.
-To use openai llm, run command below.
+   The configurations of the supervisor agent and the worker agent are defined in the docker-compose yaml file. We currently use openAI GPT-4o-mini as LLM, and we plan to add support for llama3.1-70B-instruct (served by TGI-Gaudi) in a subsequent release.
+   To use openai llm, run command below.
+
 ```
 cd docker/openai/
 bash launch_agent_service_openai.sh
 ```
 
 ## Validate services
+
 First look at logs of the agent docker containers:
+
 ```
 docker logs docgrader-agent-endpoint
 ```
+
 ```
 docker logs react-agent-endpoint
 ```
+
 You should see something like "HTTP server setup successful" if the docker containers are started successfully.</p>
 
 Second, validate worker agent:
+
 ```
 curl http://${ip_address}:9095/v1/chat/completions -X POST -H "Content-Type: application/json" -d '{
      "query": "Most recent album by Taylor Swift"
     }'
-``` 
+```
+
 Third, validate supervisor agent:
+
 ```
 curl http://${ip_address}:9090/v1/chat/completions -X POST -H "Content-Type: application/json" -d '{
      "query": "Most recent album by Taylor Swift"
@@ -78,4 +102,5 @@ curl http://${ip_address}:9090/v1/chat/completions -X POST -H "Content-Type: app
 ```
 
 ## How to register your own tools with agent
-You can take a look at the tools yaml and python files in this example. For more details, please refer to the "Provide your own tools" section in the instructions [here](https://github.com/minmin-intel/GenAIComps/tree/agent-comp-dev/comps/agent/langchain#4-provide-your-own-tools). 
\ No newline at end of file
+
+You can take a look at the tools yaml and python files in this example. For more details, please refer to the "Provide your own tools" section in the instructions [here](https://github.com/minmin-intel/GenAIComps/tree/agent-comp-dev/comps/agent/langchain#4-provide-your-own-tools).
diff --git a/HierarchicalAgenticRAG/docker/openai/docker-compose-agent-openai.yaml b/HierarchicalAgenticRAG/docker/openai/docker-compose-agent-openai.yaml
index f22558dd4d..6da595d94c 100644
--- a/HierarchicalAgenticRAG/docker/openai/docker-compose-agent-openai.yaml
+++ b/HierarchicalAgenticRAG/docker/openai/docker-compose-agent-openai.yaml
@@ -1,3 +1,6 @@
+# Copyright (C) 2024 Intel Corporation
+# SPDX-License-Identifier: Apache-2.0
+
 services:
   worker-docgrader-agent:
     image: opea/comps-agent-langchain:latest
@@ -27,7 +30,7 @@ services:
       LANGCHAIN_TRACING_V2: ${LANGCHAIN_TRACING_V2}
       LANGCHAIN_PROJECT: "opea-worker-agent-service"
       port: 9095
-    
+
   supervisor-react-agent:
     image: opea/comps-agent-langchain:latest
     container_name: react-agent-endpoint
diff --git a/HierarchicalAgenticRAG/docker/openai/launch_agent_service_openai.sh b/HierarchicalAgenticRAG/docker/openai/launch_agent_service_openai.sh
index 97be30d12d..7cc197ccc8 100644
--- a/HierarchicalAgenticRAG/docker/openai/launch_agent_service_openai.sh
+++ b/HierarchicalAgenticRAG/docker/openai/launch_agent_service_openai.sh
@@ -1,3 +1,6 @@
+# Copyright (C) 2024 Intel Corporation
+# SPDX-License-Identifier: Apache-2.0
+
 export ip_address=$(hostname -I | awk '{print $1}')
 export recursion_limit=12
 export model="gpt-4o-mini-2024-07-18"
@@ -7,4 +10,4 @@ export OPENAI_API_KEY=${OPENAI_API_KEY}
 export WORKER_AGENT_URL="http://${ip_address}:9095/v1/chat/completions"
 export CRAG_SERVER=http://${ip_address}:8080
 
-docker compose -f docker-compose-agent-openai.yaml up -d
\ No newline at end of file
+docker compose -f docker-compose-agent-openai.yaml up -d
diff --git a/HierarchicalAgenticRAG/tests/test_hierarchicalagenticrag_on_openai.sh b/HierarchicalAgenticRAG/tests/test_hierarchicalagenticrag_on_openai.sh
index befbc2ca77..6ae4b96b92 100644
--- a/HierarchicalAgenticRAG/tests/test_hierarchicalagenticrag_on_openai.sh
+++ b/HierarchicalAgenticRAG/tests/test_hierarchicalagenticrag_on_openai.sh
@@ -77,4 +77,4 @@ function main() {
     stop_services
 }
 
-main
\ No newline at end of file
+main
diff --git a/HierarchicalAgenticRAG/tools/pycragapi.py b/HierarchicalAgenticRAG/tools/pycragapi.py
index 90fe1b7f14..52cdd9b063 100644
--- a/HierarchicalAgenticRAG/tools/pycragapi.py
+++ b/HierarchicalAgenticRAG/tools/pycragapi.py
@@ -12,8 +12,7 @@
 
 
 class CRAG(object):
-    """
-    A client for interacting with the CRAG server, offering methods to query various domains such as Open, Movie, Finance, Music, and Sports. Each method corresponds to an API endpoint on the CRAG server.
+    """A client for interacting with the CRAG server, offering methods to query various domains such as Open, Movie, Finance, Music, and Sports. Each method corresponds to an API endpoint on the CRAG server.
 
     Attributes:
         server (str): The base URL of the CRAG server. Defaults to "http://127.0.0.1:8080".
@@ -60,273 +59,272 @@ class CRAG(object):
 
     Note:
         Each method performs a POST request to the corresponding API endpoint and returns the response as a JSON dictionary.
-    """    
+    """
+
     def __init__(self):
-        self.server = os.environ.get('CRAG_SERVER', "http://127.0.0.1:8080")
-    
-    def open_search_entity_by_name(self, query:str):
-        url = self.server + '/open/search_entity_by_name'
-        headers={'accept': "application/json"}
-        data = {'query': query}
+        self.server = os.environ.get("CRAG_SERVER", "http://127.0.0.1:8080")
+
+    def open_search_entity_by_name(self, query: str):
+        url = self.server + "/open/search_entity_by_name"
+        headers = {"accept": "application/json"}
+        data = {"query": query}
         result = requests.post(url, json=data, headers=headers)
         return json.loads(result.text)
 
-    def open_get_entity(self, entity:str):
-        url = self.server + '/open/get_entity'
-        headers={'accept': "application/json"}
-        data = {'query': entity}
+    def open_get_entity(self, entity: str):
+        url = self.server + "/open/get_entity"
+        headers = {"accept": "application/json"}
+        data = {"query": entity}
         result = requests.post(url, json=data, headers=headers)
         return json.loads(result.text)
 
-    def movie_get_person_info(self, person_name:str):
-        url = self.server + '/movie/get_person_info'
-        headers={'accept': "application/json"}
-        data = {'query': person_name}
+    def movie_get_person_info(self, person_name: str):
+        url = self.server + "/movie/get_person_info"
+        headers = {"accept": "application/json"}
+        data = {"query": person_name}
         result = requests.post(url, json=data, headers=headers)
         return json.loads(result.text)
 
-    def movie_get_movie_info(self, movie_name:str):
-        url = self.server + '/movie/get_movie_info'
-        headers={'accept': "application/json"}
-        data = {'query': movie_name}
+    def movie_get_movie_info(self, movie_name: str):
+        url = self.server + "/movie/get_movie_info"
+        headers = {"accept": "application/json"}
+        data = {"query": movie_name}
         result = requests.post(url, json=data, headers=headers)
         return json.loads(result.text)
 
-    def movie_get_year_info(self, year:str):
-        url = self.server + '/movie/get_year_info'
-        headers={'accept': "application/json"}
-        data = {'query': year}
+    def movie_get_year_info(self, year: str):
+        url = self.server + "/movie/get_year_info"
+        headers = {"accept": "application/json"}
+        data = {"query": year}
         result = requests.post(url, json=data, headers=headers)
         return json.loads(result.text)
 
-    def movie_get_movie_info_by_id(self, movid_id:int):
-        url = self.server + '/movie/get_movie_info_by_id'
-        headers={'accept': "application/json"}
-        data = {'query': movid_id}
+    def movie_get_movie_info_by_id(self, movid_id: int):
+        url = self.server + "/movie/get_movie_info_by_id"
+        headers = {"accept": "application/json"}
+        data = {"query": movid_id}
         result = requests.post(url, json=data, headers=headers)
         return json.loads(result.text)
 
-    def movie_get_person_info_by_id(self, person_id:int):
-        url = self.server + '/movie/get_person_info_by_id'
-        headers={'accept': "application/json"}
-        data = {'query': person_id}
+    def movie_get_person_info_by_id(self, person_id: int):
+        url = self.server + "/movie/get_person_info_by_id"
+        headers = {"accept": "application/json"}
+        data = {"query": person_id}
         result = requests.post(url, json=data, headers=headers)
         return json.loads(result.text)
-    
-    def finance_get_company_name(self, query:str):
-        url = self.server + '/finance/get_company_name'
-        headers={'accept': "application/json"}
-        data = {'query': query}
+
+    def finance_get_company_name(self, query: str):
+        url = self.server + "/finance/get_company_name"
+        headers = {"accept": "application/json"}
+        data = {"query": query}
         result = requests.post(url, json=data, headers=headers)
         return json.loads(result.text)
 
-    def finance_get_ticker_by_name(self, query:str):
-        url = self.server + '/finance/get_ticker_by_name'
-        headers={'accept': "application/json"}
-        data = {'query': query}
+    def finance_get_ticker_by_name(self, query: str):
+        url = self.server + "/finance/get_ticker_by_name"
+        headers = {"accept": "application/json"}
+        data = {"query": query}
         result = requests.post(url, json=data, headers=headers)
         return json.loads(result.text)
 
-    def finance_get_price_history(self, ticker_name:str):
-        url = self.server + '/finance/get_price_history'
-        headers={'accept': "application/json"}
-        data = {'query': ticker_name}
+    def finance_get_price_history(self, ticker_name: str):
+        url = self.server + "/finance/get_price_history"
+        headers = {"accept": "application/json"}
+        data = {"query": ticker_name}
         result = requests.post(url, json=data, headers=headers)
         return json.loads(result.text)
 
-    def finance_get_detailed_price_history(self, ticker_name:str):
-        url = self.server + '/finance/get_detailed_price_history'
-        headers={'accept': "application/json"}
-        data = {'query': ticker_name}
+    def finance_get_detailed_price_history(self, ticker_name: str):
+        url = self.server + "/finance/get_detailed_price_history"
+        headers = {"accept": "application/json"}
+        data = {"query": ticker_name}
         result = requests.post(url, json=data, headers=headers)
         return json.loads(result.text)
 
-    def finance_get_dividends_history(self, ticker_name:str):
-        url = self.server + '/finance/get_dividends_history'
-        headers={'accept': "application/json"}
-        data = {'query': ticker_name}
+    def finance_get_dividends_history(self, ticker_name: str):
+        url = self.server + "/finance/get_dividends_history"
+        headers = {"accept": "application/json"}
+        data = {"query": ticker_name}
         result = requests.post(url, json=data, headers=headers)
         return json.loads(result.text)
-    
-    def finance_get_market_capitalization(self, ticker_name:str):
-        url = self.server + '/finance/get_market_capitalization'
-        headers={'accept': "application/json"}
-        data = {'query': ticker_name}
+
+    def finance_get_market_capitalization(self, ticker_name: str):
+        url = self.server + "/finance/get_market_capitalization"
+        headers = {"accept": "application/json"}
+        data = {"query": ticker_name}
         result = requests.post(url, json=data, headers=headers)
         return json.loads(result.text)
 
-    def finance_get_eps(self, ticker_name:str):
-        url = self.server + '/finance/get_eps'
-        headers={'accept': "application/json"}
-        data = {'query': ticker_name}
+    def finance_get_eps(self, ticker_name: str):
+        url = self.server + "/finance/get_eps"
+        headers = {"accept": "application/json"}
+        data = {"query": ticker_name}
         result = requests.post(url, json=data, headers=headers)
         return json.loads(result.text)
 
-    def finance_get_pe_ratio(self, ticker_name:str):
-        url = self.server + '/finance/get_pe_ratio'
-        headers={'accept': "application/json"}
-        data = {'query': ticker_name}
+    def finance_get_pe_ratio(self, ticker_name: str):
+        url = self.server + "/finance/get_pe_ratio"
+        headers = {"accept": "application/json"}
+        data = {"query": ticker_name}
         result = requests.post(url, json=data, headers=headers)
         return json.loads(result.text)
 
-    def finance_get_info(self, ticker_name:str):
-        url = self.server + '/finance/get_info'
-        headers={'accept': "application/json"}
-        data = {'query': ticker_name}
+    def finance_get_info(self, ticker_name: str):
+        url = self.server + "/finance/get_info"
+        headers = {"accept": "application/json"}
+        data = {"query": ticker_name}
         result = requests.post(url, json=data, headers=headers)
         return json.loads(result.text)
 
-    def music_search_artist_entity_by_name(self, artist_name:str):
-        url = self.server + '/music/search_artist_entity_by_name'
-        headers={'accept': "application/json"}
-        data = {'query': artist_name}
+    def music_search_artist_entity_by_name(self, artist_name: str):
+        url = self.server + "/music/search_artist_entity_by_name"
+        headers = {"accept": "application/json"}
+        data = {"query": artist_name}
         result = requests.post(url, json=data, headers=headers)
         return json.loads(result.text)
 
-    def music_search_song_entity_by_name(self, song_name:str):
-        url = self.server + '/music/search_song_entity_by_name'
-        headers={'accept': "application/json"}
-        data = {'query': song_name}
+    def music_search_song_entity_by_name(self, song_name: str):
+        url = self.server + "/music/search_song_entity_by_name"
+        headers = {"accept": "application/json"}
+        data = {"query": song_name}
         result = requests.post(url, json=data, headers=headers)
         return json.loads(result.text)
 
-    def music_get_billboard_rank_date(self, rank:int, date:str=None):
-        url = self.server + '/music/get_billboard_rank_date'
-        headers={'accept': "application/json"}
-        data = {'rank': rank, 'date': date}
+    def music_get_billboard_rank_date(self, rank: int, date: str = None):
+        url = self.server + "/music/get_billboard_rank_date"
+        headers = {"accept": "application/json"}
+        data = {"rank": rank, "date": date}
         result = requests.post(url, json=data, headers=headers)
         return json.loads(result.text)
 
-    def music_get_billboard_attributes(self, date:str, attribute:str, song_name:str):
-        url = self.server + '/music/get_billboard_attributes'
-        headers={'accept': "application/json"}
-        data = {'date': date, 'attribute': attribute, 'song_name': song_name}
+    def music_get_billboard_attributes(self, date: str, attribute: str, song_name: str):
+        url = self.server + "/music/get_billboard_attributes"
+        headers = {"accept": "application/json"}
+        data = {"date": date, "attribute": attribute, "song_name": song_name}
         result = requests.post(url, json=data, headers=headers)
         return json.loads(result.text)
 
-    def music_grammy_get_best_artist_by_year(self, year:int):
-        url = self.server + '/music/grammy_get_best_artist_by_year'
-        headers={'accept': "application/json"}
-        data = {'query': year}
+    def music_grammy_get_best_artist_by_year(self, year: int):
+        url = self.server + "/music/grammy_get_best_artist_by_year"
+        headers = {"accept": "application/json"}
+        data = {"query": year}
         result = requests.post(url, json=data, headers=headers)
         return json.loads(result.text)
 
-    def music_grammy_get_award_count_by_artist(self, artist_name:str):
-        url = self.server + '/music/grammy_get_award_count_by_artist'
-        headers={'accept': "application/json"}
-        data = {'query': artist_name}
+    def music_grammy_get_award_count_by_artist(self, artist_name: str):
+        url = self.server + "/music/grammy_get_award_count_by_artist"
+        headers = {"accept": "application/json"}
+        data = {"query": artist_name}
         result = requests.post(url, json=data, headers=headers)
         return json.loads(result.text)
 
-    def music_grammy_get_award_count_by_song(self, song_name:str):
-        url = self.server + '/music/grammy_get_award_count_by_song'
-        headers={'accept': "application/json"}
-        data = {'query': song_name}
+    def music_grammy_get_award_count_by_song(self, song_name: str):
+        url = self.server + "/music/grammy_get_award_count_by_song"
+        headers = {"accept": "application/json"}
+        data = {"query": song_name}
         result = requests.post(url, json=data, headers=headers)
         return json.loads(result.text)
 
-    def music_grammy_get_best_song_by_year(self, year:int):
-        url = self.server + '/music/grammy_get_best_song_by_year'
-        headers={'accept': "application/json"}
-        data = {'query': year}
+    def music_grammy_get_best_song_by_year(self, year: int):
+        url = self.server + "/music/grammy_get_best_song_by_year"
+        headers = {"accept": "application/json"}
+        data = {"query": year}
         result = requests.post(url, json=data, headers=headers)
         return json.loads(result.text)
 
-    def music_grammy_get_award_date_by_artist(self, artist_name:str):
-        url = self.server + '/music/grammy_get_award_date_by_artist'
-        headers={'accept': "application/json"}
-        data = {'query': artist_name}
+    def music_grammy_get_award_date_by_artist(self, artist_name: str):
+        url = self.server + "/music/grammy_get_award_date_by_artist"
+        headers = {"accept": "application/json"}
+        data = {"query": artist_name}
         result = requests.post(url, json=data, headers=headers)
         return json.loads(result.text)
 
-    def music_grammy_get_best_album_by_year(self, year:int):
-        url = self.server + '/music/grammy_get_best_album_by_year'
-        headers={'accept': "application/json"}
-        data = {'query': year}
+    def music_grammy_get_best_album_by_year(self, year: int):
+        url = self.server + "/music/grammy_get_best_album_by_year"
+        headers = {"accept": "application/json"}
+        data = {"query": year}
         result = requests.post(url, json=data, headers=headers)
         return json.loads(result.text)
 
     def music_grammy_get_all_awarded_artists(self):
-        url = self.server + '/music/grammy_get_all_awarded_artists'
-        headers={'accept': "application/json"}
+        url = self.server + "/music/grammy_get_all_awarded_artists"
+        headers = {"accept": "application/json"}
         result = requests.post(url, headers=headers)
         return json.loads(result.text)
 
-    def music_get_artist_birth_place(self, artist_name:str):
-        url = self.server + '/music/get_artist_birth_place'
-        headers={'accept': "application/json"}
-        data = {'query': artist_name}
+    def music_get_artist_birth_place(self, artist_name: str):
+        url = self.server + "/music/get_artist_birth_place"
+        headers = {"accept": "application/json"}
+        data = {"query": artist_name}
         result = requests.post(url, json=data, headers=headers)
         return json.loads(result.text)
 
-    def music_get_artist_birth_date(self, artist_name:str):
-        url = self.server + '/music/get_artist_birth_date'
-        headers={'accept': "application/json"}
-        data = {'query': artist_name}
+    def music_get_artist_birth_date(self, artist_name: str):
+        url = self.server + "/music/get_artist_birth_date"
+        headers = {"accept": "application/json"}
+        data = {"query": artist_name}
         result = requests.post(url, json=data, headers=headers)
         return json.loads(result.text)
 
-    def music_get_members(self, band_name:str):
-        url = self.server + '/music/get_members'
-        headers={'accept': "application/json"}
-        data = {'query': band_name}
+    def music_get_members(self, band_name: str):
+        url = self.server + "/music/get_members"
+        headers = {"accept": "application/json"}
+        data = {"query": band_name}
         result = requests.post(url, json=data, headers=headers)
         return json.loads(result.text)
 
-    def music_get_lifespan(self, artist_name:str):
-        url = self.server + '/music/get_lifespan'
-        headers={'accept': "application/json"}
-        data = {'query': artist_name}
+    def music_get_lifespan(self, artist_name: str):
+        url = self.server + "/music/get_lifespan"
+        headers = {"accept": "application/json"}
+        data = {"query": artist_name}
         result = requests.post(url, json=data, headers=headers)
         return json.loads(result.text)
 
-    def music_get_song_author(self, song_name:str):
-        url = self.server + '/music/get_song_author'
-        headers={'accept': "application/json"}
-        data = {'query': song_name}
+    def music_get_song_author(self, song_name: str):
+        url = self.server + "/music/get_song_author"
+        headers = {"accept": "application/json"}
+        data = {"query": song_name}
         result = requests.post(url, json=data, headers=headers)
         return json.loads(result.text)
 
-    def music_get_song_release_country(self, song_name:str):
-        url = self.server + '/music/get_song_release_country'
-        headers={'accept': "application/json"}
-        data = {'query': song_name}
+    def music_get_song_release_country(self, song_name: str):
+        url = self.server + "/music/get_song_release_country"
+        headers = {"accept": "application/json"}
+        data = {"query": song_name}
         result = requests.post(url, json=data, headers=headers)
         return json.loads(result.text)
 
-    def music_get_song_release_date(self, song_name:str):
-        url = self.server + '/music/get_song_release_date'
-        headers={'accept': "application/json"}
-        data = {'query': song_name}
+    def music_get_song_release_date(self, song_name: str):
+        url = self.server + "/music/get_song_release_date"
+        headers = {"accept": "application/json"}
+        data = {"query": song_name}
         result = requests.post(url, json=data, headers=headers)
         return json.loads(result.text)
 
-    def music_get_artist_all_works(self, song_name:str):
-        url = self.server + '/music/get_artist_all_works'
-        headers={'accept': "application/json"}
-        data = {'query': song_name}
+    def music_get_artist_all_works(self, song_name: str):
+        url = self.server + "/music/get_artist_all_works"
+        headers = {"accept": "application/json"}
+        data = {"query": song_name}
         result = requests.post(url, json=data, headers=headers)
         return json.loads(result.text)
 
-    def sports_soccer_get_games_on_date(self, date:str, team_name:str=None):
-        url = self.server + '/sports/soccer/get_games_on_date'
-        headers={'accept': "application/json"}
-        data = {'team_name': team_name, 'date': date}
+    def sports_soccer_get_games_on_date(self, date: str, team_name: str = None):
+        url = self.server + "/sports/soccer/get_games_on_date"
+        headers = {"accept": "application/json"}
+        data = {"team_name": team_name, "date": date}
         result = requests.post(url, json=data, headers=headers)
         return json.loads(result.text)
 
-    def sports_nba_get_games_on_date(self, date:str, team_name:str=None):
-        url = self.server + '/sports/nba/get_games_on_date'
-        headers={'accept': "application/json"}
-        data = {'team_name': team_name, 'date': date}
+    def sports_nba_get_games_on_date(self, date: str, team_name: str = None):
+        url = self.server + "/sports/nba/get_games_on_date"
+        headers = {"accept": "application/json"}
+        data = {"team_name": team_name, "date": date}
         result = requests.post(url, json=data, headers=headers)
         return json.loads(result.text)
 
-    def sports_nba_get_play_by_play_data_by_game_ids(self, game_ids:List[str]):
-        url = self.server + '/sports/nba/get_play_by_play_data_by_game_ids'
-        headers={'accept': "application/json"}
-        data = {'game_ids': game_ids}
+    def sports_nba_get_play_by_play_data_by_game_ids(self, game_ids: List[str]):
+        url = self.server + "/sports/nba/get_play_by_play_data_by_game_ids"
+        headers = {"accept": "application/json"}
+        data = {"game_ids": game_ids}
         result = requests.post(url, json=data, headers=headers)
         return json.loads(result.text)
-
-    
\ No newline at end of file
diff --git a/HierarchicalAgenticRAG/tools/supervisor_agent_tools.yaml b/HierarchicalAgenticRAG/tools/supervisor_agent_tools.yaml
index 7983774fa0..58110e5292 100644
--- a/HierarchicalAgenticRAG/tools/supervisor_agent_tools.yaml
+++ b/HierarchicalAgenticRAG/tools/supervisor_agent_tools.yaml
@@ -1,3 +1,6 @@
+# Copyright (C) 2024 Intel Corporation
+# SPDX-License-Identifier: Apache-2.0
+
 search_knowledge_base:
   description: Search knowledge base for a given query. Returns text related to the query.
   callable_api: tools.py:search_knowledge_base
@@ -53,4 +56,4 @@ get_grammy_best_artist_by_year:
     year:
       type: int
       description: year
-  return_output: grammy_best_new_artist
\ No newline at end of file
+  return_output: grammy_best_new_artist
diff --git a/HierarchicalAgenticRAG/tools/tools.py b/HierarchicalAgenticRAG/tools/tools.py
index 5bd87f8e1d..94a44f6787 100644
--- a/HierarchicalAgenticRAG/tools/tools.py
+++ b/HierarchicalAgenticRAG/tools/tools.py
@@ -1,49 +1,52 @@
-import requests
+# Copyright (C) 2024 Intel Corporation
+# SPDX-License-Identifier: Apache-2.0
+
 import os
+
+import requests
 from tools.pycragapi import CRAG
 
+
 def search_knowledge_base(query: str) -> str:
-    '''Search the knowledge base for a specific query.'''
+    """Search the knowledge base for a specific query."""
     # use worker agent (DocGrader) to search the knowledge base
-    url = os.environ.get('WORKER_AGENT_URL')
+    url = os.environ.get("WORKER_AGENT_URL")
     print(url)
     proxies = {"http": ""}
     payload = {
-        "query":query,
-        } 
+        "query": query,
+    }
     response = requests.post(url, json=payload, proxies=proxies)
     return response.json()["text"]
-    
 
 
 def get_grammy_best_artist_by_year(year: int) -> dict:
-    '''Get the Grammy Best New Artist for a specific year.'''
+    """Get the Grammy Best New Artist for a specific year."""
     api = CRAG()
     year = int(year)
     return api.music_grammy_get_best_artist_by_year(year)
 
 
-
 def get_members(band_name: str) -> dict:
-    '''Get the member list of a band.'''
+    """Get the member list of a band."""
     api = CRAG()
     return api.music_get_members(band_name)
 
 
 def get_artist_birth_place(artist_name: str) -> dict:
-    '''Get the birthplace of an artist.'''
+    """Get the birthplace of an artist."""
     api = CRAG()
     return api.music_get_artist_birth_place(artist_name)
 
 
 def get_billboard_rank_date(rank: int, date: str = None) -> dict:
-    '''Get Billboard ranking for a specific rank and date.'''
+    """Get Billboard ranking for a specific rank and date."""
     api = CRAG()
     rank = int(rank)
     return api.music_get_billboard_rank_date(rank, date)
 
 
 def get_song_release_date(song_name: str) -> dict:
-    '''Get the release date of a song.'''
+    """Get the release date of a song."""
     api = CRAG()
     return api.music_get_song_release_date(song_name)
diff --git a/HierarchicalAgenticRAG/tools/worker_agent_tools.yaml b/HierarchicalAgenticRAG/tools/worker_agent_tools.yaml
index 7b472bca7d..905106ee35 100644
--- a/HierarchicalAgenticRAG/tools/worker_agent_tools.yaml
+++ b/HierarchicalAgenticRAG/tools/worker_agent_tools.yaml
@@ -1,2 +1,5 @@
+# Copyright (C) 2024 Intel Corporation
+# SPDX-License-Identifier: Apache-2.0
+
 duckduckgo_search:
-  callable_api: ddg-search
\ No newline at end of file
+  callable_api: ddg-search

From 764146f208612a17d9265729c5d4595df752d96c Mon Sep 17 00:00:00 2001
From: minmin-intel <minmin.hou@intel.com>
Date: Fri, 16 Aug 2024 12:37:59 -0700
Subject: [PATCH 06/39] change example name and update docker yaml

Signed-off-by: minmin-intel <minmin.hou@intel.com>
---
 {HierarchicalAgenticRAG => AgentQnA}/README.md      |  10 +++++-----
 .../assets/hierarchical_agentic_rag_arch.png        | Bin
 .../docker/openai/docker-compose-agent-openai.yaml  |   2 +-
 .../docker/openai/launch_agent_service_openai.sh    |   0
 .../tests/test_agentqna.sh                          |   6 +++---
 .../tools/pycragapi.py                              |   0
 .../tools/supervisor_agent_tools.yaml               |   0
 {HierarchicalAgenticRAG => AgentQnA}/tools/tools.py |   3 ++-
 .../tools/worker_agent_tools.yaml                   |   0
 9 files changed, 11 insertions(+), 10 deletions(-)
 rename {HierarchicalAgenticRAG => AgentQnA}/README.md (92%)
 rename {HierarchicalAgenticRAG => AgentQnA}/assets/hierarchical_agentic_rag_arch.png (100%)
 rename {HierarchicalAgenticRAG => AgentQnA}/docker/openai/docker-compose-agent-openai.yaml (98%)
 rename {HierarchicalAgenticRAG => AgentQnA}/docker/openai/launch_agent_service_openai.sh (100%)
 rename HierarchicalAgenticRAG/tests/test_hierarchicalagenticrag_on_openai.sh => AgentQnA/tests/test_agentqna.sh (93%)
 rename {HierarchicalAgenticRAG => AgentQnA}/tools/pycragapi.py (100%)
 rename {HierarchicalAgenticRAG => AgentQnA}/tools/supervisor_agent_tools.yaml (100%)
 rename {HierarchicalAgenticRAG => AgentQnA}/tools/tools.py (96%)
 rename {HierarchicalAgenticRAG => AgentQnA}/tools/worker_agent_tools.yaml (100%)

diff --git a/HierarchicalAgenticRAG/README.md b/AgentQnA/README.md
similarity index 92%
rename from HierarchicalAgenticRAG/README.md
rename to AgentQnA/README.md
index 4970d0b59b..89e6af415f 100644
--- a/HierarchicalAgenticRAG/README.md
+++ b/AgentQnA/README.md
@@ -1,10 +1,10 @@
-# Hierarchical Agentic RAG
+# Agents for Question Answering
 ## Overview
 This example showcases a hierarchical multi-agent system for question-answering applications. The architecture diagram is shown below. The supervisor agent interfaces with the user and dispatch tasks to the worker agent and other tools to gather information and come up with answers. The worker agent uses the retrieval tool to generate answers to the queries posted by the supervisor agent. Other tools used by the supervisor agent may include APIs to interface knowledge graphs, SQL databases, external knowledge bases, etc.
 ![Architecture Overview](assets/hierarchical_agentic_rag_arch.png)
-### Why Agentic RAG?
+### Why Agent for question answering?
 1. Improve relevancy of retrieved context.
-Agent can rephrase user queries, decompose user queries, and iterate to get the most relevant context for answering user's questions.
+Agent can rephrase user queries, decompose user queries, and iterate to get the most relevant context for answering user's questions. Compared to conventional RAG, RAG agent can significantly improve the correctness and relevancy of the answer.
 2. Use tools to get additional knowledge.
 For example, knowledge graphs and SQL databases can be exposed as APIs for Agents to gather knowledge that may be missing in the retrieval vector database.
 3. Hierarchical agent can further improve performance.
@@ -12,7 +12,7 @@ Expert worker agents, such as retrieval agent, knowledge graph agent, SQL agent,
 
 ### Roadmap
 * v0.9: Worker agent uses open-source websearch tool (duckduckgo), agents use OpenAI GPT-4o-mini as llm backend.
-* v1.0: Worker agent uses OPEA retrieval megaservice as tool, 
+* v1.0: Worker agent uses OPEA retrieval megaservice as tool. 
 * v1.0 or later: agents use open-source llm backend.
 * v1.1 or later: add safeguards
 
@@ -42,7 +42,7 @@ git clone https://github.com/opea-project/GenAIExamples.git
 ```
 Second, set up env vars
 ```
-export TOOLSET_PATH=$WORKDIR/GenAIExamples/HierarchicalAgenticRAG/tools/
+export TOOLSET_PATH=$WORKDIR/GenAIExamples/AgentQnA/tools/
 # optional: OPANAI_API_KEY
 export OPENAI_API_KEY=<your-openai-key>
 ```
diff --git a/HierarchicalAgenticRAG/assets/hierarchical_agentic_rag_arch.png b/AgentQnA/assets/hierarchical_agentic_rag_arch.png
similarity index 100%
rename from HierarchicalAgenticRAG/assets/hierarchical_agentic_rag_arch.png
rename to AgentQnA/assets/hierarchical_agentic_rag_arch.png
diff --git a/HierarchicalAgenticRAG/docker/openai/docker-compose-agent-openai.yaml b/AgentQnA/docker/openai/docker-compose-agent-openai.yaml
similarity index 98%
rename from HierarchicalAgenticRAG/docker/openai/docker-compose-agent-openai.yaml
rename to AgentQnA/docker/openai/docker-compose-agent-openai.yaml
index f22558dd4d..19096d75d9 100644
--- a/HierarchicalAgenticRAG/docker/openai/docker-compose-agent-openai.yaml
+++ b/AgentQnA/docker/openai/docker-compose-agent-openai.yaml
@@ -10,7 +10,7 @@ services:
     ipc: host
     environment:
       ip_address: ${ip_address}
-      strategy: docgrader
+      strategy: rag_agent
       recursion_limit: ${recursion_limit}
       llm_engine: openai
       OPENAI_API_KEY: ${OPENAI_API_KEY}
diff --git a/HierarchicalAgenticRAG/docker/openai/launch_agent_service_openai.sh b/AgentQnA/docker/openai/launch_agent_service_openai.sh
similarity index 100%
rename from HierarchicalAgenticRAG/docker/openai/launch_agent_service_openai.sh
rename to AgentQnA/docker/openai/launch_agent_service_openai.sh
diff --git a/HierarchicalAgenticRAG/tests/test_hierarchicalagenticrag_on_openai.sh b/AgentQnA/tests/test_agentqna.sh
similarity index 93%
rename from HierarchicalAgenticRAG/tests/test_hierarchicalagenticrag_on_openai.sh
rename to AgentQnA/tests/test_agentqna.sh
index befbc2ca77..1754e14180 100644
--- a/HierarchicalAgenticRAG/tests/test_hierarchicalagenticrag_on_openai.sh
+++ b/AgentQnA/tests/test_agentqna.sh
@@ -7,9 +7,10 @@ echo "IMAGE_REPO=${IMAGE_REPO}"
 echo "OPENAI_API_KEY=${OPENAI_API_KEY}"
 
 WORKPATH=$(dirname "$PWD")
-WORKDIR=$WORKPATH/../../
+export WORKDIR=$WORKPATH/../../
 echo "WORKDIR=${WORKDIR}"
 export ip_address=$(hostname -I | awk '{print $1}')
+export TOOLSET_PATH=$WORKDIR/GenAIExamples/AgentQnA/tools/
 
 function build_agent_docker_image() {
     cd $WORKDIR
@@ -30,8 +31,7 @@ function start_services() {
     echo "Starting CRAG server"
     docker run -d -p=8080:8000 docker.io/aicrowd/kdd-cup-24-crag-mock-api:v0
     echo "Starting Agent services"
-    export TOOLSET_PATH=$WORKDIR/GenAIExamples/HierarchicalAgenticRAG/tools/
-    cd $WORKDIR/GenAIExamples/HierarchicalAgenticRAG/docker/openai
+    cd $WORKDIR/GenAIExamples/AgentQnA/docker/openai
     bash launch_agent_service_openai.sh
 }
 
diff --git a/HierarchicalAgenticRAG/tools/pycragapi.py b/AgentQnA/tools/pycragapi.py
similarity index 100%
rename from HierarchicalAgenticRAG/tools/pycragapi.py
rename to AgentQnA/tools/pycragapi.py
diff --git a/HierarchicalAgenticRAG/tools/supervisor_agent_tools.yaml b/AgentQnA/tools/supervisor_agent_tools.yaml
similarity index 100%
rename from HierarchicalAgenticRAG/tools/supervisor_agent_tools.yaml
rename to AgentQnA/tools/supervisor_agent_tools.yaml
diff --git a/HierarchicalAgenticRAG/tools/tools.py b/AgentQnA/tools/tools.py
similarity index 96%
rename from HierarchicalAgenticRAG/tools/tools.py
rename to AgentQnA/tools/tools.py
index 5bd87f8e1d..06f5c36652 100644
--- a/HierarchicalAgenticRAG/tools/tools.py
+++ b/AgentQnA/tools/tools.py
@@ -12,7 +12,8 @@ def search_knowledge_base(query: str) -> str:
         "query":query,
         } 
     response = requests.post(url, json=payload, proxies=proxies)
-    return response.json()["text"]
+    answer = response.json()["text"]
+    return answer
     
 
 
diff --git a/HierarchicalAgenticRAG/tools/worker_agent_tools.yaml b/AgentQnA/tools/worker_agent_tools.yaml
similarity index 100%
rename from HierarchicalAgenticRAG/tools/worker_agent_tools.yaml
rename to AgentQnA/tools/worker_agent_tools.yaml

From 31745a5f90b50dce7ae2b3b7d9b16456d7523840 Mon Sep 17 00:00:00 2001
From: "pre-commit-ci[bot]"
 <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Date: Fri, 16 Aug 2024 19:44:19 +0000
Subject: [PATCH 07/39] [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci
---
 AgentQnA/README.md | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/AgentQnA/README.md b/AgentQnA/README.md
index c038ba71e2..98b8a8bd7a 100644
--- a/AgentQnA/README.md
+++ b/AgentQnA/README.md
@@ -1,22 +1,23 @@
 # Agents for Question Answering
+
 ## Overview
 
 This example showcases a hierarchical multi-agent system for question-answering applications. The architecture diagram is shown below. The supervisor agent interfaces with the user and dispatch tasks to the worker agent and other tools to gather information and come up with answers. The worker agent uses the retrieval tool to generate answers to the queries posted by the supervisor agent. Other tools used by the supervisor agent may include APIs to interface knowledge graphs, SQL databases, external knowledge bases, etc.
 ![Architecture Overview](assets/hierarchical_agentic_rag_arch.png)
 
 ### Why Agent for question answering?
+
 1. Improve relevancy of retrieved context.
-Agent can rephrase user queries, decompose user queries, and iterate to get the most relevant context for answering user's questions. Compared to conventional RAG, RAG agent can significantly improve the correctness and relevancy of the answer.
+   Agent can rephrase user queries, decompose user queries, and iterate to get the most relevant context for answering user's questions. Compared to conventional RAG, RAG agent can significantly improve the correctness and relevancy of the answer.
 2. Use tools to get additional knowledge.
    For example, knowledge graphs and SQL databases can be exposed as APIs for Agents to gather knowledge that may be missing in the retrieval vector database.
 3. Hierarchical agent can further improve performance.
    Expert worker agents, such as retrieval agent, knowledge graph agent, SQL agent, etc., can provide high-quality output for different aspects of a complex query, and the supervisor agent can aggregate the information together to provide a comprehensive answer.
 
-
-* v0.9: Worker agent uses open-source websearch tool (duckduckgo), agents use OpenAI GPT-4o-mini as llm backend.
-* v1.0: Worker agent uses OPEA retrieval megaservice as tool. 
-* v1.0 or later: agents use open-source llm backend.
-* v1.1 or later: add safeguards
+- v0.9: Worker agent uses open-source websearch tool (duckduckgo), agents use OpenAI GPT-4o-mini as llm backend.
+- v1.0: Worker agent uses OPEA retrieval megaservice as tool.
+- v1.0 or later: agents use open-source llm backend.
+- v1.1 or later: add safeguards
 
 ## Getting started
 

From e5496b3d81791466953874b299267e506abd888a Mon Sep 17 00:00:00 2001
From: minmin-intel <minmin.hou@intel.com>
Date: Mon, 19 Aug 2024 09:13:49 -0700
Subject: [PATCH 08/39] change diagram name and test script name

Signed-off-by: minmin-intel <minmin.hou@intel.com>
---
 AgentQnA/README.md                                  |   5 +++--
 ...ical_agentic_rag_arch.png => agent_qna_arch.png} | Bin
 .../{test_agentqna.sh => _test_agentqna_on_xeon.sh} |   0
 3 files changed, 3 insertions(+), 2 deletions(-)
 rename AgentQnA/assets/{hierarchical_agentic_rag_arch.png => agent_qna_arch.png} (100%)
 rename AgentQnA/tests/{test_agentqna.sh => _test_agentqna_on_xeon.sh} (100%)

diff --git a/AgentQnA/README.md b/AgentQnA/README.md
index 98b8a8bd7a..90da3c2f3b 100644
--- a/AgentQnA/README.md
+++ b/AgentQnA/README.md
@@ -3,7 +3,7 @@
 ## Overview
 
 This example showcases a hierarchical multi-agent system for question-answering applications. The architecture diagram is shown below. The supervisor agent interfaces with the user and dispatch tasks to the worker agent and other tools to gather information and come up with answers. The worker agent uses the retrieval tool to generate answers to the queries posted by the supervisor agent. Other tools used by the supervisor agent may include APIs to interface knowledge graphs, SQL databases, external knowledge bases, etc.
-![Architecture Overview](assets/hierarchical_agentic_rag_arch.png)
+![Architecture Overview](assets/agent_qna_arch.png)
 
 ### Why Agent for question answering?
 
@@ -14,6 +14,7 @@ This example showcases a hierarchical multi-agent system for question-answering
 3. Hierarchical agent can further improve performance.
    Expert worker agents, such as retrieval agent, knowledge graph agent, SQL agent, etc., can provide high-quality output for different aspects of a complex query, and the supervisor agent can aggregate the information together to provide a comprehensive answer.
 
+### Roadmap
 - v0.9: Worker agent uses open-source websearch tool (duckduckgo), agents use OpenAI GPT-4o-mini as llm backend.
 - v1.0: Worker agent uses OPEA retrieval megaservice as tool.
 - v1.0 or later: agents use open-source llm backend.
@@ -101,4 +102,4 @@ curl http://${ip_address}:9090/v1/chat/completions -X POST -H "Content-Type: app
 
 ## How to register your own tools with agent
 
-You can take a look at the tools yaml and python files in this example. For more details, please refer to the "Provide your own tools" section in the instructions [here](https://github.com/minmin-intel/GenAIComps/tree/agent-comp-dev/comps/agent/langchain#4-provide-your-own-tools).
+You can take a look at the tools yaml and python files in this example. For more details, please refer to the "Provide your own tools" section in the instructions [here](https://github.com/minmin-intel/GenAIComps/tree/agent-comp-dev/comps/agent/langchain#-4-provide-your-own-tools).
diff --git a/AgentQnA/assets/hierarchical_agentic_rag_arch.png b/AgentQnA/assets/agent_qna_arch.png
similarity index 100%
rename from AgentQnA/assets/hierarchical_agentic_rag_arch.png
rename to AgentQnA/assets/agent_qna_arch.png
diff --git a/AgentQnA/tests/test_agentqna.sh b/AgentQnA/tests/_test_agentqna_on_xeon.sh
similarity index 100%
rename from AgentQnA/tests/test_agentqna.sh
rename to AgentQnA/tests/_test_agentqna_on_xeon.sh

From 8e921d454737a552ac25cc38193d4683f1e82c97 Mon Sep 17 00:00:00 2001
From: "pre-commit-ci[bot]"
 <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Date: Mon, 19 Aug 2024 16:14:13 +0000
Subject: [PATCH 09/39] [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci
---
 AgentQnA/README.md | 1 +
 1 file changed, 1 insertion(+)

diff --git a/AgentQnA/README.md b/AgentQnA/README.md
index 90da3c2f3b..41eac2b0eb 100644
--- a/AgentQnA/README.md
+++ b/AgentQnA/README.md
@@ -15,6 +15,7 @@ This example showcases a hierarchical multi-agent system for question-answering
    Expert worker agents, such as retrieval agent, knowledge graph agent, SQL agent, etc., can provide high-quality output for different aspects of a complex query, and the supervisor agent can aggregate the information together to provide a comprehensive answer.
 
 ### Roadmap
+
 - v0.9: Worker agent uses open-source websearch tool (duckduckgo), agents use OpenAI GPT-4o-mini as llm backend.
 - v1.0: Worker agent uses OPEA retrieval megaservice as tool.
 - v1.0 or later: agents use open-source llm backend.

From f31d02d09faf504e33e961939155675d2baa019b Mon Sep 17 00:00:00 2001
From: minmin-intel <minmin.hou@intel.com>
Date: Mon, 19 Aug 2024 10:31:56 -0700
Subject: [PATCH 10/39] update test

---
 AgentQnA/tests/_test_agentqna_on_xeon.sh | 5 -----
 1 file changed, 5 deletions(-)

diff --git a/AgentQnA/tests/_test_agentqna_on_xeon.sh b/AgentQnA/tests/_test_agentqna_on_xeon.sh
index 119c738f4b..489a827b38 100644
--- a/AgentQnA/tests/_test_agentqna_on_xeon.sh
+++ b/AgentQnA/tests/_test_agentqna_on_xeon.sh
@@ -19,11 +19,6 @@ function build_agent_docker_image() {
     fi
     cd GenAIComps
     echo PWD: $(pwd)
-    local CUR=$(git branch --show-current)
-    echo "Check out agent component, Current Branch is ${CUR}"
-    if [ "${CUR}" != "PR480" ] ; then
-        git fetch origin pull/480/head:PR480; git checkout PR480
-    fi
     docker build -t opea/comps-agent-langchain:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/agent/langchain/docker/Dockerfile .
 }
 

From 9b024c8b53cd0e7ad19c061bc6c8477b0c347ac7 Mon Sep 17 00:00:00 2001
From: minmin-intel <minmin.hou@intel.com>
Date: Mon, 19 Aug 2024 16:29:14 -0700
Subject: [PATCH 11/39] add dataprep and retrieval tool

Signed-off-by: minmin-intel <minmin.hou@intel.com>
---
 .../openai/docker-compose-agent-openai.yaml   |   1 +
 .../openai/launch_agent_service_openai.sh     |   1 +
 AgentQnA/retrieval_tool/README.md             |  35 ++++
 .../docker/Dockerfile_retrievaltool           |  31 ++++
 .../retrieval_tool/docker/build_images.sh     |  25 +++
 .../docker/docker-compose-retrieval-tool.yaml | 154 ++++++++++++++++++
 .../docker/launch_retrieval_tool.sh           |  21 +++
 .../retrieval_tool/docker/retrieval_tool.py   |  60 +++++++
 AgentQnA/retrieval_tool/index_data.py         |  70 ++++++++
 AgentQnA/retrieval_tool/run_ingest_data.sh    |   4 +
 AgentQnA/tools/worker_agent_tools.py          |  23 +++
 AgentQnA/tools/worker_agent_tools.yaml        |  13 +-
 12 files changed, 436 insertions(+), 2 deletions(-)
 create mode 100644 AgentQnA/retrieval_tool/README.md
 create mode 100644 AgentQnA/retrieval_tool/docker/Dockerfile_retrievaltool
 create mode 100644 AgentQnA/retrieval_tool/docker/build_images.sh
 create mode 100644 AgentQnA/retrieval_tool/docker/docker-compose-retrieval-tool.yaml
 create mode 100644 AgentQnA/retrieval_tool/docker/launch_retrieval_tool.sh
 create mode 100644 AgentQnA/retrieval_tool/docker/retrieval_tool.py
 create mode 100644 AgentQnA/retrieval_tool/index_data.py
 create mode 100644 AgentQnA/retrieval_tool/run_ingest_data.sh
 create mode 100644 AgentQnA/tools/worker_agent_tools.py

diff --git a/AgentQnA/docker/openai/docker-compose-agent-openai.yaml b/AgentQnA/docker/openai/docker-compose-agent-openai.yaml
index 1dc46cd743..a595435a5e 100644
--- a/AgentQnA/docker/openai/docker-compose-agent-openai.yaml
+++ b/AgentQnA/docker/openai/docker-compose-agent-openai.yaml
@@ -30,6 +30,7 @@ services:
       LANGCHAIN_TRACING_V2: ${LANGCHAIN_TRACING_V2}
       LANGCHAIN_PROJECT: "opea-worker-agent-service"
       port: 9095
+      RETRIEVAL_TOOl_URL: ${RETRIEVAL_TOOl_URL}
 
   supervisor-react-agent:
     image: opea/comps-agent-langchain:latest
diff --git a/AgentQnA/docker/openai/launch_agent_service_openai.sh b/AgentQnA/docker/openai/launch_agent_service_openai.sh
index 7cc197ccc8..92136dd162 100644
--- a/AgentQnA/docker/openai/launch_agent_service_openai.sh
+++ b/AgentQnA/docker/openai/launch_agent_service_openai.sh
@@ -8,6 +8,7 @@ export temperature=0
 export max_new_tokens=512
 export OPENAI_API_KEY=${OPENAI_API_KEY}
 export WORKER_AGENT_URL="http://${ip_address}:9095/v1/chat/completions"
+export RETRIEVAL_TOOL_URL="http://${ip_address}:8889/v1/retrievaltool"
 export CRAG_SERVER=http://${ip_address}:8080
 
 docker compose -f docker-compose-agent-openai.yaml up -d
diff --git a/AgentQnA/retrieval_tool/README.md b/AgentQnA/retrieval_tool/README.md
new file mode 100644
index 0000000000..b25436d61e
--- /dev/null
+++ b/AgentQnA/retrieval_tool/README.md
@@ -0,0 +1,35 @@
+# Retrieval tool for agent
+The retrieval tool in this example is an OPEA megaservice that is comprised of a query embedder, a document retriever and a document reranker.
+
+## Follow the instructions here to launch microservices.
+1. Build images
+```
+cd docker
+build_images.sh
+```
+2. Launch services
+```
+bash launch_retrieval_tool.sh
+```
+
+## Index data into vector database
+In this example, we use an example jsonl file to ingest example documents into the vector database. For more ways to ingest data and the type of documents supported by OPEA dataprep microservices, please refer to the documentation in the opea-project/GenAIComps repo.
+1. create a conda env
+2. Run commands below
+```
+bash run_ingest_data.sh
+```
+
+## Validate services
+```
+export ip_address=$(hostname -I | awk '{print $1}')
+curl http://${ip_address}:8889/v1/retrievaltool -X POST -H "Content-Type: application/json" -d '{
+     "text": "Taylor Swift hometown"
+    }' 
+```
+
+## Consume retrieval tool
+The endpoint for the retrieval tool is
+```
+http://${ip_address}:8889/v1/retrievaltool
+``` 
diff --git a/AgentQnA/retrieval_tool/docker/Dockerfile_retrievaltool b/AgentQnA/retrieval_tool/docker/Dockerfile_retrievaltool
new file mode 100644
index 0000000000..f4c6627cda
--- /dev/null
+++ b/AgentQnA/retrieval_tool/docker/Dockerfile_retrievaltool
@@ -0,0 +1,31 @@
+# Copyright (C) 2024 Intel Corporation
+# SPDX-License-Identifier: Apache-2.0
+
+FROM python:3.11-slim
+
+RUN apt-get update -y && apt-get install -y --no-install-recommends --fix-missing \
+    libgl1-mesa-glx \
+    libjemalloc-dev \
+    vim \
+    git
+
+RUN useradd -m -s /bin/bash user && \
+    mkdir -p /home/user && \
+    chown -R user /home/user/
+
+RUN cd /home/user/ && \
+    git clone https://github.com/opea-project/GenAIComps.git
+
+RUN cd /home/user/GenAIComps && pip install --no-cache-dir --upgrade pip && \
+    pip install -r /home/user/GenAIComps/requirements.txt
+
+RUN mkdir -p /home/user/script
+COPY ./retrieval_tool.py /home/user/script/retrieval_tool.py
+
+ENV PYTHONPATH=$PYTHONPATH:/home/user/GenAIComps
+
+USER user
+
+WORKDIR /home/user/script
+
+ENTRYPOINT ["python", "retrieval_tool.py"]
\ No newline at end of file
diff --git a/AgentQnA/retrieval_tool/docker/build_images.sh b/AgentQnA/retrieval_tool/docker/build_images.sh
new file mode 100644
index 0000000000..d73c74f4fa
--- /dev/null
+++ b/AgentQnA/retrieval_tool/docker/build_images.sh
@@ -0,0 +1,25 @@
+cd ${WORKDIR}/GenAIComps/
+echo $PWD
+
+echo "==============Building dataprep image================="
+# cp ingest_data.py ${WORKDIR}/GenAIComps/comps/dataprep/redis/langchain/prepare_doc_redis.py
+docker build --no-cache -t opea/dataprep-redis:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/dataprep/redis/langchain/docker/Dockerfile .
+echo "==============Successfully built dataprep image================="
+
+echo "==============Building embedding-tei image================="
+docker build --no-cache -t opea/embedding-tei:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/embeddings/langchain/docker/Dockerfile .
+echo "==============Successfully built embedding-tei image================="
+
+echo "==============Building retriever-redis image================="
+docker build --no-cache -t opea/retriever-redis:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/retrievers/langchain/redis/docker/Dockerfile .
+echo "==============Successfully built retriever-redis image================="
+
+echo "==============Building reranking-tei image================="
+docker build --no-cache -t opea/reranking-tei:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/reranks/tei/docker/Dockerfile .
+echo "==============Successfully built reranking-tei image================="
+
+cd $WORKDIR/GenAIExamples/AgentQnA/retrieval_tool/docker/
+echo $PWD
+echo "==============Building retrieval-tool image================="
+docker build --no-cache -t opea/retrievaltool:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f Dockerfile_retrievaltool .
+echo "==============Successfully built embedding-tei image================="
\ No newline at end of file
diff --git a/AgentQnA/retrieval_tool/docker/docker-compose-retrieval-tool.yaml b/AgentQnA/retrieval_tool/docker/docker-compose-retrieval-tool.yaml
new file mode 100644
index 0000000000..15dd9d2426
--- /dev/null
+++ b/AgentQnA/retrieval_tool/docker/docker-compose-retrieval-tool.yaml
@@ -0,0 +1,154 @@
+
+# Copyright (C) 2024 Intel Corporation
+# SPDX-License-Identifier: Apache-2.0
+
+version: "3.8"
+
+services:
+  redis-vector-db:
+    image: redis/redis-stack:7.2.0-v9
+    container_name: redis-vector-db
+    ports:
+      - "6379:6379"
+      - "8001:8001"
+  tei-embedding-service:
+    image: ghcr.io/huggingface/text-embeddings-inference:cpu-1.2
+    container_name: tei-embedding-server
+    ports:
+      - "6006:80"
+    volumes:
+      - ${WORKDIR}/hf_cache:/data
+    shm_size: 1g
+    environment:
+      no_proxy: ${no_proxy}
+      http_proxy: ${http_proxy}
+      https_proxy: ${https_proxy}
+    command: --model-id ${EMBEDDING_MODEL_ID} --auto-truncate
+  embedding:
+    image: opea/embedding-tei:latest
+    container_name: embedding-tei-server
+    volumes:
+      - ${WORKDIR}/GenAIComps/comps/:/home/user/comps
+    depends_on:
+      - tei-embedding-service
+    ports:
+      - "6000:6000"
+    ipc: host
+    environment:
+      no_proxy: ${no_proxy}
+      http_proxy: ${http_proxy}
+      https_proxy: ${https_proxy}
+      TEI_EMBEDDING_ENDPOINT: ${TEI_EMBEDDING_ENDPOINT}
+      LANGCHAIN_API_KEY: ${LANGCHAIN_API_KEY}
+      LANGCHAIN_TRACING_V2: ${LANGCHAIN_TRACING_V2}
+      LANGCHAIN_PROJECT: "opea-embedding-service"
+    restart: unless-stopped
+  retriever:
+    image: opea/retriever-redis:latest
+    container_name: retriever-redis-server
+    volumes:
+      - ${WORKDIR}/GenAIComps/comps/:/home/user/comps
+    depends_on:
+      - redis-vector-db
+    ports:
+      - "7000:7000"
+    ipc: host
+    environment:
+      no_proxy: ${no_proxy}
+      http_proxy: ${http_proxy}
+      https_proxy: ${https_proxy}
+      REDIS_URL: ${REDIS_URL}
+      INDEX_NAME: ${INDEX_NAME}
+      TEI_EMBEDDING_ENDPOINT: ${TEI_EMBEDDING_ENDPOINT}
+      LANGCHAIN_API_KEY: ${LANGCHAIN_API_KEY}
+      LANGCHAIN_TRACING_V2: ${LANGCHAIN_TRACING_V2}
+      LANGCHAIN_PROJECT: "opea-retriever-service"
+    restart: unless-stopped
+  tei-reranking-service:
+    image: ghcr.io/huggingface/text-embeddings-inference:cpu-1.2
+    container_name: tei-reranking-server
+    ports:
+      - "8808:80"
+    volumes:
+      - ${WORKDIR}/hf_cache:/data
+    shm_size: 1g
+    environment:
+      no_proxy: ${no_proxy}
+      http_proxy: ${http_proxy}
+      https_proxy: ${https_proxy}
+      HUGGINGFACEHUB_API_TOKEN: ${HUGGINGFACEHUB_API_TOKEN}
+      HF_HUB_DISABLE_PROGRESS_BARS: 1
+      HF_HUB_ENABLE_HF_TRANSFER: 0
+    command: --model-id ${RERANK_MODEL_ID} --auto-truncate
+  reranking:
+    image: opea/reranking-tei:latest
+    container_name: reranking-tei-xeon-server
+    volumes:
+      - ${WORKDIR}/GenAIComps/comps/:/home/user/comps
+    depends_on:
+      - tei-reranking-service
+    ports:
+      - "8000:8000"
+    ipc: host
+    environment:
+      no_proxy: ${no_proxy}
+      http_proxy: ${http_proxy}
+      https_proxy: ${https_proxy}
+      TEI_RERANKING_ENDPOINT: ${TEI_RERANKING_ENDPOINT}
+      HUGGINGFACEHUB_API_TOKEN: ${HUGGINGFACEHUB_API_TOKEN}
+      HF_HUB_DISABLE_PROGRESS_BARS: 1
+      HF_HUB_ENABLE_HF_TRANSFER: 0
+      LANGCHAIN_API_KEY: ${LANGCHAIN_API_KEY}
+      LANGCHAIN_TRACING_V2: ${LANGCHAIN_TRACING_V2}
+      LANGCHAIN_PROJECT: "opea-reranking-service"
+    restart: unless-stopped
+  
+  dataprep-redis-service:
+    image: opea/dataprep-redis:latest
+    container_name: dataprep-redis-server
+    volumes:
+      - ${WORKDIR}/GenAIComps/comps/:/home/user/comps/
+    depends_on:
+      - redis-vector-db
+    ports:
+      - "6007:6007"
+      - "6008:6008"
+      - "6009:6009"
+    environment:
+      no_proxy: ${no_proxy}
+      http_proxy: ${http_proxy}
+      https_proxy: ${https_proxy}
+      REDIS_URL: ${REDIS_URL}
+      INDEX_NAME: ${INDEX_NAME}
+      TEI_ENDPOINT: ${TEI_EMBEDDING_ENDPOINT}
+  
+  retrievaltool-xeon-backend-server:
+    image: opea/retrievaltool:latest
+    container_name: retrievaltool-xeon-backend-server
+    volumes: 
+      - ${WORKDIR}/GenAIComps/comps/:/home/user/GenAIComps/comps/
+      - ${WORKDIR}/GenAIExamples/AgentQnA/retrieval_tool/docker/:/home/user/script/
+    depends_on:
+      - redis-vector-db
+      - tei-embedding-service
+      - embedding
+      - retriever
+      - tei-reranking-service
+      - reranking
+    ports:
+      - "8889:8889"
+    environment:
+      # - no_proxy=${no_proxy}
+      # - https_proxy=${https_proxy} # certain proxies does not work for gateway on 4016
+      # - http_proxy=${http_proxy}
+      - MEGA_SERVICE_HOST_IP=${MEGA_SERVICE_HOST_IP}
+      - EMBEDDING_SERVICE_HOST_IP=${EMBEDDING_SERVICE_HOST_IP}
+      - RETRIEVER_SERVICE_HOST_IP=${RETRIEVER_SERVICE_HOST_IP}
+      - RERANK_SERVICE_HOST_IP=${RERANK_SERVICE_HOST_IP}
+      # - LLM_SERVICE_HOST_IP=${LLM_SERVICE_HOST_IP}
+    ipc: host
+    restart: always
+
+networks:
+  default:
+    driver: bridge
\ No newline at end of file
diff --git a/AgentQnA/retrieval_tool/docker/launch_retrieval_tool.sh b/AgentQnA/retrieval_tool/docker/launch_retrieval_tool.sh
new file mode 100644
index 0000000000..299e12dc90
--- /dev/null
+++ b/AgentQnA/retrieval_tool/docker/launch_retrieval_tool.sh
@@ -0,0 +1,21 @@
+host_ip=$(hostname -I | awk '{print $1}')
+export WORKDIR=/localdisk/minminho
+export no_proxy=${no_proxy}
+export http_proxy=${http_proxy}
+export https_proxy=${https_proxy}
+export EMBEDDING_MODEL_ID="BAAI/bge-base-en-v1.5"
+export RERANK_MODEL_ID="BAAI/bge-reranker-base"
+export TEI_EMBEDDING_ENDPOINT="http://${host_ip}:6006"
+export TEI_RERANKING_ENDPOINT="http://${host_ip}:8808"
+export REDIS_URL="redis://${host_ip}:6379"
+export INDEX_NAME="rag-redis"
+export MEGA_SERVICE_HOST_IP=${host_ip}
+export EMBEDDING_SERVICE_HOST_IP=${host_ip}
+export RETRIEVER_SERVICE_HOST_IP=${host_ip}
+export RERANK_SERVICE_HOST_IP=${host_ip}
+export BACKEND_SERVICE_ENDPOINT="http://${host_ip}:8889/v1/retrievaltool"
+export DATAPREP_SERVICE_ENDPOINT="http://${host_ip}:6007/v1/dataprep"
+export DATAPREP_GET_FILE_ENDPOINT="http://${host_ip}:6008/v1/dataprep/get_file"
+export DATAPREP_DELETE_FILE_ENDPOINT="http://${host_ip}:6009/v1/dataprep/delete_file"
+
+docker compose -f docker-compose-retrieval-tool.yaml up -d
\ No newline at end of file
diff --git a/AgentQnA/retrieval_tool/docker/retrieval_tool.py b/AgentQnA/retrieval_tool/docker/retrieval_tool.py
new file mode 100644
index 0000000000..238303bd72
--- /dev/null
+++ b/AgentQnA/retrieval_tool/docker/retrieval_tool.py
@@ -0,0 +1,60 @@
+# Copyright (C) 2024 Intel Corporation
+# SPDX-License-Identifier: Apache-2.0
+
+import asyncio
+import os
+
+from comps import MicroService, RetrievalToolGateway, ServiceOrchestrator, ServiceType
+
+MEGA_SERVICE_HOST_IP = os.getenv("MEGA_SERVICE_HOST_IP", "0.0.0.0")
+MEGA_SERVICE_PORT = os.getenv("MEGA_SERVICE_PORT", 8889)
+EMBEDDING_SERVICE_HOST_IP = os.getenv("EMBEDDING_SERVICE_HOST_IP", "0.0.0.0")
+EMBEDDING_SERVICE_PORT = os.getenv("EMBEDDING_SERVICE_PORT", 6000)
+RETRIEVER_SERVICE_HOST_IP = os.getenv("RETRIEVER_SERVICE_HOST_IP", "0.0.0.0")
+RETRIEVER_SERVICE_PORT = os.getenv("RETRIEVER_SERVICE_PORT", 7000)
+RERANK_SERVICE_HOST_IP = os.getenv("RERANK_SERVICE_HOST_IP", "0.0.0.0")
+RERANK_SERVICE_PORT = os.getenv("RERANK_SERVICE_PORT", 8000)
+
+class RetrievalToolService:
+    def __init__(self, host="0.0.0.0", port=8000):
+        self.host = host
+        self.port = port
+        self.megaservice = ServiceOrchestrator()
+
+    def add_remote_service(self):
+        embedding = MicroService(
+            name="embedding",
+            host=EMBEDDING_SERVICE_HOST_IP,
+            port=EMBEDDING_SERVICE_PORT,
+            endpoint="/v1/embeddings",
+            use_remote_service=True,
+            service_type=ServiceType.EMBEDDING,
+        )
+        retriever = MicroService(
+            name="retriever",
+            host=RETRIEVER_SERVICE_HOST_IP,
+            port=RETRIEVER_SERVICE_PORT,
+            endpoint="/v1/retrieval",
+            use_remote_service=True,
+            service_type=ServiceType.RETRIEVER,
+        )
+        rerank = MicroService(
+            name="rerank",
+            host=RERANK_SERVICE_HOST_IP,
+            port=RERANK_SERVICE_PORT,
+            endpoint="/v1/reranking",
+            use_remote_service=True,
+            service_type=ServiceType.RERANK,
+        )
+        
+        self.megaservice.add(embedding).add(retriever).add(rerank)
+        self.megaservice.flow_to(embedding, retriever)
+        self.megaservice.flow_to(retriever, rerank)
+
+        # self.megaservice.add(embedding)
+        self.gateway = RetrievalToolGateway(megaservice=self.megaservice, host="0.0.0.0", port=self.port)
+
+
+if __name__ == "__main__":
+    chatqna = RetrievalToolService(host=MEGA_SERVICE_HOST_IP, port=MEGA_SERVICE_PORT)
+    chatqna.add_remote_service()
\ No newline at end of file
diff --git a/AgentQnA/retrieval_tool/index_data.py b/AgentQnA/retrieval_tool/index_data.py
new file mode 100644
index 0000000000..262d548890
--- /dev/null
+++ b/AgentQnA/retrieval_tool/index_data.py
@@ -0,0 +1,70 @@
+import requests
+import json
+import argparse
+import os
+import tqdm
+
+def get_args():
+    parser = argparse.ArgumentParser(description='Index data')
+    parser.add_argument('--host_ip', type=str, default='localhost', help='Host IP')
+    parser.add_argument('--port', type=int, default=6007, help='Port')
+    parser.add_argument('--filedir', type=str, default=None, help='file directory')
+    parser.add_argument('--filename', type=str, default=None, help='file name')
+    parser.add_argument("--chunk_size", type=int, default=10000, help="Chunk size")
+    parser.add_argument("--chunk_overlap", type=int, default=0, help="Chunk overlap")
+    args = parser.parse_args()
+    return args
+
+def split_jsonl_into_txts(jsonl_file):
+    docs = []
+    n = 0
+    with open(jsonl_file, 'r') as f:
+        for line in f:
+            data = json.loads(line)
+            docs.append(data["doc"])
+            n+=1
+            if n>2:
+                break
+    return docs
+
+def write_docs_to_disk(docs, output_folder):
+    output_files = []
+    for i, text in enumerate(docs):
+        output = os.path.join(output_folder, str(i) + '.txt')
+        output_files.append(output)
+        with open(output, 'w') as f:
+            f.write(text)
+    return output_files
+
+def delete_files(files):
+    for file in files:
+        os.remove(file)
+
+def main():
+    args = get_args()
+    print(args)
+
+    host_ip = args.host_ip
+    port = args.port
+    proxies = {"http": ""}
+    url = "http://{host_ip}:{port}/v1/dataprep".format(host_ip=host_ip, port=port)
+
+    # Split jsonl file into json files
+    files = split_jsonl_into_txts(os.path.join(args.filedir, args.filename))
+    file_list = write_docs_to_disk(files, args.filedir)
+
+    print(file_list)
+    
+    for file in tqdm.tqdm(file_list):
+        print("Indexing file: ", file)
+        files = [('files', (f, open(f, 'rb'))) for f in [file]]
+        payload = {"chunk_size": args.chunk_size, "chunk_overlap": args.chunk_overlap}
+        resp = requests.request('POST', url=url, headers={}, files=files, data=payload, proxies=proxies)
+        print(resp.text)
+
+    print("Removing temp files....")
+    delete_files(file_list)
+    print('ALL DONE!')
+
+if __name__ == '__main__':
+    main()
\ No newline at end of file
diff --git a/AgentQnA/retrieval_tool/run_ingest_data.sh b/AgentQnA/retrieval_tool/run_ingest_data.sh
new file mode 100644
index 0000000000..2d365f34e2
--- /dev/null
+++ b/AgentQnA/retrieval_tool/run_ingest_data.sh
@@ -0,0 +1,4 @@
+FILEDIR=${WORKDIR}/datasets/crag_docs/
+FILENAME=crag_docs_music.jsonl
+
+python index_data.py --filedir ${FILEDIR} --filename ${FILENAME}
\ No newline at end of file
diff --git a/AgentQnA/tools/worker_agent_tools.py b/AgentQnA/tools/worker_agent_tools.py
new file mode 100644
index 0000000000..07fb7e7edc
--- /dev/null
+++ b/AgentQnA/tools/worker_agent_tools.py
@@ -0,0 +1,23 @@
+import requests
+import os
+
+def search_knowledge_base(query: str) -> str:
+    """Search the knowledge base for a specific query."""
+    # use worker agent (DocGrader) to search the knowledge base
+    url = os.environ.get("RETRIEVAL_TOOL_URL")
+    print(url)
+    proxies = {"http": ""}
+    payload = {
+        "text": query,
+    }
+    response = requests.post(url, json=payload, proxies=proxies)
+    print(response)
+    docs = response.json()["documents"]
+    context = ""
+    for i, doc in enumerate(docs):
+        if i == 0:
+            context = doc
+        else:
+            context += "\n" + doc
+    print(context)
+    return context
\ No newline at end of file
diff --git a/AgentQnA/tools/worker_agent_tools.yaml b/AgentQnA/tools/worker_agent_tools.yaml
index 905106ee35..972f0a15a6 100644
--- a/AgentQnA/tools/worker_agent_tools.yaml
+++ b/AgentQnA/tools/worker_agent_tools.yaml
@@ -1,5 +1,14 @@
 # Copyright (C) 2024 Intel Corporation
 # SPDX-License-Identifier: Apache-2.0
 
-duckduckgo_search:
-  callable_api: ddg-search
+# duckduckgo_search:
+#   callable_api: ddg-search
+
+search_knowledge_base:
+  description: Search knowledge base for a given query. Returns text related to the query.
+  callable_api: worker_agent_tools.py:search_knowledge_base
+  args_schema:
+    query:
+      type: str
+      description: query
+  return_output: retrieved_data
\ No newline at end of file

From b59400dcb5bd5cdde62c825a8d12914a6c3d5212 Mon Sep 17 00:00:00 2001
From: minmin-intel <minmin.hou@intel.com>
Date: Wed, 21 Aug 2024 15:13:35 -0700
Subject: [PATCH 12/39] test rag agent with retrieval tool

---
 .../openai/docker-compose-agent-openai.yaml   |  9 +-
 .../openai/launch_agent_service_openai.sh     |  4 +-
 AgentQnA/retrieval_tool/index_data.py         |  6 +-
 AgentQnA/tests/run_test_agent_service.sh      |  5 +
 AgentQnA/tests/src/commons.py                 |  1 +
 AgentQnA/tests/src/test_agent_service.py      | 97 +++++++++++++++++++
 AgentQnA/tools/worker_agent_tools.py          |  1 -
 7 files changed, 114 insertions(+), 9 deletions(-)
 create mode 100644 AgentQnA/tests/run_test_agent_service.sh
 create mode 100644 AgentQnA/tests/src/commons.py
 create mode 100644 AgentQnA/tests/src/test_agent_service.py

diff --git a/AgentQnA/docker/openai/docker-compose-agent-openai.yaml b/AgentQnA/docker/openai/docker-compose-agent-openai.yaml
index a595435a5e..f88da8e794 100644
--- a/AgentQnA/docker/openai/docker-compose-agent-openai.yaml
+++ b/AgentQnA/docker/openai/docker-compose-agent-openai.yaml
@@ -14,7 +14,7 @@ services:
     environment:
       ip_address: ${ip_address}
       strategy: rag_agent
-      recursion_limit: ${recursion_limit}
+      recursion_limit: ${recursion_limit_worker}
       llm_engine: openai
       OPENAI_API_KEY: ${OPENAI_API_KEY}
       model: ${model}
@@ -23,6 +23,7 @@ services:
       streaming: false
       tools: /home/user/tools/worker_agent_tools.yaml
       require_human_feedback: false
+      RETRIEVAL_TOOL_URL: ${RETRIEVAL_TOOL_URL}
       no_proxy: ${no_proxy}
       http_proxy: ${http_proxy}
       https_proxy: ${https_proxy}
@@ -30,7 +31,7 @@ services:
       LANGCHAIN_TRACING_V2: ${LANGCHAIN_TRACING_V2}
       LANGCHAIN_PROJECT: "opea-worker-agent-service"
       port: 9095
-      RETRIEVAL_TOOl_URL: ${RETRIEVAL_TOOl_URL}
+      
 
   supervisor-react-agent:
     image: opea/comps-agent-langchain:latest
@@ -44,13 +45,13 @@ services:
     environment:
       ip_address: ${ip_address}
       strategy: react_langgraph
-      recursion_limit: ${recursion_limit}
+      recursion_limit: ${recursion_limit_supervisor}
       llm_engine: openai
       OPENAI_API_KEY: ${OPENAI_API_KEY}
       model: ${model}
       temperature: ${temperature}
       max_new_tokens: ${max_new_tokens}
-      streaming: ${streaming}
+      streaming: false
       tools: /home/user/tools/supervisor_agent_tools.yaml
       require_human_feedback: false
       no_proxy: ${no_proxy}
diff --git a/AgentQnA/docker/openai/launch_agent_service_openai.sh b/AgentQnA/docker/openai/launch_agent_service_openai.sh
index 92136dd162..e6dfbafb42 100644
--- a/AgentQnA/docker/openai/launch_agent_service_openai.sh
+++ b/AgentQnA/docker/openai/launch_agent_service_openai.sh
@@ -1,8 +1,10 @@
 # Copyright (C) 2024 Intel Corporation
 # SPDX-License-Identifier: Apache-2.0
 
+export TOOLSET_PATH=$WORKDIR/GenAIExamples/AgentQnA/tools/
 export ip_address=$(hostname -I | awk '{print $1}')
-export recursion_limit=12
+export recursion_limit_worker=12
+export recursion_limit_supervisor=10
 export model="gpt-4o-mini-2024-07-18"
 export temperature=0
 export max_new_tokens=512
diff --git a/AgentQnA/retrieval_tool/index_data.py b/AgentQnA/retrieval_tool/index_data.py
index 262d548890..3f9e843aaa 100644
--- a/AgentQnA/retrieval_tool/index_data.py
+++ b/AgentQnA/retrieval_tool/index_data.py
@@ -22,9 +22,9 @@ def split_jsonl_into_txts(jsonl_file):
         for line in f:
             data = json.loads(line)
             docs.append(data["doc"])
-            n+=1
-            if n>2:
-                break
+            # n+=1
+            # if n>2:
+            #     break
     return docs
 
 def write_docs_to_disk(docs, output_folder):
diff --git a/AgentQnA/tests/run_test_agent_service.sh b/AgentQnA/tests/run_test_agent_service.sh
new file mode 100644
index 0000000000..a291889e7c
--- /dev/null
+++ b/AgentQnA/tests/run_test_agent_service.sh
@@ -0,0 +1,5 @@
+QUERYFILE=$WORKDIR/datasets/crag_qas/crag_20_answerable_queries.csv
+OUTFILE=$WORKDIR/datasets/crag_results/validation_5outof20.jsonl
+PORT=9095
+
+python src/test_agent_service.py --query_file $QUERYFILE --output_file $OUTFILE --port $PORT #--quick_test
diff --git a/AgentQnA/tests/src/commons.py b/AgentQnA/tests/src/commons.py
new file mode 100644
index 0000000000..e1dc6adb36
--- /dev/null
+++ b/AgentQnA/tests/src/commons.py
@@ -0,0 +1 @@
+QUERY_SEPERATOR = "========THIS IS A NEW QUERY========"
\ No newline at end of file
diff --git a/AgentQnA/tests/src/test_agent_service.py b/AgentQnA/tests/src/test_agent_service.py
new file mode 100644
index 0000000000..2d12b9b620
--- /dev/null
+++ b/AgentQnA/tests/src/test_agent_service.py
@@ -0,0 +1,97 @@
+import requests
+import json
+import argparse
+import os
+import pandas as pd
+from commons import QUERY_SEPERATOR
+
+def get_test_data(args):
+    if args.query_file.endswith('.jsonl'):
+        df = pd.read_json(args.query_file, lines=True, convert_dates=False)
+    elif args.query_file.endswith('.csv'):
+        df = pd.read_csv(args.query_file)
+    return df
+
+def generate_answer(url, prompt):
+    proxies = {"http": ""}
+    payload = {
+        "query":prompt,
+        } 
+    response = requests.post(url, json=payload, proxies=proxies)
+    answer = response.json()["text"]
+    return answer
+
+def save_results(output_file, output_list):       
+    with open(output_file, "w") as f:
+        for output in output_list:
+            f.write(json.dumps(output))
+            f.write("\n")
+
+def save_as_csv(output):
+    df = pd.read_json(output, lines=True, convert_dates=False)
+    df.to_csv(output.replace(".jsonl", ".csv"), index=False)
+
+if __name__ == "__main__":
+    parser = argparse.ArgumentParser()
+    parser.add_argument("--host_ip", type=str, default="localhost", help="host ip of the retrieval tool")
+    parser.add_argument("--port", type=str, default="9095", help="port of the retrieval tool")
+    parser.add_argument("--query_file", type=str, default=None, help="query jsonl file")
+    parser.add_argument("--output_file", type=str, default="output.jsonl", help="output jsonl file")
+    parser.add_argument("--quick_test", action="store_true", help="run quick test")
+    args = parser.parse_args()
+    
+    host_ip = args.host_ip
+    port = args.port
+    endpoint = "{port}/v1/chat/completions".format(port = port)
+    url = "http://{host_ip}:{endpoint}".format(host_ip=host_ip, endpoint=endpoint)
+
+    if args.quick_test:
+        query= [
+                "Taylor Swift hometown",
+                # "how many songs has the band the beatles released that have been recorded at abbey road studios?",
+                # "what's the most recent album from the founder of ysl records?",
+                # "when did dolly parton's song, blown away, come out?"
+                # "what song topped the billboard chart on 2004-02-04?",
+                # "what grammy award did edgar barrera win this year?",
+                # "who has had more number one hits on the us billboard hot 100 chart, michael jackson or elvis presley?",
+            ]
+        query_time=[
+            "08/11/2024, 23:37:29 PT", 
+            # "03/21/2024, 23:37:29 PT",
+            # "03/21/2024, 23:37:29 PT",
+            # "03/21/2024, 23:37:29 PT",
+            ]
+        df = pd.DataFrame({"query": query, "query_time": query_time})
+    else:
+        df = get_test_data(args)
+        df = df.head() # for validation purpose
+
+    
+    output_list = []
+    n = 0
+    for _, row in df.iterrows():
+        q = row['query']
+        t = row['query_time']
+        prompt = "Question: {}\nThe question was asked at: {}".format(q, t)
+        print(QUERY_SEPERATOR)
+        print('******Query:\n',prompt)
+        print("******Agent is working on the query")
+        answer = generate_answer(url, prompt)
+        print('******Answer from agent:\n',answer)
+        print('='*50)
+        output_list.append(
+                {
+                    "query": q,
+                    "query_time": t,
+                    # "ref_answer": row["answer"],
+                    "answer": answer,
+                    # "question_type": row["question_type"],
+                    # "static_or_dynamic": row["static_or_dynamic"],
+                }
+            )
+        save_results(args.output_file, output_list)
+        # n += 1
+        # if n > 1:
+        #     break
+    save_results(args.output_file, output_list)
+    save_as_csv(args.output_file)
\ No newline at end of file
diff --git a/AgentQnA/tools/worker_agent_tools.py b/AgentQnA/tools/worker_agent_tools.py
index 07fb7e7edc..d599edf8e9 100644
--- a/AgentQnA/tools/worker_agent_tools.py
+++ b/AgentQnA/tools/worker_agent_tools.py
@@ -3,7 +3,6 @@
 
 def search_knowledge_base(query: str) -> str:
     """Search the knowledge base for a specific query."""
-    # use worker agent (DocGrader) to search the knowledge base
     url = os.environ.get("RETRIEVAL_TOOL_URL")
     print(url)
     proxies = {"http": ""}

From 0a799a6531cef1c8f1035634b092def5c05a46f6 Mon Sep 17 00:00:00 2001
From: minmin-intel <minmin.hou@intel.com>
Date: Wed, 21 Aug 2024 15:49:50 -0700
Subject: [PATCH 13/39] fix merge unsaved changes

---
 .../openai/docker-compose-agent-openai.yaml    | 18 ------------------
 .../openai/launch_agent_service_openai.sh      |  8 --------
 2 files changed, 26 deletions(-)

diff --git a/AgentQnA/docker/openai/docker-compose-agent-openai.yaml b/AgentQnA/docker/openai/docker-compose-agent-openai.yaml
index 14fde6a950..f88da8e794 100644
--- a/AgentQnA/docker/openai/docker-compose-agent-openai.yaml
+++ b/AgentQnA/docker/openai/docker-compose-agent-openai.yaml
@@ -14,11 +14,7 @@ services:
     environment:
       ip_address: ${ip_address}
       strategy: rag_agent
-<<<<<<< HEAD
       recursion_limit: ${recursion_limit_worker}
-=======
-      recursion_limit: ${recursion_limit}
->>>>>>> main
       llm_engine: openai
       OPENAI_API_KEY: ${OPENAI_API_KEY}
       model: ${model}
@@ -27,10 +23,7 @@ services:
       streaming: false
       tools: /home/user/tools/worker_agent_tools.yaml
       require_human_feedback: false
-<<<<<<< HEAD
       RETRIEVAL_TOOL_URL: ${RETRIEVAL_TOOL_URL}
-=======
->>>>>>> main
       no_proxy: ${no_proxy}
       http_proxy: ${http_proxy}
       https_proxy: ${https_proxy}
@@ -38,10 +31,7 @@ services:
       LANGCHAIN_TRACING_V2: ${LANGCHAIN_TRACING_V2}
       LANGCHAIN_PROJECT: "opea-worker-agent-service"
       port: 9095
-<<<<<<< HEAD
       
-=======
->>>>>>> main
 
   supervisor-react-agent:
     image: opea/comps-agent-langchain:latest
@@ -55,21 +45,13 @@ services:
     environment:
       ip_address: ${ip_address}
       strategy: react_langgraph
-<<<<<<< HEAD
       recursion_limit: ${recursion_limit_supervisor}
-=======
-      recursion_limit: ${recursion_limit}
->>>>>>> main
       llm_engine: openai
       OPENAI_API_KEY: ${OPENAI_API_KEY}
       model: ${model}
       temperature: ${temperature}
       max_new_tokens: ${max_new_tokens}
-<<<<<<< HEAD
       streaming: false
-=======
-      streaming: ${streaming}
->>>>>>> main
       tools: /home/user/tools/supervisor_agent_tools.yaml
       require_human_feedback: false
       no_proxy: ${no_proxy}
diff --git a/AgentQnA/docker/openai/launch_agent_service_openai.sh b/AgentQnA/docker/openai/launch_agent_service_openai.sh
index 68aa458371..e6dfbafb42 100644
--- a/AgentQnA/docker/openai/launch_agent_service_openai.sh
+++ b/AgentQnA/docker/openai/launch_agent_service_openai.sh
@@ -1,24 +1,16 @@
 # Copyright (C) 2024 Intel Corporation
 # SPDX-License-Identifier: Apache-2.0
 
-<<<<<<< HEAD
 export TOOLSET_PATH=$WORKDIR/GenAIExamples/AgentQnA/tools/
 export ip_address=$(hostname -I | awk '{print $1}')
 export recursion_limit_worker=12
 export recursion_limit_supervisor=10
-=======
-export ip_address=$(hostname -I | awk '{print $1}')
-export recursion_limit=12
->>>>>>> main
 export model="gpt-4o-mini-2024-07-18"
 export temperature=0
 export max_new_tokens=512
 export OPENAI_API_KEY=${OPENAI_API_KEY}
 export WORKER_AGENT_URL="http://${ip_address}:9095/v1/chat/completions"
-<<<<<<< HEAD
 export RETRIEVAL_TOOL_URL="http://${ip_address}:8889/v1/retrievaltool"
-=======
->>>>>>> main
 export CRAG_SERVER=http://${ip_address}:8080
 
 docker compose -f docker-compose-agent-openai.yaml up -d

From 90815ff607712ba920f3f6c040703792cc2cf253 Mon Sep 17 00:00:00 2001
From: minmin-intel <minmin.hou@intel.com>
Date: Thu, 22 Aug 2024 11:05:41 -0700
Subject: [PATCH 14/39] update test scripts

Signed-off-by: minmin-intel <minmin.hou@intel.com>
---
 AgentQnA/example_data/test_docs_music.jsonl   | 27 +++++++
 .../retrieval_tool/docker/build_images.sh     |  3 +-
 .../docker/launch_retrieval_tool.sh           |  2 +-
 AgentQnA/retrieval_tool/run_ingest_data.sh    |  4 +-
 AgentQnA/tests/1_build_images.sh              | 69 ++++++++++++++++
 AgentQnA/tests/2_start_retrieval_tool.sh      | 19 +++++
 .../3_ingest_data_and_validate_retrieval.sh   | 63 +++++++++++++++
 AgentQnA/tests/4_launch_and_validate_agent.sh | 60 ++++++++++++++
 AgentQnA/tests/_test_agentqna_on_xeon.sh      | 81 +++++++------------
 9 files changed, 270 insertions(+), 58 deletions(-)
 create mode 100644 AgentQnA/example_data/test_docs_music.jsonl
 create mode 100644 AgentQnA/tests/1_build_images.sh
 create mode 100644 AgentQnA/tests/2_start_retrieval_tool.sh
 create mode 100644 AgentQnA/tests/3_ingest_data_and_validate_retrieval.sh
 create mode 100644 AgentQnA/tests/4_launch_and_validate_agent.sh

diff --git a/AgentQnA/example_data/test_docs_music.jsonl b/AgentQnA/example_data/test_docs_music.jsonl
new file mode 100644
index 0000000000..b1de4b702f
--- /dev/null
+++ b/AgentQnA/example_data/test_docs_music.jsonl
@@ -0,0 +1,27 @@
+{"query": "who sang the hit song \"thriller\"?", "domain": "music", "doc": "Thriller (song) - Wikipedia\nJump to content\nMain menu\nMain menu\nmove to sidebar\nhide\nNavigation\nMain pageContentsCurrent eventsRandom articleAbout WikipediaContact usDonate\nContribute\nHelpLearn to editCommunity portalRecent changesUpload file\nSearch\nSearch\nCreate account\nLog in\nPersonal tools\nCreate account Log in\nPages for logged out editors learn more\nContributionsTalk\nContents\nmove to sidebar\nhide\n(Top)\n1Composition\n2Writing\n3Recording\n4Release\n5Music video\n6Chart performance\n7Critical reception\n8Personnel\n9Charts\nToggle Charts subsection\n9.1Weekly charts\n9.2Year-end charts\n10Certifications\n11See also\n12References\nToggle the table of contents\nThriller (song)\n33 languages\n\u0627\u0644\u0639\u0631\u0628\u064a\u0629Az\u0259rbaycancaDanskDeutsch\u0395\u03bb\u03bb\u03b7\u03bd\u03b9\u03ba\u03acEspa\u00f1ol\u0641\u0627\u0631\u0633\u06ccFran\u00e7aisGalego\ud55c\uad6d\uc5b4HrvatskiItaliano\u05e2\u05d1\u05e8\u05d9\u05ea\u10e5\u10d0\u10e0\u10d7\u10e3\u10da\u10d8KiswahiliMagyar\u0d2e\u0d32\u0d2f\u0d3e\u0d33\u0d02Nederlands\u65e5\u672c\u8a9eNorsk bokm\u00e5lPolskiPortugu\u00eas\u0420\u0443\u0441\u0441\u043a\u0438\u0439ShqipSimple English\u0421\u0440\u043f\u0441\u043a\u0438 / srpskiSuomiSvenska\u0ba4\u0bae\u0bbf\u0bb4\u0bcd\u0e44\u0e17\u0e22T\u00fcrk\u00e7e\u0423\u043a\u0440\u0430\u0457\u043d\u0441\u044c\u043a\u0430Ti\u1ebfng Vi\u1ec7t\nEdit links\nArticleTalk\nEnglish\nReadEditView history\nTools\nTools\nmove to sidebar\nhide\nActions\nReadEditView history\nGeneral\nWhat links hereRelated changesUpload fileSpecial pagesPermanent linkPage informationCite this pageGet shortened URLDownload QR codeWikidata item\nPrint/export\nDownload as PDFPrintable version\nFrom Wikipedia, the free encyclopedia\n1983 single by Michael Jackson\nFor other songs, see Thriller (disambiguation) \u00a7\u00a0Music.\n\"Thriller\"US 12-inch singleSingle by Michael Jacksonfrom the album\nThriller B-side\"Things I Do for You\"Released\nNovember\u00a01983\u00a0(1983-11) (UK)[1]\nJanuary\u00a023,\u00a01984\u00a0(1984-01-23) (US)[2]\nRecorded1982StudioWestlake (Los Angeles, California)Genre\nDisco\nfunk\nLength\n5:57 (album version)\n4:37 (special edit)\n4:05 (remixed short version)\n5:04 (\"Starlight\" version)\nLabelEpicSongwriter(s)Rod TempertonProducer(s)Quincy JonesMichael Jackson singles chronology\n\"Say Say Say\" (1983)\n\"Thriller\" (1983)\n\"Farewell My Summer Love\" (1984)\nMusic video\"Thriller\" on YouTube"}
+{"query": "who sang the hit song \"thriller\"?", "domain": "music", "doc": "Recorded1982StudioWestlake (Los Angeles, California)Genre\nDisco\nfunk\nLength\n5:57 (album version)\n4:37 (special edit)\n4:05 (remixed short version)\n5:04 (\"Starlight\" version)\nLabelEpicSongwriter(s)Rod TempertonProducer(s)Quincy JonesMichael Jackson singles chronology\n\"Say Say Say\" (1983)\n\"Thriller\" (1983)\n\"Farewell My Summer Love\" (1984)\nMusic video\"Thriller\" on YouTube\n\"Thriller\" is a song by the American singer Michael Jackson. It was released by Epic Records in November 1983 in the UK and on January 23, 1984, in the US, as the seventh and final single from his sixth studio album, Thriller.[3]\n\"Thriller\" is a funk song featuring a repeating synthesizer bassline and lyrics and sound effects evoking horror films. It ends with a spoken-word sequence performed by the horror actor Vincent Price. It was produced by Quincy Jones and written by Rod Temperton, who wanted to write a theatrical song to suit Jackson's love of film.\nJackson decided to release \"Thriller\" as a single after Thriller left the top of the Billboard 200 chart. The\n\"Thriller\" music video, directed by John Landis, has Jackson dancing with a horde of zombies. It has been named the greatest music video of all time by various publications and readers' polls, and doubled sales of Thriller, helping it become the best-selling album in history."}
+{"query": "who sang the hit song \"thriller\"?", "domain": "music", "doc": "Jackson decided to release \"Thriller\" as a single after Thriller left the top of the Billboard 200 chart. The\n\"Thriller\" music video, directed by John Landis, has Jackson dancing with a horde of zombies. It has been named the greatest music video of all time by various publications and readers' polls, and doubled sales of Thriller, helping it become the best-selling album in history.\nIt was the album's seventh top-ten single on the Billboard Hot 100, reaching number four. It reached number one in Belgium, France and Spain, and the top ten in many other countries. In the week of Jackson's death in 2009, it was Jackson's bestselling track in the US, with sales of 167,000 copies on the Billboard Hot Digital Tracks chart. It entered the Billboard Hot Digital Singles Chart at number two, and remained in the charts' top ten for three consecutive weeks. \"Thriller\" is certified Diamond by the Recording Industry Association of America. It appears on several of Jackson's greatest-hits albums and has been covered by numerous artists. The song has returned to the Billboard Hot 100 chart multiple times due to its popularity around Halloween.\nComposition[edit]\n\"Thriller\"\nJackson's song \"Thriller\", released as a single in 1984; Nelson George wrote that it uses cinematic sound effects, horror film motifs, and vocal trickery to convey a sense of danger.[4]\nProblems playing this file? See media help.\n\"Thriller\" is a disco-funk song[5] The introduction features sound effects such as a creaking door, thunder, feet walking on wooden planks, winds and howling wolves.[6]\nWriting[edit]\nHorror actor Vincent Price provided the spoken-word sequence at the end of \"Thriller\"."}
+{"query": "who sang the hit song \"thriller\"?", "domain": "music", "doc": "Problems playing this file? See media help.\n\"Thriller\" is a disco-funk song[5] The introduction features sound effects such as a creaking door, thunder, feet walking on wooden planks, winds and howling wolves.[6]\nWriting[edit]\nHorror actor Vincent Price provided the spoken-word sequence at the end of \"Thriller\".\n\"Thriller\" was written by the English songwriter Rod Temperton, who had previously written \"Rock with You\" and \"Off the Wall\" for Jackson's 1979 album Off the Wall.[7] Temperton wanted to write something theatrical to suit Jackson's love of film.[8] He improvised with bass and drum patterns until he developed the bassline that runs through the song, then wrote a chord progression that built to a climax.[8] He recalled: \"I wanted it to build and build \u2013 a bit like stretching an elastic band throughout the tune to heighten suspense.\"[8]\nTemperton's first version was titled \"Starlight\", with the chorus lyric: \"Give me some starlight / Starlight sun\".[9] The production team, led by Quincy Jones, felt the song should be the title track, but that \"Starlight\" was not a strong album title. Instead, they wanted something \"mysterious\" to match Jackson's \"evolving persona\".[8] Temperton considered several titles, including \"Midnight Man\", which Jones felt was \"going in the right direction\". Finally, he conceived \"Thriller\", but worried that it was \"a crap word to sing ... It sounded terrible! However, we got Michael to spit it into the microphone a few times and it worked.\"[8]\nWith the title decided, Temperton wrote lyrics within \"a couple of hours\".[8] He envisioned a spoken-word sequence for the ending, but did not know what form it should take. It was decided to have a famous voice from the horror genre perform it, and Jones' then-wife, Peggy Lipton, suggested her friend Vincent Price.[6] Temperton composed the words for Price's part in a taxi on the way to the studio on the day of recording.[6]\nRecording[edit]\nQuincy Jones produced \"Thriller\"."}
+{"query": "who sang the hit song \"thriller\"?", "domain": "music", "doc": "Recording[edit]\nQuincy Jones produced \"Thriller\".\nAlong with the rest of the album, \"Thriller\" was recorded over eight weeks in 1982.[10] It was recorded at Westlake Recording Studios on Santa Monica Boulevard in Los Angeles, California.[6] The engineer Bruce Swedien had Jackson record his vocals in different approaches, doubling takes and recording at different distances from the microphone. Some background vocals were recorded in the Westlake shower stall.[6]\nThe bassline was performed on an ARP 2600 synthesizer, and the verse pads were performed on a Roland Jupiter-8 layered with a Sequential Circuits Prophet 5 and a Yamaha CS-80.[11] The percussion was created with a LinnDrum drum machine modified with sound chips from two other drum machines: a snare hi-hat and congas from an LM-1 and a clap from a TR-808. \"Thriller\" also features Rhodes piano performed by Greg Phillinganes and guitar performed by David Williams.[12]\nTo record the wolf howls, Swedien set up tape recorders up around his Great Dane in a barn overnight, but the dog never howled. Instead, Jackson recorded the howls himself.[13] For the creaking doors, Swedien rented doors designed for sound effects from the Universal Studios Lot and recorded the hinges.[13] Price recorded his part in two takes; Jones, acknowledging that doing a voice-over for a song is difficult, praised Price and described his takes as \"fabulous\".[6]\nRelease[edit]\nThe album Thriller was released in November 1982 on Epic Records and spent months at the top of the Billboard 200.[14] \"Thriller\" was not initially planned for release as a single, as Epic saw it as a novelty song.[15] The Epic executive Walter Yetnikoff asked: \"Who wants a single about monsters?\"[14]"}
+{"query": "who sang the hit song \"thriller\"?", "domain": "music", "doc": "Release[edit]\nThe album Thriller was released in November 1982 on Epic Records and spent months at the top of the Billboard 200.[14] \"Thriller\" was not initially planned for release as a single, as Epic saw it as a novelty song.[15] The Epic executive Walter Yetnikoff asked: \"Who wants a single about monsters?\"[14]\nBy mid-1983, sales of the album had begun to decline. Jackson, who was \"obsessive\" about his sales figures,[14] urged Yetnikoff and another Epic executive, Larry Stessel, to help conceive a plan to return the album to the top of the charts. Jackson's manager Frank DiLeo suggested releasing \"Thriller\", backed by a new music video.[14][16] It was the final single from the album, released in January 1984.[15]\nAlternative versions of \"Thriller\", including the \"Starlight\" demo, were released on the anniversary reissue Thriller 40 (2022).[17]\nMusic video[edit]\nMain article: Michael Jackson's Thriller (music video)\nThe music video for \"Thriller\" references numerous horror films,[14] and stars Jackson performing a dance routine with a horde of the undead.[14] It was directed by the horror director John Landis and written by Landis and Jackson. Jackson contacted Landis after seeing his film An American Werewolf in London. The pair conceived a 13-minute short film with a budget much larger than previous music videos. Jackson's record company refused to finance it, believing Thriller had peaked, so a making-of documentary, Making Michael Jackson's Thriller, was produced to receive financing from television networks.[14]\nMichael Jackson's Thriller premiered on MTV on December 2, 1983.[18] It was launched to great anticipation and played regularly on MTV.[18]\nIt doubled sales of Thriller, and the documentary sold over a million copies, becoming the best-selling videotape at the time.[14] It is credited for transforming music videos into a serious art form, breaking down racial barriers in popular entertainment, and popularizing the making-of documentary format.[19]"}
+{"query": "who sang the hit song \"thriller\"?", "domain": "music", "doc": "It doubled sales of Thriller, and the documentary sold over a million copies, becoming the best-selling videotape at the time.[14] It is credited for transforming music videos into a serious art form, breaking down racial barriers in popular entertainment, and popularizing the making-of documentary format.[19]\nMany elements have had a lasting impact on popular culture, such as the zombie dance and Jackson's red jacket, designed by Landis' wife Deborah Nadoolman.[19] Fans worldwide re-enact its zombie dance and it remains popular on YouTube. The Library of Congress described it as \"the most famous music video of all time\". In 2009, it became the first music video inducted into the National Film Registry as \"culturally, historically or aesthetically\" significant.[14]\nChart performance[edit]\n\"Thriller\" entered the Billboard Hot 100 charts at number 20.[20] It reached number seven the following week,[21] number five the next, and peaked the next week at number four, where it stayed for two weeks.[22][23] It finished as the #78 single on Billboard's Hot 100 for the 1984.[24]\n\"Thriller\" charted at number 19 on the Hot R&B/Hip-Hop Songs Chart.[25] On March 10, 1984, it reached its peak at number 3.[26] \"Thriller\" debuted on the UK Singles Chart on November 19, 1983, at number 24, and the following week peaked at number ten; it appeared on the chart for 52 weeks.[27] Beginning on February 5, 1984, \"Thriller\" peaked on the French Singles Chart at number one and topped the chart for four consecutive weeks.[28] \"Thriller\" also topped the Belgian VRT Top 30 Chart for two weeks in January 1984.[29]"}
+{"query": "who sang the hit song \"thriller\"?", "domain": "music", "doc": "Following Jackson's death in 2009, his music surged in popularity.[30] In the week of his death, \"Thriller\" was Jackson's best-selling track in the US, with sales of 167,000 copies on the Billboard Hot Digital Singles Chart.[30] On July 11, 2009, \"Thriller\" charted on the Billboard Hot Digital Singles Chart at number two (its peak), and the song remained in the charts' top ten for three consecutive weeks.[31] In the United Kingdom, the song charted at number 23 the week of Jackson's death.[32] The following week, the song reached its peak at number 12 on the UK Single Chart.[27] On July 12, 2009, \"Thriller\" peaked at number two on the Italian Singles Chart[33] and was later certified gold by the Federation of the Italian Music Industry.[34] \"Thriller\" reached at number three on the Australian ARIA Chart and Swiss Singles Chart and topped the Spanish Singles Charts for one week.[35] The song also placed within the top ten on the German Singles Chart, Norwegian Singles Chart and Irish Singles Chart, at number nine, number seven and number eight respectively.[35] \"Thriller\" also landed at number 25 on the Danish Singles Chart.[36] In the third week of July \"Thriller\" peaked at number 11 in Finland.[37]\n\"Thriller\"\nhas returned to the Billboard Hot 100 chart multiple times due to its popularity around Halloween. It re-entered the Billboard Hot 100 in October 2013 at number 42,[38] number 31 in November 2018,[39] and number 19 in November 2021, its highest placement since 1984.[40] This gave Jackson at least one top-20 hit across seven consecutive decades from 1969 on the Billboard Hot 100.[40]"}
+{"query": "who sang the hit song \"thriller\"?", "domain": "music", "doc": "\"Thriller\"\nhas returned to the Billboard Hot 100 chart multiple times due to its popularity around Halloween. It re-entered the Billboard Hot 100 in October 2013 at number 42,[38] number 31 in November 2018,[39] and number 19 in November 2021, its highest placement since 1984.[40] This gave Jackson at least one top-20 hit across seven consecutive decades from 1969 on the Billboard Hot 100.[40]\n\"Thriller\" was certified platinum by the Recording Industry Association of America on December 4, 1989, for sales of over one million physical units in the US[41][42] As of August 2016, the song had sold 4,024,398 copies in the US.[43] The song was later certified Diamond by RIAA for sales over 10 million equivalent-units.[44][45] \"Thriller\" reached number one on three different Billboard charts the week of November 8, 2023, more than a decade after Jackson's death. Those charts included: R&B/Hip-Hop Streaming Songs, R&B Streaming Songs and R&B Digital Song Sales charts.[46]\nCritical reception[edit]\nAshley Lasimone, of AOL's Spinner.com, noted that it \"became a signature for Jackson\" and described \"the groove of its bassline, paired with Michael's killer vocals and sleek moves\" as having \"produced a frighteningly great single.\"[47] Jon Pareles of The New York Times noted that \"'Billie Jean', 'Beat It', 'Wanna Be Startin' Somethin' ' and \"the movie in the song 'Thriller'\", were the songs, unlike the \"fluff\" \"P.Y.T.\", that were \"the hits that made Thriller a world-beater; along with Mr. Jackson's stage and video presence, listeners must have identified with his willingness to admit terror.\"[48] Ann Powers of the Los Angeles Times described \"Thriller\" as \"adequately groovy\" with a \"funked-out beat\" and lyrics \"seemingly lifted from some little kid's 'scary storybook'\".[49][50]\nPersonnel[edit]\nWritten and composed by Rod Temperton\nProduced by Quincy Jones\nMichael Jackson: lead and background vocals, LinnDrum drum machine\nRod Temperton and Brian Banks: synthesizers"}
+{"query": "who sang the hit song \"thriller\"?", "domain": "music", "doc": "Personnel[edit]\nWritten and composed by Rod Temperton\nProduced by Quincy Jones\nMichael Jackson: lead and background vocals, LinnDrum drum machine\nRod Temperton and Brian Banks: synthesizers\nGreg Phillinganes: synthesizers, Rhodes piano\nAnthony Marinelli: synthesizer programming\nDavid Williams: guitar\nJerry Hey, Gary Grant: trumpets, flugelhorns\nLarry Williams: saxophone, flute\nBill Reichenbach: trombone\nVocal, rhythm and synthesizer arrangement by Rod Temperton\nHorn arrangement by Jerry Hey\nEffects by Bruce Cannon and Bruce Swedien\nFeaturing: Narration by Vincent Price (Not featured on original edited single version)\nCharts[edit]\nWeekly charts[edit]\nChart (1983\u20131985)\nPeakposition\nAustralia (Kent Music Report)[51]\n4\nBelgium (Ultratop 50 Flanders)[52]\n1\nCanadian RPM Top Singles[53]\n3\nFinland (Suomen virallinen singlelista)[54]\n7\nFinland Jukebox (Suomen virallinen singlelista)[54]\n3\nFrance (SNEP)[28]\n1\nIreland (IRMA)[55]\n4\nNetherlands (Dutch Top 40)[56]\n3\nNetherlands (Single Top 100)[57]\n4\nNew Zealand (Recorded Music NZ)[58]\n6\nPortugal (AFP)[59]\n1\nSouth Africa (Springbok)[60]\n26\nSpain (AFYVE)[61]\n1\nUK Singles (OCC)[27]\n10\nUS Cashbox[62]\n4\nUS Billboard Hot 100[63]\n4\nUS Billboard Hot Black Singles[64][26]\n3\nUS Billboard Adult Contemporary[65]\n24\nUS Billboard Album Rock Tracks[64][26]\n42\nUS Radio & Records CHR/Pop Airplay Chart[66]\n1\nWest Germany (Official German Charts)[67]\n9\nChart (2006)\nPeakposition\nFrance (SNEP)[68]\n35\nGermany (Media Control Charts)[35]\n9\nIreland (IRMA)[55]\n8\nItaly (FIMI)[69]\n5\nNetherlands (Single Top 100)[57]\n34\nSpain (PROMUSICAE)[35]\n1\nSwitzerland (Schweizer Hitparade)[35]\n3\nChart (2007)\nPeakposition\nSpain (PROMUSICAE)[70]\n20\nUK Singles (OCC)[27]\n57\nChart (2008)\nPeakposition\nAustria (\u00d63 Austria Top 40)[71]\n55\nNorway (VG-lista)[72]\n13\nSwitzerland (Schweizer Hitparade)[73]\n53\nUK Singles (OCC)[27]\n35\nChart (2009)\nPeakposition\nAustralia (ARIA)[74]\n3\nAustria (\u00d63 Austria Top 40)[71]\n5\nBelgium (Ultratop 50 Back Catalogue Singles Flanders)[75]\n3"}
+{"query": "who sang the hit song \"thriller\"?", "domain": "music", "doc": "3\nChart (2007)\nPeakposition\nSpain (PROMUSICAE)[70]\n20\nUK Singles (OCC)[27]\n57\nChart (2008)\nPeakposition\nAustria (\u00d63 Austria Top 40)[71]\n55\nNorway (VG-lista)[72]\n13\nSwitzerland (Schweizer Hitparade)[73]\n53\nUK Singles (OCC)[27]\n35\nChart (2009)\nPeakposition\nAustralia (ARIA)[74]\n3\nAustria (\u00d63 Austria Top 40)[71]\n5\nBelgium (Ultratop 50 Back Catalogue Singles Flanders)[75]\n3\nBelgium (Ultratop 30 Back Catalogue Singles Wallonia)[76]\n2\nDenmark (Tracklisten)[36]\n25\nEurope (European Hot 100 Singles)[77]\n16\nFinland (Suomen virallinen lista)[78]\n11\nFrance (SNEP)[79]\n3\nIreland (IRMA)[35]\n8\nItaly (FIMI)[69]\n2\nJapan Singles Top 100 (Oricon)[35]\n41\nNetherlands (Single Top 100)[57]\n9\nNew Zealand (RIANZ)[35]\n12\nNorway (VG-lista)[72]\n7\nSpain (PROMUSICAE)[70]\n1\nSweden (Sverigetopplistan)[80]\n10\nSwitzerland (Schweizer Hitparade)[73]\n3\nUK Singles (OCC)[27]\n12\nUS Digital Song Sales (Billboard)[81]\n2\nChart (2010)\nPeakposition\nSpain (PROMUSICAE)[70]\n12\nSwitzerland (Schweizer Hitparade)[73]\n68\nUK Singles (OCC)[27]\n68\nChart (2012)\nPeakposition\nFrance (SNEP)[68]\n143\nIreland (IRMA)[55]\n30\nUK Singles (OCC)[27]\n49\nChart (2013)\nPeakposition\nFrance (SNEP)[68]\n159\nUK Singles (OCC)[27]\n48\nUS Billboard Hot 100[82]\n42\nChart (2014)\nPeakposition\nFrance (SNEP)[68]\n152\nSpain (PROMUSICAE)[70]\n38\nUK Singles (OCC)[27]\n57\nUS Billboard Hot 100[83]\n35\nChart (2015)\nPeakposition\nFrance (SNEP)[68]\n145\nSpain (PROMUSICAE)[70]\n48\nUK Singles (OCC)[27]\n61\nUS Billboard Hot 100[84]\n45\nChart (2016)\nPeakposition\nFrance (SNEP)[68]\n164\nUK Singles (OCC)[27]\n62\nChart (2017)\nPeakposition\nFrance (SNEP)[68]\n46\nSpain (PROMUSICAE)[70]\n32\nUK Singles (OCC)[27]\n34\nChart (2018)\nPeakposition\nCanada (Canadian Hot 100)[85]\n25\nUK Singles (OCC)[27]\n63\nUS Billboard Hot 100[86][87]\n31\nChart (2019)\nPeakposition\nUS Billboard Hot 100[88]\n44\nChart (2020)\nPeakposition\nGlobal 200[89]\n51\nUK Singles (OCC)[27]\n57\nUS Billboard Hot 100[90]\n48\nChart (2021)\nPeakposition\nCanada (Canadian Hot 100)[91]\n16\nGlobal 200 (Billboard)[92]\n28\nUK Singles (OCC)[93]\n40"}
+{"query": "who sang the hit song \"thriller\"?", "domain": "music", "doc": "34\nChart (2018)\nPeakposition\nCanada (Canadian Hot 100)[85]\n25\nUK Singles (OCC)[27]\n63\nUS Billboard Hot 100[86][87]\n31\nChart (2019)\nPeakposition\nUS Billboard Hot 100[88]\n44\nChart (2020)\nPeakposition\nGlobal 200[89]\n51\nUK Singles (OCC)[27]\n57\nUS Billboard Hot 100[90]\n48\nChart (2021)\nPeakposition\nCanada (Canadian Hot 100)[91]\n16\nGlobal 200 (Billboard)[92]\n28\nUK Singles (OCC)[93]\n40\nUK Hip Hop/R&B (OCC)[94]\n3\nUS Billboard Hot 100[95][96]\n19\nUS Billboard Digital Songs Sales[97]\n9\nChart (2022)\nPeakposition\nCanada (Canadian Hot 100)[98]\n25\nGlobal 200[99]\n37\nUK Singles (OCC)[27]\n41\nUS Billboard Hot 100[100]\n26\nChart (2023)\nPeakposition\nCanada (Canadian Hot 100)[101]\n22\nGlobal 200[102]\n39\nUK Singles (OCC)[103]\n20\nUS Billboard Hot 100[104]\n21\nYear-end charts[edit]\nChart (1984)\nPosition\nAustralia (Kent Music Report)[105]\n17\nBelgium (Ultratop Flanders)[106]\n26\nUS Billboard Hot 100[24]\n78\nChart (2009)\nPosition\nSweden (Sverigetopplistan)[107]\n88\nSwitzerland (Schweizer Hitparade)[108]\n81\nUK Singles (Official Charts Company)[109]\n143\nCertifications[edit]\nRegion\nCertification\nCertified units/sales\nAustralia (ARIA)[110]\n6\u00d7 Platinum\n420,000\u2021\nDenmark (IFPI Danmark)[111]\nPlatinum\n90,000\u2021\nFrance (SNEP)[112]\nPlatinum\n1,000,000*\nGermany (BVMI)[113]\nGold\n250,000\u2021\nItaly (FIMI)[114]\nPlatinum\n30,000\u2021\nJapan (RIAJ)[115] Full-length ringtone\nPlatinum\n250,000*\nMexico (AMPROFON)[116]\n4\u00d7 Platinum+Gold\n270,000\u2021\nSpain (PROMUSICAE)[117]\n2\u00d7 Platinum\n100,000*\nUnited Kingdom (BPI)[118] Digital sales since 2004\n2\u00d7 Platinum\n1,200,000\u2021\nUnited Kingdom (BPI)[119] other release\nGold\n500,000\u2021\nUnited States (RIAA)[120]\nDiamond\n10,000,000\u2021\nUnited States (RIAA)[121] Mastertone\nGold\n500,000*\n* Sales figures based on certification alone.\u2021 Sales+streaming figures based on certification alone.\nSee also[edit]\nList of best-selling singles\nList of best-selling singles in the United States\nList of most expensive music videos\nMichael Jackson's Thriller\nThriller (viral video)\nThrill the World\nReferences[edit]"}
+{"query": "who sang the hit song \"thriller\"?", "domain": "music", "doc": "Diamond\n10,000,000\u2021\nUnited States (RIAA)[121] Mastertone\nGold\n500,000*\n* Sales figures based on certification alone.\u2021 Sales+streaming figures based on certification alone.\nSee also[edit]\nList of best-selling singles\nList of best-selling singles in the United States\nList of most expensive music videos\nMichael Jackson's Thriller\nThriller (viral video)\nThrill the World\nReferences[edit]\n^ \"New Singles (for the week ending November 11, 1983)\" (PDF). Music Week: 30. November 5, 1983.\n^ Semigran, Aly (February 7, 2011). \"Michael Jackson's 'Thriller': Story Behind the 'Glee' Cover\". MTV. Retrieved September 17, 2023.\n^ McPhate, Tim (November 2, 2017). \"Michael Jackson's \"Thriller\": For The Record\". The Recording Academy. Retrieved November 17, 2019.\n^ George 2004, p.\u00a023.\n^ Jones, Jel D. Lewis (2005). Michael Jackson, the King of Pop: The Big Picture \u2013 The Music! The Man! The Legend! The Interviews: An Anthology. Amber Books Publishing. p.\u00a06. ISBN\u00a00-9749779-0-X. Retrieved July 22, 2010.\n^ a b c d e f Lyle, Peter (November 25, 2007). \"Michael Jackson's monster smash\". The Daily Telegraph. Archived from the original on January 12, 2022. Retrieved January 24, 2010.\n^ Kreps, Daniel (October 5, 2016). \"Rod Temperton, 'Thriller' songwriter, dead at 66\". Rolling Stone. Retrieved July 25, 2022.\n^ a b c d e f \"Revealed: the story behind Jacko's Thriller\". M magazine. October 31, 2012. Archived from the original on November 3, 2012. Retrieved October 24, 2018.\n^ Glazer, Eliot (September 25, 2009). \"Top 1984 Songs\". AOLRadioBlog.com. AOL Inc. Retrieved January 24, 2010.\n^ Vozick-Levinson, Simon (February 18, 2008). \"Quincy Jones' 'Thriller' Memories\". EW.com. Retrieved January 24, 2010.\n^ Carr, Dan (November 30, 2022). \"The synth sounds of Michael Jackson's Thriller (and how to recreate them in your DAW)\". MusicRadar. Retrieved March 19, 2023."}
+{"query": "who sang the hit song \"thriller\"?", "domain": "music", "doc": "^ Glazer, Eliot (September 25, 2009). \"Top 1984 Songs\". AOLRadioBlog.com. AOL Inc. Retrieved January 24, 2010.\n^ Vozick-Levinson, Simon (February 18, 2008). \"Quincy Jones' 'Thriller' Memories\". EW.com. Retrieved January 24, 2010.\n^ Carr, Dan (November 30, 2022). \"The synth sounds of Michael Jackson's Thriller (and how to recreate them in your DAW)\". MusicRadar. Retrieved March 19, 2023.\n^ Rogerson, Ben (February 10, 2023). \"Watch Greg Phillinganes recreate Michael Jackson's Thriller using the original synths\". MusicRadar. Retrieved March 27, 2023.\n^ a b \"The making of Michael Jackson's Thriller\". MusicRadar. Retrieved October 25, 2018.\n^ a b c d e f g h i Griffin, Nancy (July 2010). \"The \"Thriller\" Diaries\". Vanity Fair. Retrieved January 2, 2011.\n^ a b Romano, Aja (October 31, 2018). \"Michael Jackson's \"Thriller\" is the eternal Halloween bop \u2014 and so much more\". Vox. Retrieved October 25, 2021.\n^ Eagan, Daniel (November 24, 2011). America's Film Legacy, 2009\u20132010: A Viewer's Guide to the 50 Landmark Movies Added To The National Film Registry in 2009\u201310. Bloomsbury Publishing. p.\u00a0175. ISBN\u00a0978-1-4411-9328-5. Retrieved May 14, 2016.\n^ Miles Marshall Lewis (November 30, 2022). \"#Thriller40: Cultural Critics Celebrate Michael Jackson's Impact\". BET.\n^ a b Richin, Leslie (December 2, 2014). \"On This Day In 1983, Michael Jackson's 'Thriller' Premiered On MTV\". Billboard.\n^ a b Hebblethwaite, Phil (November 21, 2013). \"How Michael Jackson's Thriller changed music videos for ever\". The Guardian. Retrieved October 29, 2018.\n^ \"Week of February 11, 1984\". Billboard. Nielsen Business Media, Inc. Retrieved October 10, 2015.\n^ \"Week of February 18, 1984\". Billboard. Nielsen Business Media, Inc. January 2, 2013. Retrieved October 10, 2015.\n^ \"Week of March 3, 1984\". Billboard. Nielsen Business Media, Inc. January 2, 2013. Retrieved October 10, 2015.\n^ \"Week of March 10, 1984\". Billboard. Nielsen Business Media, Inc. Retrieved October 10, 2015."}
+{"query": "who sang the hit song \"thriller\"?", "domain": "music", "doc": "^ \"Week of February 18, 1984\". Billboard. Nielsen Business Media, Inc. January 2, 2013. Retrieved October 10, 2015.\n^ \"Week of March 3, 1984\". Billboard. Nielsen Business Media, Inc. January 2, 2013. Retrieved October 10, 2015.\n^ \"Week of March 10, 1984\". Billboard. Nielsen Business Media, Inc. Retrieved October 10, 2015.\n^ a b \"Billboard Top 100 \u2013 1984\". billboard. Retrieved March 29, 2020.\n^ \"Week of March 3, 1984\". Billboard. Nielsen Business Media, Inc. Archived from the original on January 21, 2010. Retrieved January 23, 2010.\n^ a b c \"Week of March 10, 1984\". Billboard. Nielsen Business Media, Inc. Retrieved January 23, 2010.\n^ a b c d e f g h i j k l m n o p \"Michael Jackson\". Official Charts Company. Retrieved October 10, 2015.\n^ a b \"Toutes les Chansons N\u00b0 1 des Ann\u00e9es 80\". Infodisc.fr. Dominic Durand / InfoDisc. Archived from the original on November 20, 2012. Retrieved January 23, 2010.\n^ \"Michael Jackson \u2013 Thriller\". Top30-3.radio2.be (in Dutch). VRT \u2013 Auguste Reyerslaan. Archived from the original on February 22, 2012. Retrieved January 24, 2010.\n^ a b Ed Christman, Antony Bruno (July 2, 2009). \"Michael Jackson Music Sales Surge Could Last For Months\". Billboard. Nielsen Business Media, Inc. Retrieved January 23, 2010.\n^ \"July 11, 2009\". Billboard. Nielsen Business Media. Retrieved January 23, 2010.\n^ \"Chart For Week Up To 04/07/2009\". Official Charts Company. Retrieved January 23, 2010.\n^ \"Thriller in Italian Chart\". Hung Medien. Retrieved June 21, 2013.\n^ \"Certificazioni Download FIMI\" (PDF) (in Italian). Federation of the Italian Music Industry. Archived from the original (PDF) on June 5, 2012. Retrieved January 2, 2012.\n^ a b c d e f g h \"Michael Jackson \u2013 Thriller \u2013 Music Charts\". Acharts.us. Retrieved January 23, 2010.\n^ a b \"Track Top 40 \u2013 July 10, 2009\". Hitlisterne.dk. IFPI Danmark & Nielsen Music Control. Archived from the original on September 30, 2011. Retrieved January 23, 2010."}
+{"query": "who sang the hit song \"thriller\"?", "domain": "music", "doc": "^ a b c d e f g h \"Michael Jackson \u2013 Thriller \u2013 Music Charts\". Acharts.us. Retrieved January 23, 2010.\n^ a b \"Track Top 40 \u2013 July 10, 2009\". Hitlisterne.dk. IFPI Danmark & Nielsen Music Control. Archived from the original on September 30, 2011. Retrieved January 23, 2010.\n^ \"Thriller in Finnish Chart\". Hung Medien. Retrieved January 23, 2010.\n^ \"Eminem Debuts at No. 1 on Hot R&B/Hip-Hop Songs Chart; Michael Jackson's 'Thriller' Returns\". Billboard. November 8, 2013. Retrieved October 2, 2016.\n^ \"Top 100 Songs | Billboard Hot 100 Chart\". Billboard. Retrieved November 11, 2018.\n^ a b \"Michael Jackson's 'Thriller' Leads Halloween Treats on Billboard Hot 100\". Billboard. Retrieved November 9, 2021.\n^ \"American\nsingle\ncertifications \u2013 Michael Jackson \u2013 Thriller\". Recording Industry Association of America.\n^ \"Rock Music, etc., Terms\". Georgetown College. October 26, 1999. Archived from the original on May 18, 2011. Retrieved January 8, 2010.\n^ \"Hip Hop Single Sales: The Weeknd, Zay Hilfigerrr & Drake\". Hip Hop DX. November 13, 2016. Retrieved November 14, 2016.\n^ \"Michael Jackson's Catalogue Garners Major New Gold & Platinum Awards\". RIAA. August 23, 2018. Retrieved December 21, 2018.\n^ Appel, Rich (October 30, 2014). \"Revisionist History, Part 3: Michael Jackson Gets Revenge on Prince! Year-End Hits of the Past, Re-Analyzed\". Billboard. Prometheus Global Media. Retrieved October 30, 2014.\n^ \"Michael Jackson Scores Three No. 1 Hits On The Billboard Charts This Week\". Forbes. Retrieved November 10, 2023.\n^ Lasimone, Ashley (October 28, 2009). \"Clash of the Cover Songs: Michael Jackson vs. Imogen Heap\". Spinner.com. AOL Inc. Retrieved January 23, 2010.\n^ Pareles, Jon (September 3, 1987). \"Critic's Notebook; How Good Is Jackson's 'Bad'?\". The New York Times. Retrieved January 25, 2010.\n^ Powers, Ann (February 15, 2008). \"Nine reasons why Jackson masterpiece remains a 'Thriller'\". SouthCoastToday.com. Dow Jones Local Media Group. Retrieved February 6, 2010."}
+{"query": "who sang the hit song \"thriller\"?", "domain": "music", "doc": "^ Pareles, Jon (September 3, 1987). \"Critic's Notebook; How Good Is Jackson's 'Bad'?\". The New York Times. Retrieved January 25, 2010.\n^ Powers, Ann (February 15, 2008). \"Nine reasons why Jackson masterpiece remains a 'Thriller'\". SouthCoastToday.com. Dow Jones Local Media Group. Retrieved February 6, 2010.\n^ Comstock, Miriam Marcus and Courtney. \"Thriller Chiller For Jackson\". Forbes. Retrieved November 4, 2019.\n^ Kent, David (2003). Australian Chart Book 1970\u20131992. Australian Chart Book. ISBN\u00a00-646-11917-6.\n^ \"Michael Jackson \u2013 Thriller\" (in Dutch). Ultratop 50.\nRetrieved December 14, 2021.\n^ \"Top Singles \u2013 Volume 40, No. 1, March 10, 1984\". RPM. Archived from the original on October 17, 2012. Retrieved August 3, 2010.\n^ a b Pennanen, Timo (2021). \"Michael Jackson\". Sis\u00e4lt\u00e4\u00e4 hitin - 2. laitos Levyt ja esitt\u00e4j\u00e4t Suomen musiikkilistoilla 1.1.1960\u201330.6.2021 (PDF). Helsinki: Kustannusosakeyhti\u00f6 Otava. p.\u00a0113. Retrieved May 29, 2022.\n^ a b c \"Search Results: Thriller\". IrishCharts.ie. Irish Recorded Music Association. Retrieved January 25, 2010.\n^\n\"Nederlandse Top 40 \u2013 week 2, 1984\" (in Dutch). Dutch Top 40.\n^ a b c \"Michael Jackson \u2013 Thriller\" (in Dutch). Single Top 100.\n^ \"Michael Jackson \u2013 Thriller\". Top 40 Singles.\n^ \"Top 3 in Europe\" (PDF). Music & Media. May 14, 1984. p.\u00a012. Retrieved October 29, 2021.\n^ \"SA Charts 1965\u2013March 1989\". Retrieved September 5, 2018.\n^ Salaverri, Fernando (September 2005). S\u00f3lo \u00e9xitos: a\u00f1o a a\u00f1o, 1959\u20132002 (in Spanish) (1st\u00a0ed.). Spain: Fundaci\u00f3n Autor-SGAE. ISBN\u00a084-8048-639-2.\n^ Whitburn, Joel (2014). Cash Box Pop Hits 1952-1996. Sheridan Books, Inc. ISBN\u00a0978-0-89820-209-0.\n^ \"Michael Jackson Chart History (Hot 100)\". Billboard. September 9, 2021. Retrieved September 9, 2021.\n^ a b \"Allmusic (Thriller > Charts & Awards > Billboard Singles)\". Allmusic.com. Rovi Corporation. Retrieved January 23, 2010.\n^ Whitburn, Joel (1993). Top Adult Contemporary: 1961\u20131993. Record Research. p.\u00a0118.\n^ \"Michael Jackson\"."}
+{"query": "who sang the hit song \"thriller\"?", "domain": "music", "doc": "^ \"Michael Jackson Chart History (Hot 100)\". Billboard. September 9, 2021. Retrieved September 9, 2021.\n^ a b \"Allmusic (Thriller > Charts & Awards > Billboard Singles)\". Allmusic.com. Rovi Corporation. Retrieved January 23, 2010.\n^ Whitburn, Joel (1993). Top Adult Contemporary: 1961\u20131993. Record Research. p.\u00a0118.\n^ \"Michael Jackson\".\n^ \"Offiziellecharts.de \u2013 Michael Jackson \u2013 Thriller\" (in German). GfK Entertainment charts.\nRetrieved March 18, 2019.\n^ a b c d e f g \"Michael Jackson \u2013 Thriller\" (in French). Les classement single.\n^ a b \"Michael Jackson \u2013 Thriller\". Top Digital Download.\n^ a b c d e f \"Michael Jackson \u2013 Thriller\" Canciones Top 50.\n^ a b \"Michael Jackson \u2013 Thriller\" (in German). \u00d63 Austria Top 40.\n^ a b \"Michael Jackson \u2013 Thriller\". VG-lista.\n^ a b c \"Michael Jackson \u2013 Thriller\". Swiss Singles Chart.\n^ \"Michael Jackson \u2013 Thriller\". ARIA Top 50 Singles.\n^ \"30 Back Catalogue Singles \u2013 July 18, 2009\". UltraTop.be. Hung Medien. Retrieved January 24, 2010.\n^ \"30 Back Catalogue Singles \u2013 July 4, 2009\". UltraTop.be. Hung Medien. Retrieved January 24, 2010.\n^ \"Michael Jackson Album & Song Chart History\". Billboard.com. Nielsen Business Media. Retrieved October 29, 2011.\n^ \"Michael Jackson: Thriller\" (in Finnish). Musiikkituottajat.\n^ \"Download Single Top 50 \u2013 04/07/2009\". Lescharts.com. Hung Medien. Retrieved January 23, 2010.\n^ \"Michael Jackson \u2013 Thriller\". Singles Top 100.\n^ \"Michael Jackson Chart History (Digital Song Sales)\". Billboard.\n^ \"The Hot 100, Week of November 16, 2013\". Billboard. Prometheus Global Media. Retrieved November 12, 2015.\n^ \"The Hot 100, Week of November 15, 2014\". Billboard. Prometheus Global Media.\n^ \"The Hot 100, Week of November 21, 2015\". Billboard. Prometheus Global Media. Retrieved November 12, 2015.\n^ \"Michael Jackson Chart History (Canadian Hot 100)\". Billboard.\nRetrieved November 6, 2018.\n^ Zellner, Xander. \"Michael Jackson's 'Thriller' Returns to Hot 100, Thanks to Halloween Gains\". Billboard. Retrieved November 6, 2018."}
+{"query": "who sang the hit song \"thriller\"?", "domain": "music", "doc": "^ \"The Hot 100, Week of November 21, 2015\". Billboard. Prometheus Global Media. Retrieved November 12, 2015.\n^ \"Michael Jackson Chart History (Canadian Hot 100)\". Billboard.\nRetrieved November 6, 2018.\n^ Zellner, Xander. \"Michael Jackson's 'Thriller' Returns to Hot 100, Thanks to Halloween Gains\". Billboard. Retrieved November 6, 2018.\n^ \"The Hot 100, Week of November 10, 2018\". Billboard. Retrieved September 9, 2021.\n^ \"The Hot 100, Week of November 9, 2019\". Billboard. Retrieved March 20, 2021.\n^ \"The Global 200, Week of November 14, 2020\". Billboard. Retrieved November 8, 2023.\n^ \"The Hot 100, Week of November 14, 2020\". Billboard. Retrieved November 14, 2020.\n^ \"Canadian Hot 100, Week of November 13, 2021\". Billboard. Retrieved November 23, 2021.\n^ \"Michael Jackson Chart History (Global 200)\". Billboard.\nRetrieved November 9, 2021.\n^ \"Official Singles Chart Top 100\". Official Charts Company.\nRetrieved November 8, 2023.\n^ \"Official Hip Hop and R&B Singles Chart Top 40\". Official Charts Company.\nRetrieved November 5, 2021.\n^ \"Michael Jackson's 'Thriller' Leads Halloween Treats on Billboard Hot 100\". Billboard. Retrieved November 8, 2021.\n^ \"The Hot 100, Week of November 13, 2021\". Billboard. Retrieved November 5, 2022.\n^ \"Digital Song Sales Chart, Week of November 13, 2021\". Billboard. Retrieved November 11, 2021.\n^ \"Canadian Hot 100, Week of November 12, 2022\". Billboard. Retrieved November 8, 2022.\n^ \"The Global 200, Week of November 12, 2022\". Billboard. Retrieved November 8, 2022.\n^ \"The Hot 100, Week of November 12, 2022\". Billboard. Retrieved November 8, 2022.\n^ \"Canadian Hot 100, Week of November 11, 2023\". Billboard. Retrieved November 8, 2023.\n^ \"The Global 200, Week of November 11, 2023\". Billboard. Retrieved November 8, 2023.\n^ \"Official Singles Chart Top 100\". Official Charts Company.\nRetrieved November 8, 2023.\n^ \"The Hot 100, Week of November 11, 2023\". Billboard. Retrieved November 8, 2023."}
+{"query": "who sang the hit song \"thriller\"?", "domain": "music", "doc": "^ \"Canadian Hot 100, Week of November 11, 2023\". Billboard. Retrieved November 8, 2023.\n^ \"The Global 200, Week of November 11, 2023\". Billboard. Retrieved November 8, 2023.\n^ \"Official Singles Chart Top 100\". Official Charts Company.\nRetrieved November 8, 2023.\n^ \"The Hot 100, Week of November 11, 2023\". Billboard. Retrieved November 8, 2023.\n^ \"Kent Music Report No 548 \u2013 31 December 1984 > National Top 100 Singles for 1984\". Kent Music Report. Retrieved January 23, 2023 \u2013 via Imgur.com.\n^ \"Jaaroverzichten 1984\". Ultratop. Retrieved December 14, 2021.\n^ \"\u00c5rslista Singlar \u2013 \u00c5r 2009\" (in Swedish). Sverigetopplistan. Retrieved March 29, 2020.\n^ \"Schweizer Jahreshitparade 2009 \u2013 hitparade.ch\". Hung Medien. Retrieved March 29, 2020.\n^ \"Charts Plus Year end 2009\" (PDF). Charts Plus. Retrieved May 16, 2020.\n^ \"ARIA Charts \u2013 Accreditations \u2013 2021 Singles\" (PDF). Australian Recording Industry Association.\n^ \"Danish\nsingle\ncertifications \u2013 Michael Jackson \u2013 Thriller\". IFPI Danmark. Retrieved July 2, 2023.\n^ \"French\nsingle\ncertifications \u2013 Michael Jackson \u2013 Thriller\" (in French). InfoDisc. Retrieved November 28, 2022. Select MICHAEL JACKSON and click OK.\n^ \"Gold-/Platin-Datenbank (Michael Jackson;\u00a0'Thriller')\" (in German). Bundesverband Musikindustrie. Retrieved February 18, 2023.\n^ \"Italian\nsingle\ncertifications \u2013 Michael Jackson \u2013 Thriller\" (in Italian). Federazione Industria Musicale Italiana. Select \"2014\" in the \"Anno\" drop-down menu. Select \"Thriller\" in the \"Filtra\" field. Select \"Singoli\" under \"Sezione\".\n^ \"Japanese\nringtone\ncertifications \u2013 Michael Jackson \u2013 Thriller\" (in Japanese). Recording Industry Association of Japan. Retrieved December 30, 2020. Select 2009\u5e7411\u6708 on the drop-down menu\n^ \"Certificaciones\" (in Spanish). Asociaci\u00f3n Mexicana de Productores de Fonogramas y Videogramas. Retrieved November 28, 2022. Type Michael Jackson in the box under the ARTISTA column heading\u00a0and Thriller in the box under the T\u00cdTULO column heading.\n^ \"Spanish\nsingle"}
+{"query": "who sang the hit song \"thriller\"?", "domain": "music", "doc": "^ \"Certificaciones\" (in Spanish). Asociaci\u00f3n Mexicana de Productores de Fonogramas y Videogramas. Retrieved November 28, 2022. Type Michael Jackson in the box under the ARTISTA column heading\u00a0and Thriller in the box under the T\u00cdTULO column heading.\n^ \"Spanish\nsingle\ncertifications \u2013 Michael Jackson \u2013 Thriller\". El portal de M\u00fasica. Productores de M\u00fasica de Espa\u00f1a.\n^ \"British\nsingle\ncertifications \u2013 Michael Jackson \u2013 Thriller\". British Phonographic Industry. Retrieved March 17, 2023.\n^ \"British\nsingle\ncertifications \u2013 Michael Jackson \u2013 Thriller\". British Phonographic Industry. Retrieved March 17, 2023.\n^ \"American\nsingle\ncertifications \u2013 Michael Jackson \u2013 Thriller\". Recording Industry Association of America. Retrieved August 29, 2022.\n^ \"American\nringtone\ncertifications \u2013 Michael Jackson \u2013 Thriller\". Recording Industry Association of America.\nBibliography\nBrooks, Darren (2002). Michael Jackson: An Exceptional Journey. Chrome Dreams. ISBN\u00a01-84240-178-5.\nGeorge, Nelson (2004). Michael Jackson: The Ultimate Collection (booklet). Sony BMG.\nGrant, Adrian (2009). Michael Jackson: The Visual Documentary. Omnibus Press. ISBN\u00a0978-1-84938-261-8.\nJones, Jel (2005). Michael Jackson, the King of Pop: The Big Picture: the Music! the Man! the Legend! the Interviews!. Amber Books Publishing. ISBN\u00a00-9749779-0-X.\nTaraborrelli, J. Randy (2004). The Magic and the Madness. Terra Alta, WV: Headline. ISBN\u00a00-330-42005-4.\nHalstead, Craig (2003). Michael Jackson The Solo Years. On-Line Ltd. ISBN\u00a0978-0-7552-0091-7.\nvteMichael Jackson: ThrillerSide one\n\"Wanna Be Startin' Somethin'\"\n\"Baby Be Mine\"\n\"The Girl Is Mine\"\n\"Thriller\"\nSide two\n\"Beat It\"\n\"Billie Jean\"\n\"Human Nature\"\n\"P.Y.T. (Pretty Young Thing)\"\n\"The Lady in My Life\"\nRelated articles\nE.T. the Extra-Terrestrial (audiobook)\nFarewell My Summer Love\nVictory\nVictory Tour\nMichael Jackson's Thriller\nThriller jacket\nThriller 25\nThriller 40\nThriller 40 (film)\nThrill the World\nThriller viral video\nDonga\nThriller \u2013 Live"}
+{"query": "who sang the hit song \"thriller\"?", "domain": "music", "doc": "\"Baby Be Mine\"\n\"The Girl Is Mine\"\n\"Thriller\"\nSide two\n\"Beat It\"\n\"Billie Jean\"\n\"Human Nature\"\n\"P.Y.T. (Pretty Young Thing)\"\n\"The Lady in My Life\"\nRelated articles\nE.T. the Extra-Terrestrial (audiobook)\nFarewell My Summer Love\nVictory\nVictory Tour\nMichael Jackson's Thriller\nThriller jacket\nThriller 25\nThriller 40\nThriller 40 (film)\nThrill the World\nThriller viral video\nDonga\nThriller \u2013 Live\nMichael Jackson albums discography\nvteMichael Jackson songs\nSingles\nSongs\nUnreleased songs\n1970s\n\"Got to Be There\"\n\"Ain't No Sunshine\"\n\"I Wanna Be Where You Are\"\n\"Rockin' Robin\"\n\"Love Is Here and Now You're Gone\"\n\"You've Got a Friend\"\n\"Ben\"\n\"Everybody's Somebody's Fool\"\n\"My Girl\"\n\"Shoo-Be-Doo-Be-Doo-Da-Day\"\n\"We've Got a Good Thing Going\"\n\"With a Child's Heart\"\n\"Morning Glow\"\n\"All the Things You Are\"\n\"Happy\"\n\"Too Young\"\n\"Music and Me\"\n\"We're Almost There\"\n\"Just a Little Bit of You\"\n\"You Can't Win\"\n\"Don't Stop 'Til You Get Enough\"\n\"Rock with You\"\n\"Working Day and Night\"\n\"It's the Falling in Love\"\n1980s\n\"Off the Wall\"\n\"Girlfriend\"\n\"She's Out of My Life\"\n\"One Day in Your Life\"\n\"The Girl Is Mine\"\n\"Billie Jean\"\n\"Beat It\"\n\"Wanna Be Startin' Somethin'\"\n\"Human Nature\"\n\"P.Y.T. (Pretty Young Thing)\"\n\"Thriller\"\n\"You've Really Got a Hold on Me\"\n\"Here I Am (Come and Take Me)\"\n\"Lonely Teardrops\"\n\"That's What Love Is Made Of\"\n\"Farewell My Summer Love\"\n\"Girl You're So Together\"\n\"I Just Can't Stop Loving You\"\n\"Bad\"\n\"The Way You Make Me Feel\"\n\"Speed Demon\"\n\"Liberian Girl\"\n\"Just Good Friends\"\n\"Another Part of Me\"\n\"Man in the Mirror\"\n\"Dirty Diana\"\n\"Smooth Criminal\"\n\"Leave Me Alone\"\n\"Twenty-Five Miles\"\n1990s\n\"Black or White\"\n\"Jam\"\n\"In the Closet\"\n\"Remember the Time\"\n\"Heal the World\"\n\"Who Is It\"\n\"Give In to Me\"\n\"Will You Be There\"\n\"Gone Too Soon\"\n\"Dangerous\"\n\"Come Together\"\n\"Scream\"\n\"Childhood\"\n\"They Don't Care About Us\"\n\"Stranger in Moscow\"\n\"This Time Around\"\n\"Earth Song\"\n\"D.S.\"\n\"You Are Not Alone\"\n\"Tabloid Junkie\"\n\"HIStory\"\n\"Smile\"\n\"Blood on the Dance Floor\"\n\"Ghosts\"\n\"Is It Scary\"\n\"On the Line\"\n2000s"}
+{"query": "who sang the hit song \"thriller\"?", "domain": "music", "doc": "\"Jam\"\n\"In the Closet\"\n\"Remember the Time\"\n\"Heal the World\"\n\"Who Is It\"\n\"Give In to Me\"\n\"Will You Be There\"\n\"Gone Too Soon\"\n\"Dangerous\"\n\"Come Together\"\n\"Scream\"\n\"Childhood\"\n\"They Don't Care About Us\"\n\"Stranger in Moscow\"\n\"This Time Around\"\n\"Earth Song\"\n\"D.S.\"\n\"You Are Not Alone\"\n\"Tabloid Junkie\"\n\"HIStory\"\n\"Smile\"\n\"Blood on the Dance Floor\"\n\"Ghosts\"\n\"Is It Scary\"\n\"On the Line\"\n2000s\n\"Speechless\"\n\"You Rock My World\"\n\"Heaven Can Wait\"\n\"Butterflies\"\n\"Cry\"\n\"One More Chance\"\n\"Cheater\"\n\"(I Like) The Way You Love Me\"\n\"Fall Again\"\n\"This Is It\"\n2010s\n\"Hold My Hand\"\n\"Hollywood Tonight\"\n\"(I Can't Make It) Another Day\"\n\"Behind the Mask\"\n\"Don't Be Messin' 'Round\"\n\"I'm So Blue\"\n\"Price of Fame\"\n\"Love Never Felt So Good\"\n\"Chicago\"\n\"Loving You\"\n\"A Place with No Name\"\n\"Slave to the Rhythm\"\n\"Blue Gangsta\"\n2020s\n\"She's Trouble\"\nOther\n\"We Are the World\"\n\"Mind Is the Magic\"\n\"What More Can I Give\"\n\"We Are the World 25 for Haiti\"\n\"Blood on the Dance Floor x Dangerous\"\n\"Diamonds Are Invincible\"\nFeatured\n\"Ease on Down the Road\"\n\"A Brand New Day\"\n\"Night Time Lover\"\n\"Papa Was a Rollin' Stone\"\n\"State of Independence\"\n\"Muscles\"\n\"Say Say Say\"\n\"Somebody's Watching Me\"\n\"Don't Stand Another Chance\"\n\"Centipede\"\n\"Tell Me I'm Not Dreamin' (Too Good to Be True)\"\n\"Eaten Alive\"\n\"Get It\"\n\"2300 Jackson Street\"\n\"Do the Bartman\"\n\"Whatzupwitu\"\n\"Why\"\n\"I Need You\"\n\"We Be Ballin'\"\n\"Girls, Girls, Girls\"\n\"All in Your Name\"\n\"There Must Be More to Life Than This\"\n\"Low\"\n\"Don't Matter to Me\"\nCategory\nAuthority control databases\nMusicBrainz work\nRetrieved from \"https://en.wikipedia.org/w/index.php?title=Thriller_(song)&oldid=1212467768\""}
+{"query": "who sang the hit song \"thriller\"?", "domain": "music", "doc": "\nCategories: 1982 songs1983 singles1984 singlesCBS Records singlesColumbia Records singlesCompositions with a narratorEpic Records singlesHalloween songsMichael Jackson songsNumber-one singles in SpainSNEP Top Singles number-one singlesSong recordings produced by Quincy JonesSongs about monstersSongs written by Rod TempertonHidden categories: CS1 Dutch-language sources (nl)CS1 Italian-language sources (it)CS1 Spanish-language sources (es)Articles with German-language sources (de)CS1 Swedish-language sources (sv)CS1 French-language sources (fr)CS1 German-language sources (de)Cite certification used for Italy without IDCS1 Japanese-language sources (ja)Articles with short descriptionShort description is different from WikidataGood articlesUse American English from November 2021All Wikipedia articles written in American EnglishUse mdy dates from November 2014Articles with hAudio microformatsCertification Cite Ref usages outside Certification Table EntrySingle chart usages for FlandersSingle chart usages for Dutch40Single chart called without artistSingle chart called without songSingle chart usages for Dutch100Single chart usages for New ZealandSingle chart usages for West GermanySingle chart usages for FranceSingle chart usages for ItalySingle chart making named refSingle chart usages for SpainSingle chart usages for AustriaSingle chart usages for NorwaySingle chart usages for SwissSingle chart usages for AustraliaSingle chart usages for FinlandSingle chart usages for SwedenSingle chart usages for BillboarddigitalsongsSingle chart usages for CanadaSingle chart usages for Billboardglobal200Single chart usages for UKSingle chart usages for UKrandbCertification Table Entry usages for AustraliaPages using certification Table Entry with streaming figuresCertification Table Entry usages for DenmarkCertification Table Entry usages for FrancePages using certification Table Entry with sales figuresCertification Table Entry usages for GermanyCertification Table Entry usages for ItalyCertification Table Entry usages for JapanCertification Table Entry usages for MexicoCertification Table Entry usages for SpainCertification Table Entry usages for United KingdomCertification Table Entry usages for United StatesPages using certification Table Entry with sales footnotePages using certification Table Entry with streaming footnoteArticles with MusicBrainz work identifiers"}
+{"query": "who sang the hit song \"thriller\"?", "domain": "music", "doc": "This page was last edited on 8 March 2024, at 01:12\u00a0(UTC).\nText is available under the Creative Commons Attribution-ShareAlike License 4.0;\nadditional terms may apply. By using this site, you agree to the Terms of Use and Privacy Policy. Wikipedia\u00ae is a registered trademark of the Wikimedia Foundation, Inc., a non-profit organization.\nPrivacy policy\nAbout Wikipedia\nDisclaimers\nContact Wikipedia\nCode of Conduct\nDevelopers\nStatistics\nCookie statement\nMobile view\nToggle limited content width"}
+{"query": "who sang the hit song \"thriller\"?", "domain": "music", "doc": "Jon Pareles of The New York Times noted that &quot;&#x27;Billie Jean&#x27;, &#x27;Beat It&#x27;, &#x27;Wanna Be Startin&#x27; Somethin&#x27; &#x27; and &quot;the movie in the song &#x27;Thriller&#x27;&quot;, were the songs, unlike the &quot;fluff&quot; &quot;P.Y.T.&quot;, that were &quot;the hits that made Thriller a world-beater; along with Mr. Jackson&#x27;s stage and video presence, ...Jon Pareles of The New York Times noted that \"'Billie Jean', 'Beat It', 'Wanna Be Startin' Somethin' ' and \"the movie in the song 'Thriller'\", were the songs, unlike the \"fluff\" \"P.Y.T.\", that were \"the hits that made Thriller a world-beater; along with Mr. Jackson's stage and video presence, listeners must have identified with his willingness to admit terror.\" It appears on several of Jackson's greatest-hits albums and has been covered by numerous artists. The song has returned to the Billboard Hot 100 chart multiple times due to its popularity around Halloween. \"Thriller\" is a disco-funk song The introduction features sound effects such as a creaking door, thunder, feet walking on wooden planks, winds and howling wolves. This gave Jackson at least one top-20 hit across seven consecutive decades from 1969 on the Billboard Hot 100. \"Thriller\" was certified platinum by the Recording Industry Association of America on December 4, 1989, for sales of over one million physical units in the US As of August 2016, the song had sold 4,024,398 copies in the US. \"Thriller\" is certified Diamond by the Recording Industry Association of America. It appears on several of Jackson's greatest-hits albums and has been covered by numerous artists. The song has returned to the Billboard Hot 100 chart multiple times due to its popularity around Halloween. \"Thriller\" has returned to the Billboard Hot 100 chart multiple times due to its popularity around Halloween"}
+{"query": "who sang the hit song \"thriller\"?", "domain": "music", "doc": ". \"Thriller\" is certified Diamond by the Recording Industry Association of America. It appears on several of Jackson's greatest-hits albums and has been covered by numerous artists. The song has returned to the Billboard Hot 100 chart multiple times due to its popularity around Halloween. \"Thriller\" has returned to the Billboard Hot 100 chart multiple times due to its popularity around Halloween. It re-entered the Billboard Hot 100 in October 2013 at number 42, number 31 in November 2018, and number 19 in November 2021, its highest placement since 1984. This gave Jackson at least one top-20 hit across seven consecutive decades from 1969 on the Billboard Hot 100."}
diff --git a/AgentQnA/retrieval_tool/docker/build_images.sh b/AgentQnA/retrieval_tool/docker/build_images.sh
index d73c74f4fa..4ecf7c4ae1 100644
--- a/AgentQnA/retrieval_tool/docker/build_images.sh
+++ b/AgentQnA/retrieval_tool/docker/build_images.sh
@@ -2,7 +2,6 @@ cd ${WORKDIR}/GenAIComps/
 echo $PWD
 
 echo "==============Building dataprep image================="
-# cp ingest_data.py ${WORKDIR}/GenAIComps/comps/dataprep/redis/langchain/prepare_doc_redis.py
 docker build --no-cache -t opea/dataprep-redis:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/dataprep/redis/langchain/docker/Dockerfile .
 echo "==============Successfully built dataprep image================="
 
@@ -22,4 +21,4 @@ cd $WORKDIR/GenAIExamples/AgentQnA/retrieval_tool/docker/
 echo $PWD
 echo "==============Building retrieval-tool image================="
 docker build --no-cache -t opea/retrievaltool:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f Dockerfile_retrievaltool .
-echo "==============Successfully built embedding-tei image================="
\ No newline at end of file
+echo "==============Successfully built retrieval-tool image================="
\ No newline at end of file
diff --git a/AgentQnA/retrieval_tool/docker/launch_retrieval_tool.sh b/AgentQnA/retrieval_tool/docker/launch_retrieval_tool.sh
index 299e12dc90..90291fb7b7 100644
--- a/AgentQnA/retrieval_tool/docker/launch_retrieval_tool.sh
+++ b/AgentQnA/retrieval_tool/docker/launch_retrieval_tool.sh
@@ -1,5 +1,5 @@
 host_ip=$(hostname -I | awk '{print $1}')
-export WORKDIR=/localdisk/minminho
+
 export no_proxy=${no_proxy}
 export http_proxy=${http_proxy}
 export https_proxy=${https_proxy}
diff --git a/AgentQnA/retrieval_tool/run_ingest_data.sh b/AgentQnA/retrieval_tool/run_ingest_data.sh
index 2d365f34e2..87da727e72 100644
--- a/AgentQnA/retrieval_tool/run_ingest_data.sh
+++ b/AgentQnA/retrieval_tool/run_ingest_data.sh
@@ -1,4 +1,4 @@
-FILEDIR=${WORKDIR}/datasets/crag_docs/
-FILENAME=crag_docs_music.jsonl
+FILEDIR=${WORKDIR}/GenAIExamples/AgentQnA/example_data/
+FILENAME=test_docs_music.jsonl
 
 python index_data.py --filedir ${FILEDIR} --filename ${FILENAME}
\ No newline at end of file
diff --git a/AgentQnA/tests/1_build_images.sh b/AgentQnA/tests/1_build_images.sh
new file mode 100644
index 0000000000..a2255ad382
--- /dev/null
+++ b/AgentQnA/tests/1_build_images.sh
@@ -0,0 +1,69 @@
+#!/bin/bash
+# Copyright (C) 2024 Intel Corporation
+# SPDX-License-Identifier: Apache-2.0
+
+set -e
+WORKPATH=$(dirname "$PWD")
+export WORKDIR=$WORKPATH/../../
+echo "WORKDIR=${WORKDIR}"
+export ip_address=$(hostname -I | awk '{print $1}')
+
+
+function get_genai_comps() {
+    cd $WORKDIR
+    if [ ! -d "GenAIComps" ] ; then
+        git clone https://github.com/opea-project/GenAIComps.git
+    fi
+}
+
+function build_docker_images_for_retrieval_tool(){
+    cd $WORKDIR/GenAIComps/
+    echo $PWD
+    echo "==============Building dataprep image================="
+    docker build --no-cache -t opea/dataprep-redis:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/dataprep/redis/langchain/docker/Dockerfile .
+    echo "==============Successfully built dataprep image================="
+
+    echo "==============Building embedding-tei image================="
+    docker build --no-cache -t opea/embedding-tei:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/embeddings/langchain/docker/Dockerfile .
+    echo "==============Successfully built embedding-tei image================="
+
+    echo "==============Building retriever-redis image================="
+    docker build --no-cache -t opea/retriever-redis:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/retrievers/langchain/redis/docker/Dockerfile .
+    echo "==============Successfully built retriever-redis image================="
+
+    echo "==============Building reranking-tei image================="
+    docker build --no-cache -t opea/reranking-tei:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/reranks/tei/docker/Dockerfile .
+    echo "==============Successfully built reranking-tei image================="
+
+    cd $WORKDIR/GenAIExamples/AgentQnA/retrieval_tool/docker/
+    echo $PWD
+    echo "==============Building retrieval-tool image================="
+    docker build --no-cache -t opea/retrievaltool:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f Dockerfile_retrievaltool .
+    echo "==============Successfully built retrieval-tool image================="
+}
+
+function build_agent_docker_image() {
+    cd $WORKDIR/GenAIComps
+    docker build -t opea/comps-agent-langchain:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/agent/langchain/docker/Dockerfile .
+}
+
+
+
+
+
+function main() {
+
+    echo "==================== Get GenAI components ===================="
+    get_genai_comps
+    echo "==================== GenAI components downloaded ===================="
+
+    echo "==================== Build docker images for retrieval tool ===================="
+    build_docker_images_for_retrieval_tool
+    echo "==================== Build docker images for retrieval tool completed ===================="
+
+    echo "==================== Build agent docker image ===================="
+    build_agent_docker_image
+    echo "==================== Build agent docker image completed ===================="
+}
+
+main
diff --git a/AgentQnA/tests/2_start_retrieval_tool.sh b/AgentQnA/tests/2_start_retrieval_tool.sh
new file mode 100644
index 0000000000..1f64acc616
--- /dev/null
+++ b/AgentQnA/tests/2_start_retrieval_tool.sh
@@ -0,0 +1,19 @@
+#!/bin/bash
+# Copyright (C) 2024 Intel Corporation
+# SPDX-License-Identifier: Apache-2.0
+
+set -e
+WORKPATH=$(dirname "$PWD")
+export WORKDIR=$WORKPATH/../../
+echo "WORKDIR=${WORKDIR}"
+export ip_address=$(hostname -I | awk '{print $1}')
+
+function start_retrieval_tool() {
+    echo "Starting Retrieval tool"
+    cd $WORKDIR/GenAIExamples/AgentQnA/retrieval_tool/docker/
+    bash launch_retrieval_tool.sh
+}
+
+echo "==================== Start retrieval tool ===================="
+start_retrieval_tool
+echo "==================== Retrieval tool started ===================="
\ No newline at end of file
diff --git a/AgentQnA/tests/3_ingest_data_and_validate_retrieval.sh b/AgentQnA/tests/3_ingest_data_and_validate_retrieval.sh
new file mode 100644
index 0000000000..28a2b28935
--- /dev/null
+++ b/AgentQnA/tests/3_ingest_data_and_validate_retrieval.sh
@@ -0,0 +1,63 @@
+#!/bin/bash
+# Copyright (C) 2024 Intel Corporation
+# SPDX-License-Identifier: Apache-2.0
+
+set -e
+
+WORKPATH=$(dirname "$PWD")
+export WORKDIR=$WORKPATH/../../
+echo "WORKDIR=${WORKDIR}"
+export ip_address=$(hostname -I | awk '{print $1}')
+
+
+function validate() {
+    local CONTENT="$1"
+    local EXPECTED_RESULT="$2"
+    local SERVICE_NAME="$3"
+
+    if echo "$CONTENT" | grep -q "$EXPECTED_RESULT"; then
+        echo "[ $SERVICE_NAME ] Content is as expected: $CONTENT"
+        echo 0
+    else
+        echo "[ $SERVICE_NAME ] Content does not match the expected result: $CONTENT"
+        echo 1
+    fi
+}
+
+function ingest_data_and_validate() {
+    echo "Ingesting data"
+    cd $WORKDIR/GenAIExamples/AgentQnA/retrieval_tool/
+    local CONTENT=$(bash run_ingest_data.sh)
+    local EXIT_CODE=$(validate "$CONTENT" "Data preparation succeeded" "dataprep-redis-server")
+    echo "$EXIT_CODE"
+    local EXIT_CODE="${EXIT_CODE:0-1}"
+    echo "return value is $EXIT_CODE"
+    if [ "$EXIT_CODE" == "1" ]; then
+        docker logs dataprep-redis-server
+        return 1
+    fi
+}
+
+function validate_retrieval_tool() {
+    echo "----------------Test retrieval tool ----------------"
+    local CONTENT=$(http_proxy="" curl http://${ip_address}:8889/v1/retrievaltool -X POST -H "Content-Type: application/json" -d '{
+     "text": "Who sang Thriller"
+    }')
+    local EXIT_CODE=$(validate "$CONTENT" "Thriller" "retrieval-tool")
+    
+    if [ "$EXIT_CODE" == "1" ]; then
+        docker logs retrievaltool-xeon-backend-server
+        exit 1
+    fi
+}
+
+function main(){
+
+    echo "==================== Ingest data ===================="
+    ingest_data_and_validate
+    echo "==================== Data ingestion completed ===================="
+
+    echo "==================== Validate retrieval tool ===================="
+    validate_retrieval_tool
+    echo "==================== Retrieval tool validated ===================="
+}
\ No newline at end of file
diff --git a/AgentQnA/tests/4_launch_and_validate_agent.sh b/AgentQnA/tests/4_launch_and_validate_agent.sh
new file mode 100644
index 0000000000..9085589acd
--- /dev/null
+++ b/AgentQnA/tests/4_launch_and_validate_agent.sh
@@ -0,0 +1,60 @@
+#!/bin/bash
+# Copyright (C) 2024 Intel Corporation
+# SPDX-License-Identifier: Apache-2.0
+
+set -e
+echo "OPENAI_API_KEY=${OPENAI_API_KEY}"
+
+WORKPATH=$(dirname "$PWD")
+export WORKDIR=$WORKPATH/../../
+echo "WORKDIR=${WORKDIR}"
+export ip_address=$(hostname -I | awk '{print $1}')
+export TOOLSET_PATH=$WORKDIR/GenAIExamples/AgentQnA/tools/
+
+function start_agent_and_api_server() {
+    echo "Starting CRAG server"
+    docker run -d -p=8080:8000 docker.io/aicrowd/kdd-cup-24-crag-mock-api:v0
+
+    echo "Starting Agent services"
+    cd $WORKDIR/GenAIExamples/AgentQnA/docker/openai
+    bash launch_agent_service_openai.sh
+}
+
+function validate() {
+    local CONTENT="$1"
+    local EXPECTED_RESULT="$2"
+    local SERVICE_NAME="$3"
+
+    if echo "$CONTENT" | grep -q "$EXPECTED_RESULT"; then
+        echo "[ $SERVICE_NAME ] Content is as expected: $CONTENT"
+        echo 0
+    else
+        echo "[ $SERVICE_NAME ] Content does not match the expected result: $CONTENT"
+        echo 1
+    fi
+}
+
+function validate_agent_service() {
+    echo "----------------Test agent ----------------"
+    local CONTENT=$(http_proxy="" curl http://${ip_address}:9090/v1/chat/completions -X POST -H "Content-Type: application/json" -d '{
+     "query": "Who sang Thriller"
+    }')
+    local EXIT_CODE=$(validate "$CONTENT" "Thriller" "react-agent-endpoint")
+    docker logs react-agent-endpoint
+    if [ "$EXIT_CODE" == "1" ]; then
+        exit 1
+    fi
+
+}
+
+function main() {
+    echo "==================== Start agent ===================="
+    start_agent_and_api_server
+    echo "==================== Agent started ===================="
+
+    echo "==================== Validate agent service ===================="
+    validate_agent_service
+    echo "==================== Agent service validated ===================="
+}
+
+main
\ No newline at end of file
diff --git a/AgentQnA/tests/_test_agentqna_on_xeon.sh b/AgentQnA/tests/_test_agentqna_on_xeon.sh
index 489a827b38..ed31c62af2 100644
--- a/AgentQnA/tests/_test_agentqna_on_xeon.sh
+++ b/AgentQnA/tests/_test_agentqna_on_xeon.sh
@@ -3,73 +3,48 @@
 # SPDX-License-Identifier: Apache-2.0
 
 set -e
-echo "IMAGE_REPO=${IMAGE_REPO}"
-echo "OPENAI_API_KEY=${OPENAI_API_KEY}"
 
+echo "OPENAI_API_KEY=${OPENAI_API_KEY}"
 WORKPATH=$(dirname "$PWD")
 export WORKDIR=$WORKPATH/../../
 echo "WORKDIR=${WORKDIR}"
 export ip_address=$(hostname -I | awk '{print $1}')
 export TOOLSET_PATH=$WORKDIR/GenAIExamples/AgentQnA/tools/
 
-function build_agent_docker_image() {
-    cd $WORKDIR
-    if [ ! -d "GenAIComps" ] ; then
-        git clone https://github.com/opea-project/GenAIComps.git
-    fi
-    cd GenAIComps
-    echo PWD: $(pwd)
-    docker build -t opea/comps-agent-langchain:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/agent/langchain/docker/Dockerfile .
+function stop_agent_and_api_server() {
+    echo "Stopping CRAG server"
+    docker stop $(docker ps -q --filter ancestor=docker.io/aicrowd/kdd-cup-24-crag-mock-api:v0)
+    echo "Stopping Agent services"
+    docker stop $(docker ps -q --filter ancestor=opea/comps-agent-langchain:latest)
 }
 
-function start_services() {
-    echo "Starting CRAG server"
-    docker run -d -p=8080:8000 docker.io/aicrowd/kdd-cup-24-crag-mock-api:v0
-    echo "Starting Agent services"
-    cd $WORKDIR/GenAIExamples/AgentQnA/docker/openai
-    bash launch_agent_service_openai.sh
+function stop_retrieval_tool() {
+    echo "Stopping Retrieval tool"
+    docker compose -f $WORKDIR/GenAIExamples/AgentQnA/retrieval_tool/docker/docker_compose.yaml down
 }
 
-function validate() {
-    local CONTENT="$1"
-    local EXPECTED_RESULT="$2"
-    local SERVICE_NAME="$3"
+echo "=================== #1 Building docker images===================="
+bash 1_build_images.sh
+echo "=================== #1 Building docker images completed===================="
 
-    if echo "$CONTENT" | grep -q "$EXPECTED_RESULT"; then
-        echo "[ $SERVICE_NAME ] Content is as expected: $CONTENT"
-        echo 0
-    else
-        echo "[ $SERVICE_NAME ] Content does not match the expected result: $CONTENT"
-        echo 1
-    fi
-}
+echo "=================== #2 Start retrieval tool===================="
+bash 2_start_retrieval_tool.sh
+echo "=================== #2 Retrieval tool started===================="
 
+echo "=================== #3 Ingest data and validate retrieval===================="
+bash 3_ingest_data_and_validate_retrieval.sh
+echo "=================== #3 Data ingestion and validation completed===================="
 
-function run_tests() {
-    echo "----------------Test supervisor agent ----------------"
-    local CONTENT=$(http_proxy="" curl http://${ip_address}:9090/v1/chat/completions -X POST -H "Content-Type: application/json" -d '{
-     "query": "Most recent album by Taylor Swift"
-    }')
-    local EXIT_CODE=$(validate "$CONTENT" "Taylor" "react-agent-endpoint")
-    docker logs react-agent-endpoint
-    if [ "$EXIT_CODE" == "1" ]; then
-        exit 1
-    fi
+echo "=================== #4 Start agent and API server===================="
+bash 4_launch_and_validate_agent.sh
+echo "=================== #4 Agent test passed ===================="
 
-}
+echo "=================== #5 Stop agent and API server===================="
+stop_agent_and_api_server
+echo "=================== #5 Agent and API server stopped===================="
 
-function stop_services() {
-    echo "Stopping CRAG server"
-    docker stop $(docker ps -q --filter ancestor=docker.io/aicrowd/kdd-cup-24-crag-mock-api:v0)
-    echo "Stopping Agent services"
-    docker stop $(docker ps -q --filter ancestor=opea/comps-agent-langchain:latest)
-}
-
-function main() {
-    build_agent_docker_image
-    start_services
-    run_tests
-    stop_services
-}
+# echo "=================== #6 Stop retrieval tool===================="
+# stop_retrieval_tool
+# echo "=================== #6 Retrieval tool stopped===================="
 
-main
+echo "ALL DONE!"

From cef6fa3b6418896f4540fe8c55d54acdcea7ec08 Mon Sep 17 00:00:00 2001
From: minmin-intel <minmin.hou@intel.com>
Date: Thu, 22 Aug 2024 11:19:24 -0700
Subject: [PATCH 15/39] set hf_cache as env var

Signed-off-by: minmin-intel <minmin.hou@intel.com>
---
 .../docker/docker-compose-retrieval-tool.yaml              | 4 ++--
 AgentQnA/retrieval_tool/docker/launch_retrieval_tool.sh    | 2 +-
 AgentQnA/tests/2_start_retrieval_tool.sh                   | 7 +++++++
 3 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/AgentQnA/retrieval_tool/docker/docker-compose-retrieval-tool.yaml b/AgentQnA/retrieval_tool/docker/docker-compose-retrieval-tool.yaml
index 15dd9d2426..4bae0d35bb 100644
--- a/AgentQnA/retrieval_tool/docker/docker-compose-retrieval-tool.yaml
+++ b/AgentQnA/retrieval_tool/docker/docker-compose-retrieval-tool.yaml
@@ -17,7 +17,7 @@ services:
     ports:
       - "6006:80"
     volumes:
-      - ${WORKDIR}/hf_cache:/data
+      - ${HF_CACHE_DIR}:/data
     shm_size: 1g
     environment:
       no_proxy: ${no_proxy}
@@ -70,7 +70,7 @@ services:
     ports:
       - "8808:80"
     volumes:
-      - ${WORKDIR}/hf_cache:/data
+      - ${HF_CACHE_DIR}:/data
     shm_size: 1g
     environment:
       no_proxy: ${no_proxy}
diff --git a/AgentQnA/retrieval_tool/docker/launch_retrieval_tool.sh b/AgentQnA/retrieval_tool/docker/launch_retrieval_tool.sh
index 90291fb7b7..9ba6451ed8 100644
--- a/AgentQnA/retrieval_tool/docker/launch_retrieval_tool.sh
+++ b/AgentQnA/retrieval_tool/docker/launch_retrieval_tool.sh
@@ -1,5 +1,5 @@
 host_ip=$(hostname -I | awk '{print $1}')
-
+export HF_CACHE_DIR=${HF_CACHE_DIR}
 export no_proxy=${no_proxy}
 export http_proxy=${http_proxy}
 export https_proxy=${https_proxy}
diff --git a/AgentQnA/tests/2_start_retrieval_tool.sh b/AgentQnA/tests/2_start_retrieval_tool.sh
index 1f64acc616..09fa8a2035 100644
--- a/AgentQnA/tests/2_start_retrieval_tool.sh
+++ b/AgentQnA/tests/2_start_retrieval_tool.sh
@@ -8,6 +8,12 @@ export WORKDIR=$WORKPATH/../../
 echo "WORKDIR=${WORKDIR}"
 export ip_address=$(hostname -I | awk '{print $1}')
 
+export HF_CACHE_DIR=$WORKDIR/hf_cache
+if [ ! -d "$HF_CACHE_DIR" ]; then
+    echo "Creating HF_CACHE directory"
+    mkdir -p "$HF_CACHE_DIR"
+fi
+
 function start_retrieval_tool() {
     echo "Starting Retrieval tool"
     cd $WORKDIR/GenAIExamples/AgentQnA/retrieval_tool/docker/
@@ -16,4 +22,5 @@ function start_retrieval_tool() {
 
 echo "==================== Start retrieval tool ===================="
 start_retrieval_tool
+sleep 20 # needed for downloading the models
 echo "==================== Retrieval tool started ===================="
\ No newline at end of file

From c6ebc21c879d67876ea8c93f0548bd5b208e500c Mon Sep 17 00:00:00 2001
From: minmin-intel <minmin.hou@intel.com>
Date: Thu, 22 Aug 2024 14:46:46 -0700
Subject: [PATCH 16/39] fix test

Signed-off-by: minmin-intel <minmin.hou@intel.com>
---
 .../docker/docker-compose-retrieval-tool.yaml | 29 +++++++++----------
 .../3_ingest_data_and_validate_retrieval.sh   |  5 +++-
 AgentQnA/tests/4_launch_and_validate_agent.sh |  2 +-
 AgentQnA/tests/_test_agentqna_on_xeon.sh      |  8 ++---
 4 files changed, 23 insertions(+), 21 deletions(-)

diff --git a/AgentQnA/retrieval_tool/docker/docker-compose-retrieval-tool.yaml b/AgentQnA/retrieval_tool/docker/docker-compose-retrieval-tool.yaml
index 4bae0d35bb..b01cac4266 100644
--- a/AgentQnA/retrieval_tool/docker/docker-compose-retrieval-tool.yaml
+++ b/AgentQnA/retrieval_tool/docker/docker-compose-retrieval-tool.yaml
@@ -27,8 +27,8 @@ services:
   embedding:
     image: opea/embedding-tei:latest
     container_name: embedding-tei-server
-    volumes:
-      - ${WORKDIR}/GenAIComps/comps/:/home/user/comps
+    # volumes:
+    #   - ${WORKDIR}/GenAIComps/comps/:/home/user/comps
     depends_on:
       - tei-embedding-service
     ports:
@@ -46,8 +46,8 @@ services:
   retriever:
     image: opea/retriever-redis:latest
     container_name: retriever-redis-server
-    volumes:
-      - ${WORKDIR}/GenAIComps/comps/:/home/user/comps
+    # volumes:
+    #   - ${WORKDIR}/GenAIComps/comps/:/home/user/comps
     depends_on:
       - redis-vector-db
     ports:
@@ -83,8 +83,8 @@ services:
   reranking:
     image: opea/reranking-tei:latest
     container_name: reranking-tei-xeon-server
-    volumes:
-      - ${WORKDIR}/GenAIComps/comps/:/home/user/comps
+    # volumes:
+    #   - ${WORKDIR}/GenAIComps/comps/:/home/user/comps
     depends_on:
       - tei-reranking-service
     ports:
@@ -106,8 +106,8 @@ services:
   dataprep-redis-service:
     image: opea/dataprep-redis:latest
     container_name: dataprep-redis-server
-    volumes:
-      - ${WORKDIR}/GenAIComps/comps/:/home/user/comps/
+    # volumes:
+    #   - ${WORKDIR}/GenAIComps/comps/:/home/user/comps/
     depends_on:
       - redis-vector-db
     ports:
@@ -125,9 +125,9 @@ services:
   retrievaltool-xeon-backend-server:
     image: opea/retrievaltool:latest
     container_name: retrievaltool-xeon-backend-server
-    volumes: 
-      - ${WORKDIR}/GenAIComps/comps/:/home/user/GenAIComps/comps/
-      - ${WORKDIR}/GenAIExamples/AgentQnA/retrieval_tool/docker/:/home/user/script/
+    # volumes: 
+    #   - ${WORKDIR}/GenAIComps/comps/:/home/user/GenAIComps/comps/
+    #   - ${WORKDIR}/GenAIExamples/AgentQnA/retrieval_tool/docker/:/home/user/script/
     depends_on:
       - redis-vector-db
       - tei-embedding-service
@@ -138,14 +138,13 @@ services:
     ports:
       - "8889:8889"
     environment:
-      # - no_proxy=${no_proxy}
-      # - https_proxy=${https_proxy} # certain proxies does not work for gateway on 4016
-      # - http_proxy=${http_proxy}
+      - no_proxy=${no_proxy}
+      - https_proxy=${https_proxy}
+      - http_proxy=${http_proxy}
       - MEGA_SERVICE_HOST_IP=${MEGA_SERVICE_HOST_IP}
       - EMBEDDING_SERVICE_HOST_IP=${EMBEDDING_SERVICE_HOST_IP}
       - RETRIEVER_SERVICE_HOST_IP=${RETRIEVER_SERVICE_HOST_IP}
       - RERANK_SERVICE_HOST_IP=${RERANK_SERVICE_HOST_IP}
-      # - LLM_SERVICE_HOST_IP=${LLM_SERVICE_HOST_IP}
     ipc: host
     restart: always
 
diff --git a/AgentQnA/tests/3_ingest_data_and_validate_retrieval.sh b/AgentQnA/tests/3_ingest_data_and_validate_retrieval.sh
index 28a2b28935..ef2d05af0d 100644
--- a/AgentQnA/tests/3_ingest_data_and_validate_retrieval.sh
+++ b/AgentQnA/tests/3_ingest_data_and_validate_retrieval.sh
@@ -27,6 +27,7 @@ function validate() {
 function ingest_data_and_validate() {
     echo "Ingesting data"
     cd $WORKDIR/GenAIExamples/AgentQnA/retrieval_tool/
+    echo $PWD
     local CONTENT=$(bash run_ingest_data.sh)
     local EXIT_CODE=$(validate "$CONTENT" "Data preparation succeeded" "dataprep-redis-server")
     echo "$EXIT_CODE"
@@ -60,4 +61,6 @@ function main(){
     echo "==================== Validate retrieval tool ===================="
     validate_retrieval_tool
     echo "==================== Retrieval tool validated ===================="
-}
\ No newline at end of file
+}
+
+main
\ No newline at end of file
diff --git a/AgentQnA/tests/4_launch_and_validate_agent.sh b/AgentQnA/tests/4_launch_and_validate_agent.sh
index 9085589acd..f1d916e451 100644
--- a/AgentQnA/tests/4_launch_and_validate_agent.sh
+++ b/AgentQnA/tests/4_launch_and_validate_agent.sh
@@ -37,7 +37,7 @@ function validate() {
 function validate_agent_service() {
     echo "----------------Test agent ----------------"
     local CONTENT=$(http_proxy="" curl http://${ip_address}:9090/v1/chat/completions -X POST -H "Content-Type: application/json" -d '{
-     "query": "Who sang Thriller"
+     "query": "Tell me about Michael Jackson song thriller"
     }')
     local EXIT_CODE=$(validate "$CONTENT" "Thriller" "react-agent-endpoint")
     docker logs react-agent-endpoint
diff --git a/AgentQnA/tests/_test_agentqna_on_xeon.sh b/AgentQnA/tests/_test_agentqna_on_xeon.sh
index ed31c62af2..bb8498850a 100644
--- a/AgentQnA/tests/_test_agentqna_on_xeon.sh
+++ b/AgentQnA/tests/_test_agentqna_on_xeon.sh
@@ -20,7 +20,7 @@ function stop_agent_and_api_server() {
 
 function stop_retrieval_tool() {
     echo "Stopping Retrieval tool"
-    docker compose -f $WORKDIR/GenAIExamples/AgentQnA/retrieval_tool/docker/docker_compose.yaml down
+    docker compose -f $WORKDIR/GenAIExamples/AgentQnA/retrieval_tool/docker/docker-compose-retrieval-tool.yaml down
 }
 
 echo "=================== #1 Building docker images===================="
@@ -43,8 +43,8 @@ echo "=================== #5 Stop agent and API server===================="
 stop_agent_and_api_server
 echo "=================== #5 Agent and API server stopped===================="
 
-# echo "=================== #6 Stop retrieval tool===================="
-# stop_retrieval_tool
-# echo "=================== #6 Retrieval tool stopped===================="
+echo "=================== #6 Stop retrieval tool===================="
+stop_retrieval_tool
+echo "=================== #6 Retrieval tool stopped===================="
 
 echo "ALL DONE!"

From dc33dd32a960f7844b4b3ec77bfed301820f8622 Mon Sep 17 00:00:00 2001
From: minmin-intel <minmin.hou@intel.com>
Date: Wed, 28 Aug 2024 09:34:26 -0700
Subject: [PATCH 17/39] test llama3.1 on gaudi

Signed-off-by: minmin-intel <minmin.hou@intel.com>
---
 .../docker-compose-agent-tgi-gaudi.yaml       | 91 +++++++++++++++++++
 .../launch_agent_service_tgi_gaudi.sh         | 22 +++++
 ... => 4_launch_and_validate_agent_openai.sh} |  0
 .../tests/4_launch_and_validate_agent_tgi.sh  | 60 ++++++++++++
 AgentQnA/tests/_test_agentqna_on_xeon.sh      |  2 +-
 AgentQnA/tests/test_agentqna_on_gaudi.sh      | 50 ++++++++++
 6 files changed, 224 insertions(+), 1 deletion(-)
 create mode 100644 AgentQnA/docker/tgi-gaudi/docker-compose-agent-tgi-gaudi.yaml
 create mode 100644 AgentQnA/docker/tgi-gaudi/launch_agent_service_tgi_gaudi.sh
 rename AgentQnA/tests/{4_launch_and_validate_agent.sh => 4_launch_and_validate_agent_openai.sh} (100%)
 create mode 100644 AgentQnA/tests/4_launch_and_validate_agent_tgi.sh
 create mode 100644 AgentQnA/tests/test_agentqna_on_gaudi.sh

diff --git a/AgentQnA/docker/tgi-gaudi/docker-compose-agent-tgi-gaudi.yaml b/AgentQnA/docker/tgi-gaudi/docker-compose-agent-tgi-gaudi.yaml
new file mode 100644
index 0000000000..fe5d0af217
--- /dev/null
+++ b/AgentQnA/docker/tgi-gaudi/docker-compose-agent-tgi-gaudi.yaml
@@ -0,0 +1,91 @@
+# Copyright (C) 2024 Intel Corporation
+# SPDX-License-Identifier: Apache-2.0
+
+services:
+  tgi-server:
+    image: ghcr.io/huggingface/tgi-gaudi:latest
+    container_name: tgi-server
+    ports:
+      - "8085:80"
+    volumes:
+      - ${HF_CACHE_DIR}:/data
+    environment:
+      no_proxy: ${no_proxy}
+      http_proxy: ${http_proxy}
+      https_proxy: ${https_proxy}
+      HF_TOKEN: ${HUGGINGFACEHUB_API_TOKEN}
+      HF_HUB_DISABLE_PROGRESS_BARS: 1
+      HF_HUB_ENABLE_HF_TRANSFER: 0
+      HABANA_VISIBLE_DEVICES: all
+      OMPI_MCA_btl_vader_single_copy_mechanism: none
+    runtime: habana
+    cap_add:
+      - SYS_NICE
+    ipc: host
+    command: --model-id ${LLM_MODEL_ID} --max-input-length 4096 --max-total-tokens 8192 --sharded true --num-shard 4
+  worker-docgrader-agent:
+    image: opea/comps-agent-langchain:latest
+    container_name: docgrader-agent-endpoint
+    depends_on:
+      - tgi-server
+    volumes:
+      - ${WORKDIR}/GenAIComps/comps/agent/langchain/:/home/user/comps/agent/langchain/
+      - ${TOOLSET_PATH}:/home/user/tools/
+    ports:
+      - "9095:9095"
+    ipc: host
+    environment:
+      ip_address: ${ip_address}
+      strategy: rag_agent
+      recursion_limit: ${recursion_limit_worker}
+      llm_engine: tgi
+      llm_endpoint_url: ${LLM_ENDPOINT_URL}
+      model: ${LLM_MODEL_ID}
+      temperature: ${temperature}
+      max_new_tokens: ${max_new_tokens}
+      streaming: false
+      tools: /home/user/tools/worker_agent_tools.yaml
+      require_human_feedback: false
+      RETRIEVAL_TOOL_URL: ${RETRIEVAL_TOOL_URL}
+      no_proxy: ${no_proxy}
+      http_proxy: ${http_proxy}
+      https_proxy: ${https_proxy}
+      LANGCHAIN_API_KEY: ${LANGCHAIN_API_KEY}
+      LANGCHAIN_TRACING_V2: ${LANGCHAIN_TRACING_V2}
+      LANGCHAIN_PROJECT: "opea-worker-agent-service"
+      port: 9095
+      
+
+  supervisor-react-agent:
+    image: opea/comps-agent-langchain:latest
+    container_name: react-agent-endpoint
+    depends_on:
+      - tgi-server
+      - worker-docgrader-agent
+    volumes:
+      - ${WORKDIR}/GenAIComps/comps/agent/langchain/:/home/user/comps/agent/langchain/
+      - ${TOOLSET_PATH}:/home/user/tools/
+    ports:
+      - "9090:9090"
+    ipc: host
+    environment:
+      ip_address: ${ip_address}
+      strategy: react_langgraph
+      recursion_limit: ${recursion_limit_supervisor}
+      llm_engine: tgi
+      llm_endpoint_url: ${LLM_ENDPOINT_URL}
+      model: ${LLM_MODEL_ID}
+      temperature: ${temperature}
+      max_new_tokens: ${max_new_tokens}
+      streaming: false
+      tools: /home/user/tools/supervisor_agent_tools.yaml
+      require_human_feedback: false
+      no_proxy: ${no_proxy}
+      http_proxy: ${http_proxy}
+      https_proxy: ${https_proxy}
+      LANGCHAIN_API_KEY: ${LANGCHAIN_API_KEY}
+      LANGCHAIN_TRACING_V2: ${LANGCHAIN_TRACING_V2}
+      LANGCHAIN_PROJECT: "opea-supervisor-agent-service"
+      CRAG_SERVER: $CRAG_SERVER
+      WORKER_AGENT_URL: $WORKER_AGENT_URL
+      port: 9090
diff --git a/AgentQnA/docker/tgi-gaudi/launch_agent_service_tgi_gaudi.sh b/AgentQnA/docker/tgi-gaudi/launch_agent_service_tgi_gaudi.sh
new file mode 100644
index 0000000000..8e71f76052
--- /dev/null
+++ b/AgentQnA/docker/tgi-gaudi/launch_agent_service_tgi_gaudi.sh
@@ -0,0 +1,22 @@
+# Copyright (C) 2024 Intel Corporation
+# SPDX-License-Identifier: Apache-2.0
+
+export ip_address=$(hostname -I | awk '{print $1}')
+
+# LLM related environment variables
+export HF_CACHE_DIR=${HF_CACHE_DIR}
+export HUGGINGFACEHUB_API_TOKEN=${HUGGINGFACEHUB_API_TOKEN}
+export LLM_MODEL_ID="meta-llama/Meta-Llama-3.1-70B-Instruct"
+export LLM_ENDPOINT_URL="http://${ip_address}:8085"
+export temperature=0
+export max_new_tokens=512
+
+# agent related environment variables
+export TOOLSET_PATH=$WORKDIR/GenAIExamples/AgentQnA/tools/
+export recursion_limit_worker=12
+export recursion_limit_supervisor=10
+export WORKER_AGENT_URL="http://${ip_address}:9095/v1/chat/completions"
+export RETRIEVAL_TOOL_URL="http://${ip_address}:8889/v1/retrievaltool"
+export CRAG_SERVER=http://${ip_address}:8080
+
+docker compose -f docker-compose-agent-tgi-gaudi.yaml up -d
\ No newline at end of file
diff --git a/AgentQnA/tests/4_launch_and_validate_agent.sh b/AgentQnA/tests/4_launch_and_validate_agent_openai.sh
similarity index 100%
rename from AgentQnA/tests/4_launch_and_validate_agent.sh
rename to AgentQnA/tests/4_launch_and_validate_agent_openai.sh
diff --git a/AgentQnA/tests/4_launch_and_validate_agent_tgi.sh b/AgentQnA/tests/4_launch_and_validate_agent_tgi.sh
new file mode 100644
index 0000000000..5cce76e960
--- /dev/null
+++ b/AgentQnA/tests/4_launch_and_validate_agent_tgi.sh
@@ -0,0 +1,60 @@
+#!/bin/bash
+# Copyright (C) 2024 Intel Corporation
+# SPDX-License-Identifier: Apache-2.0
+
+set -e
+echo "OPENAI_API_KEY=${OPENAI_API_KEY}"
+
+WORKPATH=$(dirname "$PWD")
+export WORKDIR=$WORKPATH/../../
+echo "WORKDIR=${WORKDIR}"
+export ip_address=$(hostname -I | awk '{print $1}')
+export TOOLSET_PATH=$WORKDIR/GenAIExamples/AgentQnA/tools/
+
+function start_agent_and_api_server() {
+    echo "Starting CRAG server"
+    docker run -d -p=8080:8000 docker.io/aicrowd/kdd-cup-24-crag-mock-api:v0
+
+    echo "Starting Agent services"
+    cd $WORKDIR/GenAIExamples/AgentQnA/docker/tgi-gaudi
+    bash launch_agent_service_tgi_gaudi.sh
+}
+
+function validate() {
+    local CONTENT="$1"
+    local EXPECTED_RESULT="$2"
+    local SERVICE_NAME="$3"
+
+    if echo "$CONTENT" | grep -q "$EXPECTED_RESULT"; then
+        echo "[ $SERVICE_NAME ] Content is as expected: $CONTENT"
+        echo 0
+    else
+        echo "[ $SERVICE_NAME ] Content does not match the expected result: $CONTENT"
+        echo 1
+    fi
+}
+
+function validate_agent_service() {
+    echo "----------------Test agent ----------------"
+    local CONTENT=$(http_proxy="" curl http://${ip_address}:9090/v1/chat/completions -X POST -H "Content-Type: application/json" -d '{
+     "query": "Tell me about Michael Jackson song thriller"
+    }')
+    local EXIT_CODE=$(validate "$CONTENT" "Thriller" "react-agent-endpoint")
+    docker logs react-agent-endpoint
+    if [ "$EXIT_CODE" == "1" ]; then
+        exit 1
+    fi
+
+}
+
+function main() {
+    echo "==================== Start agent ===================="
+    start_agent_and_api_server
+    echo "==================== Agent started ===================="
+
+    echo "==================== Validate agent service ===================="
+    validate_agent_service
+    echo "==================== Agent service validated ===================="
+}
+
+main
\ No newline at end of file
diff --git a/AgentQnA/tests/_test_agentqna_on_xeon.sh b/AgentQnA/tests/_test_agentqna_on_xeon.sh
index bb8498850a..a1c556499b 100644
--- a/AgentQnA/tests/_test_agentqna_on_xeon.sh
+++ b/AgentQnA/tests/_test_agentqna_on_xeon.sh
@@ -36,7 +36,7 @@ bash 3_ingest_data_and_validate_retrieval.sh
 echo "=================== #3 Data ingestion and validation completed===================="
 
 echo "=================== #4 Start agent and API server===================="
-bash 4_launch_and_validate_agent.sh
+bash 4_launch_and_validate_agent_openai.sh
 echo "=================== #4 Agent test passed ===================="
 
 echo "=================== #5 Stop agent and API server===================="
diff --git a/AgentQnA/tests/test_agentqna_on_gaudi.sh b/AgentQnA/tests/test_agentqna_on_gaudi.sh
new file mode 100644
index 0000000000..d47471ede8
--- /dev/null
+++ b/AgentQnA/tests/test_agentqna_on_gaudi.sh
@@ -0,0 +1,50 @@
+#!/bin/bash
+# Copyright (C) 2024 Intel Corporation
+# SPDX-License-Identifier: Apache-2.0
+
+set -e
+
+echo "OPENAI_API_KEY=${OPENAI_API_KEY}"
+WORKPATH=$(dirname "$PWD")
+export WORKDIR=$WORKPATH/../../
+echo "WORKDIR=${WORKDIR}"
+export ip_address=$(hostname -I | awk '{print $1}')
+export TOOLSET_PATH=$WORKDIR/GenAIExamples/AgentQnA/tools/
+
+function stop_agent_and_api_server() {
+    echo "Stopping CRAG server"
+    docker stop $(docker ps -q --filter ancestor=docker.io/aicrowd/kdd-cup-24-crag-mock-api:v0)
+    echo "Stopping Agent services"
+    docker stop $(docker ps -q --filter ancestor=opea/comps-agent-langchain:latest)
+}
+
+function stop_retrieval_tool() {
+    echo "Stopping Retrieval tool"
+    docker compose -f $WORKDIR/GenAIExamples/AgentQnA/retrieval_tool/docker/docker-compose-retrieval-tool.yaml down
+}
+
+echo "=================== #1 Building docker images===================="
+bash 1_build_images.sh
+echo "=================== #1 Building docker images completed===================="
+
+echo "=================== #2 Start retrieval tool===================="
+bash 2_start_retrieval_tool.sh
+echo "=================== #2 Retrieval tool started===================="
+
+echo "=================== #3 Ingest data and validate retrieval===================="
+bash 3_ingest_data_and_validate_retrieval.sh
+echo "=================== #3 Data ingestion and validation completed===================="
+
+echo "=================== #4 Start agent and API server===================="
+bash 4_launch_and_validate_agent_tgi.sh
+echo "=================== #4 Agent test passed ===================="
+
+echo "=================== #5 Stop agent and API server===================="
+stop_agent_and_api_server
+echo "=================== #5 Agent and API server stopped===================="
+
+echo "=================== #6 Stop retrieval tool===================="
+stop_retrieval_tool
+echo "=================== #6 Retrieval tool stopped===================="
+
+echo "ALL DONE!"

From 047ef96e02f07241e640e87e737844728f906b3e Mon Sep 17 00:00:00 2001
From: minmin-intel <minmin.hou@intel.com>
Date: Wed, 28 Aug 2024 22:46:52 +0000
Subject: [PATCH 18/39] update agent docker yaml for serving llama3.1-70b and
 update test scripts

Signed-off-by: minmin-intel <minmin.hou@intel.com>
---
 .../docker-compose-agent-tgi-gaudi.yaml       |  5 ++++-
 .../launch_agent_service_tgi_gaudi.sh         |  2 +-
 AgentQnA/retrieval_tool/run_ingest_data.sh    |  2 +-
 .../3_ingest_data_and_validate_retrieval.sh   |  2 ++
 .../tests/4_launch_and_validate_agent_tgi.sh  | 20 ++++++++++++++++++-
 AgentQnA/tests/test_agentqna_on_gaudi.sh      |  3 +--
 6 files changed, 28 insertions(+), 6 deletions(-)

diff --git a/AgentQnA/docker/tgi-gaudi/docker-compose-agent-tgi-gaudi.yaml b/AgentQnA/docker/tgi-gaudi/docker-compose-agent-tgi-gaudi.yaml
index fe5d0af217..301c60dafe 100644
--- a/AgentQnA/docker/tgi-gaudi/docker-compose-agent-tgi-gaudi.yaml
+++ b/AgentQnA/docker/tgi-gaudi/docker-compose-agent-tgi-gaudi.yaml
@@ -16,8 +16,9 @@ services:
       HF_TOKEN: ${HUGGINGFACEHUB_API_TOKEN}
       HF_HUB_DISABLE_PROGRESS_BARS: 1
       HF_HUB_ENABLE_HF_TRANSFER: 0
-      HABANA_VISIBLE_DEVICES: all
+      HABANA_VISIBLE_DEVICES: all #0,1,4,5
       OMPI_MCA_btl_vader_single_copy_mechanism: none
+      PT_HPU_ENABLE_LAZY_COLLECTIVES: true
     runtime: habana
     cap_add:
       - SYS_NICE
@@ -39,6 +40,7 @@ services:
       strategy: rag_agent
       recursion_limit: ${recursion_limit_worker}
       llm_engine: tgi
+      HUGGINGFACEHUB_API_TOKEN: ${HUGGINGFACEHUB_API_TOKEN}
       llm_endpoint_url: ${LLM_ENDPOINT_URL}
       model: ${LLM_MODEL_ID}
       temperature: ${temperature}
@@ -73,6 +75,7 @@ services:
       strategy: react_langgraph
       recursion_limit: ${recursion_limit_supervisor}
       llm_engine: tgi
+      HUGGINGFACEHUB_API_TOKEN: ${HUGGINGFACEHUB_API_TOKEN}
       llm_endpoint_url: ${LLM_ENDPOINT_URL}
       model: ${LLM_MODEL_ID}
       temperature: ${temperature}
diff --git a/AgentQnA/docker/tgi-gaudi/launch_agent_service_tgi_gaudi.sh b/AgentQnA/docker/tgi-gaudi/launch_agent_service_tgi_gaudi.sh
index 8e71f76052..8a1acc59b2 100644
--- a/AgentQnA/docker/tgi-gaudi/launch_agent_service_tgi_gaudi.sh
+++ b/AgentQnA/docker/tgi-gaudi/launch_agent_service_tgi_gaudi.sh
@@ -8,7 +8,7 @@ export HF_CACHE_DIR=${HF_CACHE_DIR}
 export HUGGINGFACEHUB_API_TOKEN=${HUGGINGFACEHUB_API_TOKEN}
 export LLM_MODEL_ID="meta-llama/Meta-Llama-3.1-70B-Instruct"
 export LLM_ENDPOINT_URL="http://${ip_address}:8085"
-export temperature=0
+export temperature=0.01
 export max_new_tokens=512
 
 # agent related environment variables
diff --git a/AgentQnA/retrieval_tool/run_ingest_data.sh b/AgentQnA/retrieval_tool/run_ingest_data.sh
index 87da727e72..cf86cdbe2d 100644
--- a/AgentQnA/retrieval_tool/run_ingest_data.sh
+++ b/AgentQnA/retrieval_tool/run_ingest_data.sh
@@ -1,4 +1,4 @@
 FILEDIR=${WORKDIR}/GenAIExamples/AgentQnA/example_data/
 FILENAME=test_docs_music.jsonl
 
-python index_data.py --filedir ${FILEDIR} --filename ${FILENAME}
\ No newline at end of file
+python3 index_data.py --filedir ${FILEDIR} --filename ${FILENAME} --host_ip $host_ip
\ No newline at end of file
diff --git a/AgentQnA/tests/3_ingest_data_and_validate_retrieval.sh b/AgentQnA/tests/3_ingest_data_and_validate_retrieval.sh
index ef2d05af0d..6525bfaf65 100644
--- a/AgentQnA/tests/3_ingest_data_and_validate_retrieval.sh
+++ b/AgentQnA/tests/3_ingest_data_and_validate_retrieval.sh
@@ -8,6 +8,8 @@ WORKPATH=$(dirname "$PWD")
 export WORKDIR=$WORKPATH/../../
 echo "WORKDIR=${WORKDIR}"
 export ip_address=$(hostname -I | awk '{print $1}')
+export host_ip=$ip_address
+echo "ip_address=${ip_address}"
 
 
 function validate() {
diff --git a/AgentQnA/tests/4_launch_and_validate_agent_tgi.sh b/AgentQnA/tests/4_launch_and_validate_agent_tgi.sh
index 5cce76e960..0c9eb17cfd 100644
--- a/AgentQnA/tests/4_launch_and_validate_agent_tgi.sh
+++ b/AgentQnA/tests/4_launch_and_validate_agent_tgi.sh
@@ -3,13 +3,20 @@
 # SPDX-License-Identifier: Apache-2.0
 
 set -e
-echo "OPENAI_API_KEY=${OPENAI_API_KEY}"
 
 WORKPATH=$(dirname "$PWD")
 export WORKDIR=$WORKPATH/../../
 echo "WORKDIR=${WORKDIR}"
 export ip_address=$(hostname -I | awk '{print $1}')
 export TOOLSET_PATH=$WORKDIR/GenAIExamples/AgentQnA/tools/
+export HUGGINGFACEHUB_API_TOKEN=${HUGGINGFACEHUB_API_TOKEN}
+
+export HF_CACHE_DIR=$WORKDIR/hf_cache
+if [ ! -d "$HF_CACHE_DIR" ]; then
+    mkdir -p "$HF_CACHE_DIR"
+fi
+ls $HF_CACHE_DIR
+
 
 function start_agent_and_api_server() {
     echo "Starting CRAG server"
@@ -36,6 +43,15 @@ function validate() {
 
 function validate_agent_service() {
     echo "----------------Test agent ----------------"
+    local CONTENT=$(http_proxy="" curl http://${ip_address}:9095/v1/chat/completions -X POST -H "Content-Type: application/json" -d '{
+     "query": "Tell me about Michael Jackson song thriller"
+    }')
+    local EXIT_CODE=$(validate "$CONTENT" "Thriller" "react-agent-endpoint")
+    docker logs docgrader-agent-endpoint
+    if [ "$EXIT_CODE" == "1" ]; then
+        exit 1
+    fi
+
     local CONTENT=$(http_proxy="" curl http://${ip_address}:9090/v1/chat/completions -X POST -H "Content-Type: application/json" -d '{
      "query": "Tell me about Michael Jackson song thriller"
     }')
@@ -50,6 +66,8 @@ function validate_agent_service() {
 function main() {
     echo "==================== Start agent ===================="
     start_agent_and_api_server
+    echo "Waiting for LLM endpoint to be ready"
+    sleep 300
     echo "==================== Agent started ===================="
 
     echo "==================== Validate agent service ===================="
diff --git a/AgentQnA/tests/test_agentqna_on_gaudi.sh b/AgentQnA/tests/test_agentqna_on_gaudi.sh
index d47471ede8..82fadf72a1 100644
--- a/AgentQnA/tests/test_agentqna_on_gaudi.sh
+++ b/AgentQnA/tests/test_agentqna_on_gaudi.sh
@@ -4,12 +4,11 @@
 
 set -e
 
-echo "OPENAI_API_KEY=${OPENAI_API_KEY}"
 WORKPATH=$(dirname "$PWD")
 export WORKDIR=$WORKPATH/../../
 echo "WORKDIR=${WORKDIR}"
 export ip_address=$(hostname -I | awk '{print $1}')
-export TOOLSET_PATH=$WORKDIR/GenAIExamples/AgentQnA/tools/
+export HUGGINGFACEHUB_API_TOKEN=${HUGGINGFACEHUB_API_TOKEN}
 
 function stop_agent_and_api_server() {
     echo "Stopping CRAG server"

From 3c7da4cb1f304fcddce1e9c16ceecc1b941908c1 Mon Sep 17 00:00:00 2001
From: "pre-commit-ci[bot]"
 <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Date: Wed, 28 Aug 2024 22:49:37 +0000
Subject: [PATCH 19/39] [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci
---
 .../openai/docker-compose-agent-openai.yaml   |  2 +-
 .../docker-compose-agent-tgi-gaudi.yaml       |  2 +-
 .../launch_agent_service_tgi_gaudi.sh         |  2 +-
 AgentQnA/example_data/test_docs_music.jsonl   |  4 +-
 AgentQnA/retrieval_tool/README.md             | 15 +++-
 .../retrieval_tool/docker/build_images.sh     |  5 +-
 .../docker/docker-compose-retrieval-tool.yaml |  8 +-
 .../docker/launch_retrieval_tool.sh           |  5 +-
 .../retrieval_tool/docker/retrieval_tool.py   |  5 +-
 AgentQnA/retrieval_tool/index_data.py         | 42 ++++++----
 AgentQnA/retrieval_tool/run_ingest_data.sh    |  5 +-
 AgentQnA/tests/2_start_retrieval_tool.sh      |  2 +-
 .../3_ingest_data_and_validate_retrieval.sh   |  4 +-
 .../4_launch_and_validate_agent_openai.sh     |  2 +-
 .../tests/4_launch_and_validate_agent_tgi.sh  |  2 +-
 AgentQnA/tests/run_test_agent_service.sh      |  3 +
 AgentQnA/tests/src/commons.py                 |  5 +-
 AgentQnA/tests/src/test_agent_service.py      | 84 ++++++++++---------
 AgentQnA/tools/worker_agent_tools.py          |  9 +-
 AgentQnA/tools/worker_agent_tools.yaml        |  1 -
 20 files changed, 128 insertions(+), 79 deletions(-)

diff --git a/AgentQnA/docker/openai/docker-compose-agent-openai.yaml b/AgentQnA/docker/openai/docker-compose-agent-openai.yaml
index f88da8e794..5319952d1f 100644
--- a/AgentQnA/docker/openai/docker-compose-agent-openai.yaml
+++ b/AgentQnA/docker/openai/docker-compose-agent-openai.yaml
@@ -31,7 +31,7 @@ services:
       LANGCHAIN_TRACING_V2: ${LANGCHAIN_TRACING_V2}
       LANGCHAIN_PROJECT: "opea-worker-agent-service"
       port: 9095
-      
+
 
   supervisor-react-agent:
     image: opea/comps-agent-langchain:latest
diff --git a/AgentQnA/docker/tgi-gaudi/docker-compose-agent-tgi-gaudi.yaml b/AgentQnA/docker/tgi-gaudi/docker-compose-agent-tgi-gaudi.yaml
index 301c60dafe..2b475e5023 100644
--- a/AgentQnA/docker/tgi-gaudi/docker-compose-agent-tgi-gaudi.yaml
+++ b/AgentQnA/docker/tgi-gaudi/docker-compose-agent-tgi-gaudi.yaml
@@ -56,7 +56,7 @@ services:
       LANGCHAIN_TRACING_V2: ${LANGCHAIN_TRACING_V2}
       LANGCHAIN_PROJECT: "opea-worker-agent-service"
       port: 9095
-      
+
 
   supervisor-react-agent:
     image: opea/comps-agent-langchain:latest
diff --git a/AgentQnA/docker/tgi-gaudi/launch_agent_service_tgi_gaudi.sh b/AgentQnA/docker/tgi-gaudi/launch_agent_service_tgi_gaudi.sh
index 8a1acc59b2..22284eda56 100644
--- a/AgentQnA/docker/tgi-gaudi/launch_agent_service_tgi_gaudi.sh
+++ b/AgentQnA/docker/tgi-gaudi/launch_agent_service_tgi_gaudi.sh
@@ -19,4 +19,4 @@ export WORKER_AGENT_URL="http://${ip_address}:9095/v1/chat/completions"
 export RETRIEVAL_TOOL_URL="http://${ip_address}:8889/v1/retrievaltool"
 export CRAG_SERVER=http://${ip_address}:8080
 
-docker compose -f docker-compose-agent-tgi-gaudi.yaml up -d
\ No newline at end of file
+docker compose -f docker-compose-agent-tgi-gaudi.yaml up -d
diff --git a/AgentQnA/example_data/test_docs_music.jsonl b/AgentQnA/example_data/test_docs_music.jsonl
index b1de4b702f..2a20895152 100644
--- a/AgentQnA/example_data/test_docs_music.jsonl
+++ b/AgentQnA/example_data/test_docs_music.jsonl
@@ -17,11 +17,11 @@
 {"query": "who sang the hit song \"thriller\"?", "domain": "music", "doc": "^ Pareles, Jon (September 3, 1987). \"Critic's Notebook; How Good Is Jackson's 'Bad'?\". The New York Times. Retrieved January 25, 2010.\n^ Powers, Ann (February 15, 2008). \"Nine reasons why Jackson masterpiece remains a 'Thriller'\". SouthCoastToday.com. Dow Jones Local Media Group. Retrieved February 6, 2010.\n^ Comstock, Miriam Marcus and Courtney. \"Thriller Chiller For Jackson\". Forbes. Retrieved November 4, 2019.\n^ Kent, David (2003). Australian Chart Book 1970\u20131992. Australian Chart Book. ISBN\u00a00-646-11917-6.\n^ \"Michael Jackson \u2013 Thriller\" (in Dutch). Ultratop 50.\nRetrieved December 14, 2021.\n^ \"Top Singles \u2013 Volume 40, No. 1, March 10, 1984\". RPM. Archived from the original on October 17, 2012. Retrieved August 3, 2010.\n^ a b Pennanen, Timo (2021). \"Michael Jackson\". Sis\u00e4lt\u00e4\u00e4 hitin - 2. laitos Levyt ja esitt\u00e4j\u00e4t Suomen musiikkilistoilla 1.1.1960\u201330.6.2021 (PDF). Helsinki: Kustannusosakeyhti\u00f6 Otava. p.\u00a0113. Retrieved May 29, 2022.\n^ a b c \"Search Results: Thriller\". IrishCharts.ie. Irish Recorded Music Association. Retrieved January 25, 2010.\n^\n\"Nederlandse Top 40 \u2013 week 2, 1984\" (in Dutch). Dutch Top 40.\n^ a b c \"Michael Jackson \u2013 Thriller\" (in Dutch). Single Top 100.\n^ \"Michael Jackson \u2013 Thriller\". Top 40 Singles.\n^ \"Top 3 in Europe\" (PDF). Music & Media. May 14, 1984. p.\u00a012. Retrieved October 29, 2021.\n^ \"SA Charts 1965\u2013March 1989\". Retrieved September 5, 2018.\n^ Salaverri, Fernando (September 2005). S\u00f3lo \u00e9xitos: a\u00f1o a a\u00f1o, 1959\u20132002 (in Spanish) (1st\u00a0ed.). Spain: Fundaci\u00f3n Autor-SGAE. ISBN\u00a084-8048-639-2.\n^ Whitburn, Joel (2014). Cash Box Pop Hits 1952-1996. Sheridan Books, Inc. ISBN\u00a0978-0-89820-209-0.\n^ \"Michael Jackson Chart History (Hot 100)\". Billboard. September 9, 2021. Retrieved September 9, 2021.\n^ a b \"Allmusic (Thriller > Charts & Awards > Billboard Singles)\". Allmusic.com. Rovi Corporation. Retrieved January 23, 2010.\n^ Whitburn, Joel (1993). Top Adult Contemporary: 1961\u20131993. Record Research. p.\u00a0118.\n^ \"Michael Jackson\"."}
 {"query": "who sang the hit song \"thriller\"?", "domain": "music", "doc": "^ \"Michael Jackson Chart History (Hot 100)\". Billboard. September 9, 2021. Retrieved September 9, 2021.\n^ a b \"Allmusic (Thriller > Charts & Awards > Billboard Singles)\". Allmusic.com. Rovi Corporation. Retrieved January 23, 2010.\n^ Whitburn, Joel (1993). Top Adult Contemporary: 1961\u20131993. Record Research. p.\u00a0118.\n^ \"Michael Jackson\".\n^ \"Offiziellecharts.de \u2013 Michael Jackson \u2013 Thriller\" (in German). GfK Entertainment charts.\nRetrieved March 18, 2019.\n^ a b c d e f g \"Michael Jackson \u2013 Thriller\" (in French). Les classement single.\n^ a b \"Michael Jackson \u2013 Thriller\". Top Digital Download.\n^ a b c d e f \"Michael Jackson \u2013 Thriller\" Canciones Top 50.\n^ a b \"Michael Jackson \u2013 Thriller\" (in German). \u00d63 Austria Top 40.\n^ a b \"Michael Jackson \u2013 Thriller\". VG-lista.\n^ a b c \"Michael Jackson \u2013 Thriller\". Swiss Singles Chart.\n^ \"Michael Jackson \u2013 Thriller\". ARIA Top 50 Singles.\n^ \"30 Back Catalogue Singles \u2013 July 18, 2009\". UltraTop.be. Hung Medien. Retrieved January 24, 2010.\n^ \"30 Back Catalogue Singles \u2013 July 4, 2009\". UltraTop.be. Hung Medien. Retrieved January 24, 2010.\n^ \"Michael Jackson Album & Song Chart History\". Billboard.com. Nielsen Business Media. Retrieved October 29, 2011.\n^ \"Michael Jackson: Thriller\" (in Finnish). Musiikkituottajat.\n^ \"Download Single Top 50 \u2013 04/07/2009\". Lescharts.com. Hung Medien. Retrieved January 23, 2010.\n^ \"Michael Jackson \u2013 Thriller\". Singles Top 100.\n^ \"Michael Jackson Chart History (Digital Song Sales)\". Billboard.\n^ \"The Hot 100, Week of November 16, 2013\". Billboard. Prometheus Global Media. Retrieved November 12, 2015.\n^ \"The Hot 100, Week of November 15, 2014\". Billboard. Prometheus Global Media.\n^ \"The Hot 100, Week of November 21, 2015\". Billboard. Prometheus Global Media. Retrieved November 12, 2015.\n^ \"Michael Jackson Chart History (Canadian Hot 100)\". Billboard.\nRetrieved November 6, 2018.\n^ Zellner, Xander. \"Michael Jackson's 'Thriller' Returns to Hot 100, Thanks to Halloween Gains\". Billboard. Retrieved November 6, 2018."}
 {"query": "who sang the hit song \"thriller\"?", "domain": "music", "doc": "^ \"The Hot 100, Week of November 21, 2015\". Billboard. Prometheus Global Media. Retrieved November 12, 2015.\n^ \"Michael Jackson Chart History (Canadian Hot 100)\". Billboard.\nRetrieved November 6, 2018.\n^ Zellner, Xander. \"Michael Jackson's 'Thriller' Returns to Hot 100, Thanks to Halloween Gains\". Billboard. Retrieved November 6, 2018.\n^ \"The Hot 100, Week of November 10, 2018\". Billboard. Retrieved September 9, 2021.\n^ \"The Hot 100, Week of November 9, 2019\". Billboard. Retrieved March 20, 2021.\n^ \"The Global 200, Week of November 14, 2020\". Billboard. Retrieved November 8, 2023.\n^ \"The Hot 100, Week of November 14, 2020\". Billboard. Retrieved November 14, 2020.\n^ \"Canadian Hot 100, Week of November 13, 2021\". Billboard. Retrieved November 23, 2021.\n^ \"Michael Jackson Chart History (Global 200)\". Billboard.\nRetrieved November 9, 2021.\n^ \"Official Singles Chart Top 100\". Official Charts Company.\nRetrieved November 8, 2023.\n^ \"Official Hip Hop and R&B Singles Chart Top 40\". Official Charts Company.\nRetrieved November 5, 2021.\n^ \"Michael Jackson's 'Thriller' Leads Halloween Treats on Billboard Hot 100\". Billboard. Retrieved November 8, 2021.\n^ \"The Hot 100, Week of November 13, 2021\". Billboard. Retrieved November 5, 2022.\n^ \"Digital Song Sales Chart, Week of November 13, 2021\". Billboard. Retrieved November 11, 2021.\n^ \"Canadian Hot 100, Week of November 12, 2022\". Billboard. Retrieved November 8, 2022.\n^ \"The Global 200, Week of November 12, 2022\". Billboard. Retrieved November 8, 2022.\n^ \"The Hot 100, Week of November 12, 2022\". Billboard. Retrieved November 8, 2022.\n^ \"Canadian Hot 100, Week of November 11, 2023\". Billboard. Retrieved November 8, 2023.\n^ \"The Global 200, Week of November 11, 2023\". Billboard. Retrieved November 8, 2023.\n^ \"Official Singles Chart Top 100\". Official Charts Company.\nRetrieved November 8, 2023.\n^ \"The Hot 100, Week of November 11, 2023\". Billboard. Retrieved November 8, 2023."}
-{"query": "who sang the hit song \"thriller\"?", "domain": "music", "doc": "^ \"Canadian Hot 100, Week of November 11, 2023\". Billboard. Retrieved November 8, 2023.\n^ \"The Global 200, Week of November 11, 2023\". Billboard. Retrieved November 8, 2023.\n^ \"Official Singles Chart Top 100\". Official Charts Company.\nRetrieved November 8, 2023.\n^ \"The Hot 100, Week of November 11, 2023\". Billboard. Retrieved November 8, 2023.\n^ \"Kent Music Report No 548 \u2013 31 December 1984 > National Top 100 Singles for 1984\". Kent Music Report. Retrieved January 23, 2023 \u2013 via Imgur.com.\n^ \"Jaaroverzichten 1984\". Ultratop. Retrieved December 14, 2021.\n^ \"\u00c5rslista Singlar \u2013 \u00c5r 2009\" (in Swedish). Sverigetopplistan. Retrieved March 29, 2020.\n^ \"Schweizer Jahreshitparade 2009 \u2013 hitparade.ch\". Hung Medien. Retrieved March 29, 2020.\n^ \"Charts Plus Year end 2009\" (PDF). Charts Plus. Retrieved May 16, 2020.\n^ \"ARIA Charts \u2013 Accreditations \u2013 2021 Singles\" (PDF). Australian Recording Industry Association.\n^ \"Danish\nsingle\ncertifications \u2013 Michael Jackson \u2013 Thriller\". IFPI Danmark. Retrieved July 2, 2023.\n^ \"French\nsingle\ncertifications \u2013 Michael Jackson \u2013 Thriller\" (in French). InfoDisc. Retrieved November 28, 2022. Select MICHAEL JACKSON and click OK.\n^ \"Gold-/Platin-Datenbank (Michael Jackson;\u00a0'Thriller')\" (in German). Bundesverband Musikindustrie. Retrieved February 18, 2023.\n^ \"Italian\nsingle\ncertifications \u2013 Michael Jackson \u2013 Thriller\" (in Italian). Federazione Industria Musicale Italiana. Select \"2014\" in the \"Anno\" drop-down menu. Select \"Thriller\" in the \"Filtra\" field. Select \"Singoli\" under \"Sezione\".\n^ \"Japanese\nringtone\ncertifications \u2013 Michael Jackson \u2013 Thriller\" (in Japanese). Recording Industry Association of Japan. Retrieved December 30, 2020. Select 2009\u5e7411\u6708 on the drop-down menu\n^ \"Certificaciones\" (in Spanish). Asociaci\u00f3n Mexicana de Productores de Fonogramas y Videogramas. Retrieved November 28, 2022. Type Michael Jackson in the box under the ARTISTA column heading\u00a0and Thriller in the box under the T\u00cdTULO column heading.\n^ \"Spanish\nsingle"}
+{"query": "who sang the hit song \"thriller\"?", "domain": "music", "doc": "^ \"Canadian Hot 100, Week of November 11, 2023\". Billboard. Retrieved November 8, 2023.\n^ \"The Global 200, Week of November 11, 2023\". Billboard. Retrieved November 8, 2023.\n^ \"Official Singles Chart Top 100\". Official Charts Company.\nRetrieved November 8, 2023.\n^ \"The Hot 100, Week of November 11, 2023\". Billboard. Retrieved November 8, 2023.\n^ \"Kent Music Report No 548 \u2013 31 December 1984 > National Top 100 Singles for 1984\". Kent Music Report. Retrieved January 23, 2023 \u2013 via Imgur.com.\n^ \"Jaaroverzichten 1984\". Ultratop. Retrieved December 14, 2021.\n^ \"\u00c5rslista Singular \u2013 \u00c5r 2009\" (in Swedish). Sverigetopplistan. Retrieved March 29, 2020.\n^ \"Schweizer Jahreshitparade 2009 \u2013 hitparade.ch\". Hung Medien. Retrieved March 29, 2020.\n^ \"Charts Plus Year end 2009\" (PDF). Charts Plus. Retrieved May 16, 2020.\n^ \"ARIA Charts \u2013 Accreditations \u2013 2021 Singles\" (PDF). Australian Recording Industry Association.\n^ \"Danish\nsingle\ncertifications \u2013 Michael Jackson \u2013 Thriller\". IFPI Danmark. Retrieved July 2, 2023.\n^ \"French\nsingle\ncertifications \u2013 Michael Jackson \u2013 Thriller\" (in French). InfoDisc. Retrieved November 28, 2022. Select MICHAEL JACKSON and click OK.\n^ \"Gold-/Platin-Datenbank (Michael Jackson;\u00a0'Thriller')\" (in German). Bundesverband Musikindustrie. Retrieved February 18, 2023.\n^ \"Italian\nsingle\ncertifications \u2013 Michael Jackson \u2013 Thriller\" (in Italian). Federazione Industria Musicale Italiana. Select \"2014\" in the \"Anno\" drop-down menu. Select \"Thriller\" in the \"Filtra\" field. Select \"Singoli\" under \"Sezione\".\n^ \"Japanese\nringtone\ncertifications \u2013 Michael Jackson \u2013 Thriller\" (in Japanese). Recording Industry Association of Japan. Retrieved December 30, 2020. Select 2009\u5e7411\u6708 on the drop-down menu\n^ \"Certificaciones\" (in Spanish). Asociaci\u00f3n Mexicana de Productores de Fonogramas y Videogramas. Retrieved November 28, 2022. Type Michael Jackson in the box under the ARTISTA column heading\u00a0and Thriller in the box under the T\u00cdTULO column heading.\n^ \"Spanish\nsingle"}
 {"query": "who sang the hit song \"thriller\"?", "domain": "music", "doc": "^ \"Certificaciones\" (in Spanish). Asociaci\u00f3n Mexicana de Productores de Fonogramas y Videogramas. Retrieved November 28, 2022. Type Michael Jackson in the box under the ARTISTA column heading\u00a0and Thriller in the box under the T\u00cdTULO column heading.\n^ \"Spanish\nsingle\ncertifications \u2013 Michael Jackson \u2013 Thriller\". El portal de M\u00fasica. Productores de M\u00fasica de Espa\u00f1a.\n^ \"British\nsingle\ncertifications \u2013 Michael Jackson \u2013 Thriller\". British Phonographic Industry. Retrieved March 17, 2023.\n^ \"British\nsingle\ncertifications \u2013 Michael Jackson \u2013 Thriller\". British Phonographic Industry. Retrieved March 17, 2023.\n^ \"American\nsingle\ncertifications \u2013 Michael Jackson \u2013 Thriller\". Recording Industry Association of America. Retrieved August 29, 2022.\n^ \"American\nringtone\ncertifications \u2013 Michael Jackson \u2013 Thriller\". Recording Industry Association of America.\nBibliography\nBrooks, Darren (2002). Michael Jackson: An Exceptional Journey. Chrome Dreams. ISBN\u00a01-84240-178-5.\nGeorge, Nelson (2004). Michael Jackson: The Ultimate Collection (booklet). Sony BMG.\nGrant, Adrian (2009). Michael Jackson: The Visual Documentary. Omnibus Press. ISBN\u00a0978-1-84938-261-8.\nJones, Jel (2005). Michael Jackson, the King of Pop: The Big Picture: the Music! the Man! the Legend! the Interviews!. Amber Books Publishing. ISBN\u00a00-9749779-0-X.\nTaraborrelli, J. Randy (2004). The Magic and the Madness. Terra Alta, WV: Headline. ISBN\u00a00-330-42005-4.\nHalstead, Craig (2003). Michael Jackson The Solo Years. On-Line Ltd. ISBN\u00a0978-0-7552-0091-7.\nvteMichael Jackson: ThrillerSide one\n\"Wanna Be Startin' Somethin'\"\n\"Baby Be Mine\"\n\"The Girl Is Mine\"\n\"Thriller\"\nSide two\n\"Beat It\"\n\"Billie Jean\"\n\"Human Nature\"\n\"P.Y.T. (Pretty Young Thing)\"\n\"The Lady in My Life\"\nRelated articles\nE.T. the Extra-Terrestrial (audiobook)\nFarewell My Summer Love\nVictory\nVictory Tour\nMichael Jackson's Thriller\nThriller jacket\nThriller 25\nThriller 40\nThriller 40 (film)\nThrill the World\nThriller viral video\nDonga\nThriller \u2013 Live"}
 {"query": "who sang the hit song \"thriller\"?", "domain": "music", "doc": "\"Baby Be Mine\"\n\"The Girl Is Mine\"\n\"Thriller\"\nSide two\n\"Beat It\"\n\"Billie Jean\"\n\"Human Nature\"\n\"P.Y.T. (Pretty Young Thing)\"\n\"The Lady in My Life\"\nRelated articles\nE.T. the Extra-Terrestrial (audiobook)\nFarewell My Summer Love\nVictory\nVictory Tour\nMichael Jackson's Thriller\nThriller jacket\nThriller 25\nThriller 40\nThriller 40 (film)\nThrill the World\nThriller viral video\nDonga\nThriller \u2013 Live\nMichael Jackson albums discography\nvteMichael Jackson songs\nSingles\nSongs\nUnreleased songs\n1970s\n\"Got to Be There\"\n\"Ain't No Sunshine\"\n\"I Wanna Be Where You Are\"\n\"Rockin' Robin\"\n\"Love Is Here and Now You're Gone\"\n\"You've Got a Friend\"\n\"Ben\"\n\"Everybody's Somebody's Fool\"\n\"My Girl\"\n\"Shoo-Be-Doo-Be-Doo-Da-Day\"\n\"We've Got a Good Thing Going\"\n\"With a Child's Heart\"\n\"Morning Glow\"\n\"All the Things You Are\"\n\"Happy\"\n\"Too Young\"\n\"Music and Me\"\n\"We're Almost There\"\n\"Just a Little Bit of You\"\n\"You Can't Win\"\n\"Don't Stop 'Til You Get Enough\"\n\"Rock with You\"\n\"Working Day and Night\"\n\"It's the Falling in Love\"\n1980s\n\"Off the Wall\"\n\"Girlfriend\"\n\"She's Out of My Life\"\n\"One Day in Your Life\"\n\"The Girl Is Mine\"\n\"Billie Jean\"\n\"Beat It\"\n\"Wanna Be Startin' Somethin'\"\n\"Human Nature\"\n\"P.Y.T. (Pretty Young Thing)\"\n\"Thriller\"\n\"You've Really Got a Hold on Me\"\n\"Here I Am (Come and Take Me)\"\n\"Lonely Teardrops\"\n\"That's What Love Is Made Of\"\n\"Farewell My Summer Love\"\n\"Girl You're So Together\"\n\"I Just Can't Stop Loving You\"\n\"Bad\"\n\"The Way You Make Me Feel\"\n\"Speed Demon\"\n\"Liberian Girl\"\n\"Just Good Friends\"\n\"Another Part of Me\"\n\"Man in the Mirror\"\n\"Dirty Diana\"\n\"Smooth Criminal\"\n\"Leave Me Alone\"\n\"Twenty-Five Miles\"\n1990s\n\"Black or White\"\n\"Jam\"\n\"In the Closet\"\n\"Remember the Time\"\n\"Heal the World\"\n\"Who Is It\"\n\"Give In to Me\"\n\"Will You Be There\"\n\"Gone Too Soon\"\n\"Dangerous\"\n\"Come Together\"\n\"Scream\"\n\"Childhood\"\n\"They Don't Care About Us\"\n\"Stranger in Moscow\"\n\"This Time Around\"\n\"Earth Song\"\n\"D.S.\"\n\"You Are Not Alone\"\n\"Tabloid Junkie\"\n\"HIStory\"\n\"Smile\"\n\"Blood on the Dance Floor\"\n\"Ghosts\"\n\"Is It Scary\"\n\"On the Line\"\n2000s"}
 {"query": "who sang the hit song \"thriller\"?", "domain": "music", "doc": "\"Jam\"\n\"In the Closet\"\n\"Remember the Time\"\n\"Heal the World\"\n\"Who Is It\"\n\"Give In to Me\"\n\"Will You Be There\"\n\"Gone Too Soon\"\n\"Dangerous\"\n\"Come Together\"\n\"Scream\"\n\"Childhood\"\n\"They Don't Care About Us\"\n\"Stranger in Moscow\"\n\"This Time Around\"\n\"Earth Song\"\n\"D.S.\"\n\"You Are Not Alone\"\n\"Tabloid Junkie\"\n\"HIStory\"\n\"Smile\"\n\"Blood on the Dance Floor\"\n\"Ghosts\"\n\"Is It Scary\"\n\"On the Line\"\n2000s\n\"Speechless\"\n\"You Rock My World\"\n\"Heaven Can Wait\"\n\"Butterflies\"\n\"Cry\"\n\"One More Chance\"\n\"Cheater\"\n\"(I Like) The Way You Love Me\"\n\"Fall Again\"\n\"This Is It\"\n2010s\n\"Hold My Hand\"\n\"Hollywood Tonight\"\n\"(I Can't Make It) Another Day\"\n\"Behind the Mask\"\n\"Don't Be Messin' 'Round\"\n\"I'm So Blue\"\n\"Price of Fame\"\n\"Love Never Felt So Good\"\n\"Chicago\"\n\"Loving You\"\n\"A Place with No Name\"\n\"Slave to the Rhythm\"\n\"Blue Gangsta\"\n2020s\n\"She's Trouble\"\nOther\n\"We Are the World\"\n\"Mind Is the Magic\"\n\"What More Can I Give\"\n\"We Are the World 25 for Haiti\"\n\"Blood on the Dance Floor x Dangerous\"\n\"Diamonds Are Invincible\"\nFeatured\n\"Ease on Down the Road\"\n\"A Brand New Day\"\n\"Night Time Lover\"\n\"Papa Was a Rollin' Stone\"\n\"State of Independence\"\n\"Muscles\"\n\"Say Say Say\"\n\"Somebody's Watching Me\"\n\"Don't Stand Another Chance\"\n\"Centipede\"\n\"Tell Me I'm Not Dreamin' (Too Good to Be True)\"\n\"Eaten Alive\"\n\"Get It\"\n\"2300 Jackson Street\"\n\"Do the Bartman\"\n\"Whatzupwitu\"\n\"Why\"\n\"I Need You\"\n\"We Be Ballin'\"\n\"Girls, Girls, Girls\"\n\"All in Your Name\"\n\"There Must Be More to Life Than This\"\n\"Low\"\n\"Don't Matter to Me\"\nCategory\nAuthority control databases\nMusicBrainz work\nRetrieved from \"https://en.wikipedia.org/w/index.php?title=Thriller_(song)&oldid=1212467768\""}
 {"query": "who sang the hit song \"thriller\"?", "domain": "music", "doc": "\nCategories: 1982 songs1983 singles1984 singlesCBS Records singlesColumbia Records singlesCompositions with a narratorEpic Records singlesHalloween songsMichael Jackson songsNumber-one singles in SpainSNEP Top Singles number-one singlesSong recordings produced by Quincy JonesSongs about monstersSongs written by Rod TempertonHidden categories: CS1 Dutch-language sources (nl)CS1 Italian-language sources (it)CS1 Spanish-language sources (es)Articles with German-language sources (de)CS1 Swedish-language sources (sv)CS1 French-language sources (fr)CS1 German-language sources (de)Cite certification used for Italy without IDCS1 Japanese-language sources (ja)Articles with short descriptionShort description is different from WikidataGood articlesUse American English from November 2021All Wikipedia articles written in American EnglishUse mdy dates from November 2014Articles with hAudio microformatsCertification Cite Ref usages outside Certification Table EntrySingle chart usages for FlandersSingle chart usages for Dutch40Single chart called without artistSingle chart called without songSingle chart usages for Dutch100Single chart usages for New ZealandSingle chart usages for West GermanySingle chart usages for FranceSingle chart usages for ItalySingle chart making named refSingle chart usages for SpainSingle chart usages for AustriaSingle chart usages for NorwaySingle chart usages for SwissSingle chart usages for AustraliaSingle chart usages for FinlandSingle chart usages for SwedenSingle chart usages for BillboarddigitalsongsSingle chart usages for CanadaSingle chart usages for Billboardglobal200Single chart usages for UKSingle chart usages for UKrandbCertification Table Entry usages for AustraliaPages using certification Table Entry with streaming figuresCertification Table Entry usages for DenmarkCertification Table Entry usages for FrancePages using certification Table Entry with sales figuresCertification Table Entry usages for GermanyCertification Table Entry usages for ItalyCertification Table Entry usages for JapanCertification Table Entry usages for MexicoCertification Table Entry usages for SpainCertification Table Entry usages for United KingdomCertification Table Entry usages for United StatesPages using certification Table Entry with sales footnotePages using certification Table Entry with streaming footnoteArticles with MusicBrainz work identifiers"}
 {"query": "who sang the hit song \"thriller\"?", "domain": "music", "doc": "This page was last edited on 8 March 2024, at 01:12\u00a0(UTC).\nText is available under the Creative Commons Attribution-ShareAlike License 4.0;\nadditional terms may apply. By using this site, you agree to the Terms of Use and Privacy Policy. Wikipedia\u00ae is a registered trademark of the Wikimedia Foundation, Inc., a non-profit organization.\nPrivacy policy\nAbout Wikipedia\nDisclaimers\nContact Wikipedia\nCode of Conduct\nDevelopers\nStatistics\nCookie statement\nMobile view\nToggle limited content width"}
-{"query": "who sang the hit song \"thriller\"?", "domain": "music", "doc": "Jon Pareles of The New York Times noted that &quot;&#x27;Billie Jean&#x27;, &#x27;Beat It&#x27;, &#x27;Wanna Be Startin&#x27; Somethin&#x27; &#x27; and &quot;the movie in the song &#x27;Thriller&#x27;&quot;, were the songs, unlike the &quot;fluff&quot; &quot;P.Y.T.&quot;, that were &quot;the hits that made Thriller a world-beater; along with Mr. Jackson&#x27;s stage and video presence, ...Jon Pareles of The New York Times noted that \"'Billie Jean', 'Beat It', 'Wanna Be Startin' Somethin' ' and \"the movie in the song 'Thriller'\", were the songs, unlike the \"fluff\" \"P.Y.T.\", that were \"the hits that made Thriller a world-beater; along with Mr. Jackson's stage and video presence, listeners must have identified with his willingness to admit terror.\" It appears on several of Jackson's greatest-hits albums and has been covered by numerous artists. The song has returned to the Billboard Hot 100 chart multiple times due to its popularity around Halloween. \"Thriller\" is a disco-funk song The introduction features sound effects such as a creaking door, thunder, feet walking on wooden planks, winds and howling wolves. This gave Jackson at least one top-20 hit across seven consecutive decades from 1969 on the Billboard Hot 100. \"Thriller\" was certified platinum by the Recording Industry Association of America on December 4, 1989, for sales of over one million physical units in the US As of August 2016, the song had sold 4,024,398 copies in the US. \"Thriller\" is certified Diamond by the Recording Industry Association of America. It appears on several of Jackson's greatest-hits albums and has been covered by numerous artists. The song has returned to the Billboard Hot 100 chart multiple times due to its popularity around Halloween. \"Thriller\" has returned to the Billboard Hot 100 chart multiple times due to its popularity around Halloween"}
+{"query": "who sang the hit song \"thriller\"?", "domain": "music", "doc": "Jon Pareles of The New York Times noted that &quot;&#x27;Billie Jean&#x27;, &#x27;Beat It&#x27;, &#x27;Wanna Be Starting&#x27; Something&#x27; &#x27; and &quot;the movie in the song &#x27;Thriller&#x27;&quot;, were the songs, unlike the &quot;fluff&quot; &quot;P.Y.T.&quot;, that were &quot;the hits that made Thriller a world-beater; along with Mr. Jackson&#x27;s stage and video presence, ...Jon Pareles of The New York Times noted that \"'Billie Jean', 'Beat It', 'Wanna Be Starting' Something' ' and \"the movie in the song 'Thriller'\", were the songs, unlike the \"fluff\" \"P.Y.T.\", that were \"the hits that made Thriller a world-beater; along with Mr. Jackson's stage and video presence, listeners must have identified with his willingness to admit terror.\" It appears on several of Jackson's greatest-hits albums and has been covered by numerous artists. The song has returned to the Billboard Hot 100 chart multiple times due to its popularity around Halloween. \"Thriller\" is a disco-funk song The introduction features sound effects such as a creaking door, thunder, feet walking on wooden planks, winds and howling wolves. This gave Jackson at least one top-20 hit across seven consecutive decades from 1969 on the Billboard Hot 100. \"Thriller\" was certified platinum by the Recording Industry Association of America on December 4, 1989, for sales of over one million physical units in the US As of August 2016, the song had sold 4,024,398 copies in the US. \"Thriller\" is certified Diamond by the Recording Industry Association of America. It appears on several of Jackson's greatest-hits albums and has been covered by numerous artists. The song has returned to the Billboard Hot 100 chart multiple times due to its popularity around Halloween. \"Thriller\" has returned to the Billboard Hot 100 chart multiple times due to its popularity around Halloween"}
 {"query": "who sang the hit song \"thriller\"?", "domain": "music", "doc": ". \"Thriller\" is certified Diamond by the Recording Industry Association of America. It appears on several of Jackson's greatest-hits albums and has been covered by numerous artists. The song has returned to the Billboard Hot 100 chart multiple times due to its popularity around Halloween. \"Thriller\" has returned to the Billboard Hot 100 chart multiple times due to its popularity around Halloween. It re-entered the Billboard Hot 100 in October 2013 at number 42, number 31 in November 2018, and number 19 in November 2021, its highest placement since 1984. This gave Jackson at least one top-20 hit across seven consecutive decades from 1969 on the Billboard Hot 100."}
diff --git a/AgentQnA/retrieval_tool/README.md b/AgentQnA/retrieval_tool/README.md
index b25436d61e..841d613443 100644
--- a/AgentQnA/retrieval_tool/README.md
+++ b/AgentQnA/retrieval_tool/README.md
@@ -1,35 +1,46 @@
 # Retrieval tool for agent
+
 The retrieval tool in this example is an OPEA megaservice that is comprised of a query embedder, a document retriever and a document reranker.
 
 ## Follow the instructions here to launch microservices.
+
 1. Build images
+
 ```
 cd docker
 build_images.sh
 ```
+
 2. Launch services
+
 ```
 bash launch_retrieval_tool.sh
 ```
 
 ## Index data into vector database
+
 In this example, we use an example jsonl file to ingest example documents into the vector database. For more ways to ingest data and the type of documents supported by OPEA dataprep microservices, please refer to the documentation in the opea-project/GenAIComps repo.
+
 1. create a conda env
 2. Run commands below
+
 ```
 bash run_ingest_data.sh
 ```
 
 ## Validate services
+
 ```
 export ip_address=$(hostname -I | awk '{print $1}')
 curl http://${ip_address}:8889/v1/retrievaltool -X POST -H "Content-Type: application/json" -d '{
      "text": "Taylor Swift hometown"
-    }' 
+    }'
 ```
 
 ## Consume retrieval tool
+
 The endpoint for the retrieval tool is
+
 ```
 http://${ip_address}:8889/v1/retrievaltool
-``` 
+```
diff --git a/AgentQnA/retrieval_tool/docker/build_images.sh b/AgentQnA/retrieval_tool/docker/build_images.sh
index 4ecf7c4ae1..a2a5083f42 100644
--- a/AgentQnA/retrieval_tool/docker/build_images.sh
+++ b/AgentQnA/retrieval_tool/docker/build_images.sh
@@ -1,3 +1,6 @@
+# Copyright (C) 2024 Intel Corporation
+# SPDX-License-Identifier: Apache-2.0
+
 cd ${WORKDIR}/GenAIComps/
 echo $PWD
 
@@ -21,4 +24,4 @@ cd $WORKDIR/GenAIExamples/AgentQnA/retrieval_tool/docker/
 echo $PWD
 echo "==============Building retrieval-tool image================="
 docker build --no-cache -t opea/retrievaltool:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f Dockerfile_retrievaltool .
-echo "==============Successfully built retrieval-tool image================="
\ No newline at end of file
+echo "==============Successfully built retrieval-tool image================="
diff --git a/AgentQnA/retrieval_tool/docker/docker-compose-retrieval-tool.yaml b/AgentQnA/retrieval_tool/docker/docker-compose-retrieval-tool.yaml
index b01cac4266..66926e0a60 100644
--- a/AgentQnA/retrieval_tool/docker/docker-compose-retrieval-tool.yaml
+++ b/AgentQnA/retrieval_tool/docker/docker-compose-retrieval-tool.yaml
@@ -102,7 +102,7 @@ services:
       LANGCHAIN_TRACING_V2: ${LANGCHAIN_TRACING_V2}
       LANGCHAIN_PROJECT: "opea-reranking-service"
     restart: unless-stopped
-  
+
   dataprep-redis-service:
     image: opea/dataprep-redis:latest
     container_name: dataprep-redis-server
@@ -121,11 +121,11 @@ services:
       REDIS_URL: ${REDIS_URL}
       INDEX_NAME: ${INDEX_NAME}
       TEI_ENDPOINT: ${TEI_EMBEDDING_ENDPOINT}
-  
+
   retrievaltool-xeon-backend-server:
     image: opea/retrievaltool:latest
     container_name: retrievaltool-xeon-backend-server
-    # volumes: 
+    # volumes:
     #   - ${WORKDIR}/GenAIComps/comps/:/home/user/GenAIComps/comps/
     #   - ${WORKDIR}/GenAIExamples/AgentQnA/retrieval_tool/docker/:/home/user/script/
     depends_on:
@@ -150,4 +150,4 @@ services:
 
 networks:
   default:
-    driver: bridge
\ No newline at end of file
+    driver: bridge
diff --git a/AgentQnA/retrieval_tool/docker/launch_retrieval_tool.sh b/AgentQnA/retrieval_tool/docker/launch_retrieval_tool.sh
index 9ba6451ed8..127721f790 100644
--- a/AgentQnA/retrieval_tool/docker/launch_retrieval_tool.sh
+++ b/AgentQnA/retrieval_tool/docker/launch_retrieval_tool.sh
@@ -1,3 +1,6 @@
+# Copyright (C) 2024 Intel Corporation
+# SPDX-License-Identifier: Apache-2.0
+
 host_ip=$(hostname -I | awk '{print $1}')
 export HF_CACHE_DIR=${HF_CACHE_DIR}
 export no_proxy=${no_proxy}
@@ -18,4 +21,4 @@ export DATAPREP_SERVICE_ENDPOINT="http://${host_ip}:6007/v1/dataprep"
 export DATAPREP_GET_FILE_ENDPOINT="http://${host_ip}:6008/v1/dataprep/get_file"
 export DATAPREP_DELETE_FILE_ENDPOINT="http://${host_ip}:6009/v1/dataprep/delete_file"
 
-docker compose -f docker-compose-retrieval-tool.yaml up -d
\ No newline at end of file
+docker compose -f docker-compose-retrieval-tool.yaml up -d
diff --git a/AgentQnA/retrieval_tool/docker/retrieval_tool.py b/AgentQnA/retrieval_tool/docker/retrieval_tool.py
index 238303bd72..b2b766f118 100644
--- a/AgentQnA/retrieval_tool/docker/retrieval_tool.py
+++ b/AgentQnA/retrieval_tool/docker/retrieval_tool.py
@@ -15,6 +15,7 @@
 RERANK_SERVICE_HOST_IP = os.getenv("RERANK_SERVICE_HOST_IP", "0.0.0.0")
 RERANK_SERVICE_PORT = os.getenv("RERANK_SERVICE_PORT", 8000)
 
+
 class RetrievalToolService:
     def __init__(self, host="0.0.0.0", port=8000):
         self.host = host
@@ -46,7 +47,7 @@ def add_remote_service(self):
             use_remote_service=True,
             service_type=ServiceType.RERANK,
         )
-        
+
         self.megaservice.add(embedding).add(retriever).add(rerank)
         self.megaservice.flow_to(embedding, retriever)
         self.megaservice.flow_to(retriever, rerank)
@@ -57,4 +58,4 @@ def add_remote_service(self):
 
 if __name__ == "__main__":
     chatqna = RetrievalToolService(host=MEGA_SERVICE_HOST_IP, port=MEGA_SERVICE_PORT)
-    chatqna.add_remote_service()
\ No newline at end of file
+    chatqna.add_remote_service()
diff --git a/AgentQnA/retrieval_tool/index_data.py b/AgentQnA/retrieval_tool/index_data.py
index 3f9e843aaa..755eb68539 100644
--- a/AgentQnA/retrieval_tool/index_data.py
+++ b/AgentQnA/retrieval_tool/index_data.py
@@ -1,24 +1,30 @@
-import requests
-import json
+# Copyright (C) 2024 Intel Corporation
+# SPDX-License-Identifier: Apache-2.0
+
 import argparse
+import json
 import os
+
+import requests
 import tqdm
 
+
 def get_args():
-    parser = argparse.ArgumentParser(description='Index data')
-    parser.add_argument('--host_ip', type=str, default='localhost', help='Host IP')
-    parser.add_argument('--port', type=int, default=6007, help='Port')
-    parser.add_argument('--filedir', type=str, default=None, help='file directory')
-    parser.add_argument('--filename', type=str, default=None, help='file name')
+    parser = argparse.ArgumentParser(description="Index data")
+    parser.add_argument("--host_ip", type=str, default="localhost", help="Host IP")
+    parser.add_argument("--port", type=int, default=6007, help="Port")
+    parser.add_argument("--filedir", type=str, default=None, help="file directory")
+    parser.add_argument("--filename", type=str, default=None, help="file name")
     parser.add_argument("--chunk_size", type=int, default=10000, help="Chunk size")
     parser.add_argument("--chunk_overlap", type=int, default=0, help="Chunk overlap")
     args = parser.parse_args()
     return args
 
+
 def split_jsonl_into_txts(jsonl_file):
     docs = []
     n = 0
-    with open(jsonl_file, 'r') as f:
+    with open(jsonl_file, "r") as f:
         for line in f:
             data = json.loads(line)
             docs.append(data["doc"])
@@ -27,19 +33,22 @@ def split_jsonl_into_txts(jsonl_file):
             #     break
     return docs
 
+
 def write_docs_to_disk(docs, output_folder):
     output_files = []
     for i, text in enumerate(docs):
-        output = os.path.join(output_folder, str(i) + '.txt')
+        output = os.path.join(output_folder, str(i) + ".txt")
         output_files.append(output)
-        with open(output, 'w') as f:
+        with open(output, "w") as f:
             f.write(text)
     return output_files
 
+
 def delete_files(files):
     for file in files:
         os.remove(file)
 
+
 def main():
     args = get_args()
     print(args)
@@ -54,17 +63,18 @@ def main():
     file_list = write_docs_to_disk(files, args.filedir)
 
     print(file_list)
-    
+
     for file in tqdm.tqdm(file_list):
         print("Indexing file: ", file)
-        files = [('files', (f, open(f, 'rb'))) for f in [file]]
+        files = [("files", (f, open(f, "rb"))) for f in [file]]
         payload = {"chunk_size": args.chunk_size, "chunk_overlap": args.chunk_overlap}
-        resp = requests.request('POST', url=url, headers={}, files=files, data=payload, proxies=proxies)
+        resp = requests.request("POST", url=url, headers={}, files=files, data=payload, proxies=proxies)
         print(resp.text)
 
     print("Removing temp files....")
     delete_files(file_list)
-    print('ALL DONE!')
+    print("ALL DONE!")
+
 
-if __name__ == '__main__':
-    main()
\ No newline at end of file
+if __name__ == "__main__":
+    main()
diff --git a/AgentQnA/retrieval_tool/run_ingest_data.sh b/AgentQnA/retrieval_tool/run_ingest_data.sh
index cf86cdbe2d..c82769c84f 100644
--- a/AgentQnA/retrieval_tool/run_ingest_data.sh
+++ b/AgentQnA/retrieval_tool/run_ingest_data.sh
@@ -1,4 +1,7 @@
+# Copyright (C) 2024 Intel Corporation
+# SPDX-License-Identifier: Apache-2.0
+
 FILEDIR=${WORKDIR}/GenAIExamples/AgentQnA/example_data/
 FILENAME=test_docs_music.jsonl
 
-python3 index_data.py --filedir ${FILEDIR} --filename ${FILENAME} --host_ip $host_ip
\ No newline at end of file
+python3 index_data.py --filedir ${FILEDIR} --filename ${FILENAME} --host_ip $host_ip
diff --git a/AgentQnA/tests/2_start_retrieval_tool.sh b/AgentQnA/tests/2_start_retrieval_tool.sh
index 09fa8a2035..66d5c8108d 100644
--- a/AgentQnA/tests/2_start_retrieval_tool.sh
+++ b/AgentQnA/tests/2_start_retrieval_tool.sh
@@ -23,4 +23,4 @@ function start_retrieval_tool() {
 echo "==================== Start retrieval tool ===================="
 start_retrieval_tool
 sleep 20 # needed for downloading the models
-echo "==================== Retrieval tool started ===================="
\ No newline at end of file
+echo "==================== Retrieval tool started ===================="
diff --git a/AgentQnA/tests/3_ingest_data_and_validate_retrieval.sh b/AgentQnA/tests/3_ingest_data_and_validate_retrieval.sh
index 6525bfaf65..8794f8188d 100644
--- a/AgentQnA/tests/3_ingest_data_and_validate_retrieval.sh
+++ b/AgentQnA/tests/3_ingest_data_and_validate_retrieval.sh
@@ -47,7 +47,7 @@ function validate_retrieval_tool() {
      "text": "Who sang Thriller"
     }')
     local EXIT_CODE=$(validate "$CONTENT" "Thriller" "retrieval-tool")
-    
+
     if [ "$EXIT_CODE" == "1" ]; then
         docker logs retrievaltool-xeon-backend-server
         exit 1
@@ -65,4 +65,4 @@ function main(){
     echo "==================== Retrieval tool validated ===================="
 }
 
-main
\ No newline at end of file
+main
diff --git a/AgentQnA/tests/4_launch_and_validate_agent_openai.sh b/AgentQnA/tests/4_launch_and_validate_agent_openai.sh
index f1d916e451..2c37291301 100644
--- a/AgentQnA/tests/4_launch_and_validate_agent_openai.sh
+++ b/AgentQnA/tests/4_launch_and_validate_agent_openai.sh
@@ -57,4 +57,4 @@ function main() {
     echo "==================== Agent service validated ===================="
 }
 
-main
\ No newline at end of file
+main
diff --git a/AgentQnA/tests/4_launch_and_validate_agent_tgi.sh b/AgentQnA/tests/4_launch_and_validate_agent_tgi.sh
index 0c9eb17cfd..8e8a273886 100644
--- a/AgentQnA/tests/4_launch_and_validate_agent_tgi.sh
+++ b/AgentQnA/tests/4_launch_and_validate_agent_tgi.sh
@@ -75,4 +75,4 @@ function main() {
     echo "==================== Agent service validated ===================="
 }
 
-main
\ No newline at end of file
+main
diff --git a/AgentQnA/tests/run_test_agent_service.sh b/AgentQnA/tests/run_test_agent_service.sh
index a291889e7c..4f9828f7e6 100644
--- a/AgentQnA/tests/run_test_agent_service.sh
+++ b/AgentQnA/tests/run_test_agent_service.sh
@@ -1,3 +1,6 @@
+# Copyright (C) 2024 Intel Corporation
+# SPDX-License-Identifier: Apache-2.0
+
 QUERYFILE=$WORKDIR/datasets/crag_qas/crag_20_answerable_queries.csv
 OUTFILE=$WORKDIR/datasets/crag_results/validation_5outof20.jsonl
 PORT=9095
diff --git a/AgentQnA/tests/src/commons.py b/AgentQnA/tests/src/commons.py
index e1dc6adb36..09c38489f3 100644
--- a/AgentQnA/tests/src/commons.py
+++ b/AgentQnA/tests/src/commons.py
@@ -1 +1,4 @@
-QUERY_SEPERATOR = "========THIS IS A NEW QUERY========"
\ No newline at end of file
+# Copyright (C) 2024 Intel Corporation
+# SPDX-License-Identifier: Apache-2.0
+
+QUERY_SEPERATOR = "========THIS IS A NEW QUERY========"
diff --git a/AgentQnA/tests/src/test_agent_service.py b/AgentQnA/tests/src/test_agent_service.py
index 2d12b9b620..efe190b7f5 100644
--- a/AgentQnA/tests/src/test_agent_service.py
+++ b/AgentQnA/tests/src/test_agent_service.py
@@ -1,36 +1,45 @@
-import requests
-import json
+# Copyright (C) 2024 Intel Corporation
+# SPDX-License-Identifier: Apache-2.0
+
 import argparse
+import json
 import os
+
 import pandas as pd
+import requests
 from commons import QUERY_SEPERATOR
 
+
 def get_test_data(args):
-    if args.query_file.endswith('.jsonl'):
+    if args.query_file.endswith(".jsonl"):
         df = pd.read_json(args.query_file, lines=True, convert_dates=False)
-    elif args.query_file.endswith('.csv'):
+    elif args.query_file.endswith(".csv"):
         df = pd.read_csv(args.query_file)
     return df
 
+
 def generate_answer(url, prompt):
     proxies = {"http": ""}
     payload = {
-        "query":prompt,
-        } 
+        "query": prompt,
+    }
     response = requests.post(url, json=payload, proxies=proxies)
     answer = response.json()["text"]
     return answer
 
-def save_results(output_file, output_list):       
+
+def save_results(output_file, output_list):
     with open(output_file, "w") as f:
         for output in output_list:
             f.write(json.dumps(output))
             f.write("\n")
 
+
 def save_as_csv(output):
     df = pd.read_json(output, lines=True, convert_dates=False)
     df.to_csv(output.replace(".jsonl", ".csv"), index=False)
 
+
 if __name__ == "__main__":
     parser = argparse.ArgumentParser()
     parser.add_argument("--host_ip", type=str, default="localhost", help="host ip of the retrieval tool")
@@ -39,59 +48,58 @@ def save_as_csv(output):
     parser.add_argument("--output_file", type=str, default="output.jsonl", help="output jsonl file")
     parser.add_argument("--quick_test", action="store_true", help="run quick test")
     args = parser.parse_args()
-    
+
     host_ip = args.host_ip
     port = args.port
-    endpoint = "{port}/v1/chat/completions".format(port = port)
+    endpoint = "{port}/v1/chat/completions".format(port=port)
     url = "http://{host_ip}:{endpoint}".format(host_ip=host_ip, endpoint=endpoint)
 
     if args.quick_test:
-        query= [
-                "Taylor Swift hometown",
-                # "how many songs has the band the beatles released that have been recorded at abbey road studios?",
-                # "what's the most recent album from the founder of ysl records?",
-                # "when did dolly parton's song, blown away, come out?"
-                # "what song topped the billboard chart on 2004-02-04?",
-                # "what grammy award did edgar barrera win this year?",
-                # "who has had more number one hits on the us billboard hot 100 chart, michael jackson or elvis presley?",
-            ]
-        query_time=[
-            "08/11/2024, 23:37:29 PT", 
+        query = [
+            "Taylor Swift hometown",
+            # "how many songs has the band the beatles released that have been recorded at abbey road studios?",
+            # "what's the most recent album from the founder of ysl records?",
+            # "when did dolly parton's song, blown away, come out?"
+            # "what song topped the billboard chart on 2004-02-04?",
+            # "what grammy award did edgar barrera win this year?",
+            # "who has had more number one hits on the us billboard hot 100 chart, michael jackson or elvis presley?",
+        ]
+        query_time = [
+            "08/11/2024, 23:37:29 PT",
             # "03/21/2024, 23:37:29 PT",
             # "03/21/2024, 23:37:29 PT",
             # "03/21/2024, 23:37:29 PT",
-            ]
+        ]
         df = pd.DataFrame({"query": query, "query_time": query_time})
     else:
         df = get_test_data(args)
-        df = df.head() # for validation purpose
+        df = df.head()  # for validation purpose
 
-    
     output_list = []
     n = 0
     for _, row in df.iterrows():
-        q = row['query']
-        t = row['query_time']
+        q = row["query"]
+        t = row["query_time"]
         prompt = "Question: {}\nThe question was asked at: {}".format(q, t)
         print(QUERY_SEPERATOR)
-        print('******Query:\n',prompt)
+        print("******Query:\n", prompt)
         print("******Agent is working on the query")
         answer = generate_answer(url, prompt)
-        print('******Answer from agent:\n',answer)
-        print('='*50)
+        print("******Answer from agent:\n", answer)
+        print("=" * 50)
         output_list.append(
-                {
-                    "query": q,
-                    "query_time": t,
-                    # "ref_answer": row["answer"],
-                    "answer": answer,
-                    # "question_type": row["question_type"],
-                    # "static_or_dynamic": row["static_or_dynamic"],
-                }
-            )
+            {
+                "query": q,
+                "query_time": t,
+                # "ref_answer": row["answer"],
+                "answer": answer,
+                # "question_type": row["question_type"],
+                # "static_or_dynamic": row["static_or_dynamic"],
+            }
+        )
         save_results(args.output_file, output_list)
         # n += 1
         # if n > 1:
         #     break
     save_results(args.output_file, output_list)
-    save_as_csv(args.output_file)
\ No newline at end of file
+    save_as_csv(args.output_file)
diff --git a/AgentQnA/tools/worker_agent_tools.py b/AgentQnA/tools/worker_agent_tools.py
index d599edf8e9..1dfdb8409e 100644
--- a/AgentQnA/tools/worker_agent_tools.py
+++ b/AgentQnA/tools/worker_agent_tools.py
@@ -1,6 +1,11 @@
-import requests
+# Copyright (C) 2024 Intel Corporation
+# SPDX-License-Identifier: Apache-2.0
+
 import os
 
+import requests
+
+
 def search_knowledge_base(query: str) -> str:
     """Search the knowledge base for a specific query."""
     url = os.environ.get("RETRIEVAL_TOOL_URL")
@@ -19,4 +24,4 @@ def search_knowledge_base(query: str) -> str:
         else:
             context += "\n" + doc
     print(context)
-    return context
\ No newline at end of file
+    return context
diff --git a/AgentQnA/tools/worker_agent_tools.yaml b/AgentQnA/tools/worker_agent_tools.yaml
index 126833badf..32d19562cc 100644
--- a/AgentQnA/tools/worker_agent_tools.yaml
+++ b/AgentQnA/tools/worker_agent_tools.yaml
@@ -9,4 +9,3 @@ search_knowledge_base:
       type: str
       description: query
   return_output: retrieved_data
-

From c62611635e9878cc5b5bbf8aa28971bc94162162 Mon Sep 17 00:00:00 2001
From: minmin-intel <minmin.hou@intel.com>
Date: Thu, 29 Aug 2024 00:20:09 +0000
Subject: [PATCH 20/39] update test and folder name for cicd

Signed-off-by: minmin-intel <minmin.hou@intel.com>
---
 .../docker-compose-agent-tgi-gaudi.yaml => gaudi/compose.yaml} | 0
 .../{tgi-gaudi => gaudi}/launch_agent_service_tgi_gaudi.sh     | 2 +-
 AgentQnA/tests/4_launch_and_validate_agent_tgi.sh              | 3 ++-
 3 files changed, 3 insertions(+), 2 deletions(-)
 rename AgentQnA/docker/{tgi-gaudi/docker-compose-agent-tgi-gaudi.yaml => gaudi/compose.yaml} (100%)
 rename AgentQnA/docker/{tgi-gaudi => gaudi}/launch_agent_service_tgi_gaudi.sh (92%)

diff --git a/AgentQnA/docker/tgi-gaudi/docker-compose-agent-tgi-gaudi.yaml b/AgentQnA/docker/gaudi/compose.yaml
similarity index 100%
rename from AgentQnA/docker/tgi-gaudi/docker-compose-agent-tgi-gaudi.yaml
rename to AgentQnA/docker/gaudi/compose.yaml
diff --git a/AgentQnA/docker/tgi-gaudi/launch_agent_service_tgi_gaudi.sh b/AgentQnA/docker/gaudi/launch_agent_service_tgi_gaudi.sh
similarity index 92%
rename from AgentQnA/docker/tgi-gaudi/launch_agent_service_tgi_gaudi.sh
rename to AgentQnA/docker/gaudi/launch_agent_service_tgi_gaudi.sh
index 8a1acc59b2..7c4ae45964 100644
--- a/AgentQnA/docker/tgi-gaudi/launch_agent_service_tgi_gaudi.sh
+++ b/AgentQnA/docker/gaudi/launch_agent_service_tgi_gaudi.sh
@@ -19,4 +19,4 @@ export WORKER_AGENT_URL="http://${ip_address}:9095/v1/chat/completions"
 export RETRIEVAL_TOOL_URL="http://${ip_address}:8889/v1/retrievaltool"
 export CRAG_SERVER=http://${ip_address}:8080
 
-docker compose -f docker-compose-agent-tgi-gaudi.yaml up -d
\ No newline at end of file
+docker compose -f compose.yaml up -d
\ No newline at end of file
diff --git a/AgentQnA/tests/4_launch_and_validate_agent_tgi.sh b/AgentQnA/tests/4_launch_and_validate_agent_tgi.sh
index 0c9eb17cfd..872921a38a 100644
--- a/AgentQnA/tests/4_launch_and_validate_agent_tgi.sh
+++ b/AgentQnA/tests/4_launch_and_validate_agent_tgi.sh
@@ -23,7 +23,7 @@ function start_agent_and_api_server() {
     docker run -d -p=8080:8000 docker.io/aicrowd/kdd-cup-24-crag-mock-api:v0
 
     echo "Starting Agent services"
-    cd $WORKDIR/GenAIExamples/AgentQnA/docker/tgi-gaudi
+    cd $WORKDIR/GenAIExamples/AgentQnA/docker/gaudi
     bash launch_agent_service_tgi_gaudi.sh
 }
 
@@ -68,6 +68,7 @@ function main() {
     start_agent_and_api_server
     echo "Waiting for LLM endpoint to be ready"
     sleep 300
+    docker logs tgi-server
     echo "==================== Agent started ===================="
 
     echo "==================== Validate agent service ===================="

From 5532dd88007583220c1bee6bbe49534420010fba Mon Sep 17 00:00:00 2001
From: minmin-intel <minmin.hou@intel.com>
Date: Thu, 29 Aug 2024 00:39:30 +0000
Subject: [PATCH 21/39] stop container before run tests

Signed-off-by: minmin-intel <minmin.hou@intel.com>
---
 AgentQnA/tests/test_agentqna_on_gaudi.sh | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/AgentQnA/tests/test_agentqna_on_gaudi.sh b/AgentQnA/tests/test_agentqna_on_gaudi.sh
index 82fadf72a1..1fd7bd14b5 100644
--- a/AgentQnA/tests/test_agentqna_on_gaudi.sh
+++ b/AgentQnA/tests/test_agentqna_on_gaudi.sh
@@ -14,7 +14,7 @@ function stop_agent_and_api_server() {
     echo "Stopping CRAG server"
     docker stop $(docker ps -q --filter ancestor=docker.io/aicrowd/kdd-cup-24-crag-mock-api:v0)
     echo "Stopping Agent services"
-    docker stop $(docker ps -q --filter ancestor=opea/comps-agent-langchain:latest)
+    docker compose -f $WORKDIR/GenAIExamples/AgentQnA/docker/gaudi/compose.yaml down
 }
 
 function stop_retrieval_tool() {
@@ -22,6 +22,10 @@ function stop_retrieval_tool() {
     docker compose -f $WORKDIR/GenAIExamples/AgentQnA/retrieval_tool/docker/docker-compose-retrieval-tool.yaml down
 }
 
+echo "=================== Stop containers ===================="
+stop_agent_and_api_server
+stop_retrieval_tool
+
 echo "=================== #1 Building docker images===================="
 bash 1_build_images.sh
 echo "=================== #1 Building docker images completed===================="

From 5e03f6a5cd20c968578692c7f25e0870ce7566b4 Mon Sep 17 00:00:00 2001
From: minmin-intel <minmin.hou@intel.com>
Date: Wed, 4 Sep 2024 18:43:12 +0000
Subject: [PATCH 22/39] use DocIndexRetriever example to launch retrieval tool

Signed-off-by: minmin-intel <minmin.hou@intel.com>
---
 .../retrieval_tool/docker/build_images.sh     | 28 +++++++++----------
 .../docker/launch_retrieval_tool.sh           |  2 +-
 DocIndexRetriever/docker/Dockerfile           |  7 +++--
 .../docker/xeon/docker_compose.yaml           | 12 ++++----
 4 files changed, 26 insertions(+), 23 deletions(-)

diff --git a/AgentQnA/retrieval_tool/docker/build_images.sh b/AgentQnA/retrieval_tool/docker/build_images.sh
index a2a5083f42..d0bc5ed98f 100644
--- a/AgentQnA/retrieval_tool/docker/build_images.sh
+++ b/AgentQnA/retrieval_tool/docker/build_images.sh
@@ -4,24 +4,24 @@
 cd ${WORKDIR}/GenAIComps/
 echo $PWD
 
-echo "==============Building dataprep image================="
-docker build --no-cache -t opea/dataprep-redis:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/dataprep/redis/langchain/docker/Dockerfile .
-echo "==============Successfully built dataprep image================="
+# echo "==============Building dataprep image================="
+# docker build --no-cache -t opea/dataprep-redis:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/dataprep/redis/langchain/docker/Dockerfile .
+# echo "==============Successfully built dataprep image================="
 
-echo "==============Building embedding-tei image================="
-docker build --no-cache -t opea/embedding-tei:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/embeddings/langchain/docker/Dockerfile .
-echo "==============Successfully built embedding-tei image================="
+# echo "==============Building embedding-tei image================="
+# docker build --no-cache -t opea/embedding-tei:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/embeddings/langchain/docker/Dockerfile .
+# echo "==============Successfully built embedding-tei image================="
 
-echo "==============Building retriever-redis image================="
-docker build --no-cache -t opea/retriever-redis:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/retrievers/langchain/redis/docker/Dockerfile .
-echo "==============Successfully built retriever-redis image================="
+# echo "==============Building retriever-redis image================="
+# docker build --no-cache -t opea/retriever-redis:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/retrievers/langchain/redis/docker/Dockerfile .
+# echo "==============Successfully built retriever-redis image================="
 
-echo "==============Building reranking-tei image================="
-docker build --no-cache -t opea/reranking-tei:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/reranks/tei/docker/Dockerfile .
-echo "==============Successfully built reranking-tei image================="
+# echo "==============Building reranking-tei image================="
+# docker build --no-cache -t opea/reranking-tei:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/reranks/tei/docker/Dockerfile .
+# echo "==============Successfully built reranking-tei image================="
 
-cd $WORKDIR/GenAIExamples/AgentQnA/retrieval_tool/docker/
+cd $WORKDIR
 echo $PWD
 echo "==============Building retrieval-tool image================="
-docker build --no-cache -t opea/retrievaltool:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f Dockerfile_retrievaltool .
+docker build --no-cache -t opea/doc-index-retriever:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f GenAIExamples/DocIndexRetriever/docker/Dockerfile .
 echo "==============Successfully built retrieval-tool image================="
diff --git a/AgentQnA/retrieval_tool/docker/launch_retrieval_tool.sh b/AgentQnA/retrieval_tool/docker/launch_retrieval_tool.sh
index 127721f790..0c47dd3cce 100644
--- a/AgentQnA/retrieval_tool/docker/launch_retrieval_tool.sh
+++ b/AgentQnA/retrieval_tool/docker/launch_retrieval_tool.sh
@@ -21,4 +21,4 @@ export DATAPREP_SERVICE_ENDPOINT="http://${host_ip}:6007/v1/dataprep"
 export DATAPREP_GET_FILE_ENDPOINT="http://${host_ip}:6008/v1/dataprep/get_file"
 export DATAPREP_DELETE_FILE_ENDPOINT="http://${host_ip}:6009/v1/dataprep/delete_file"
 
-docker compose -f docker-compose-retrieval-tool.yaml up -d
+docker compose -f $WORKDIR/GenAIExamples/DocIndexRetriever/docker/xeon/docker_compose.yaml up -d
diff --git a/DocIndexRetriever/docker/Dockerfile b/DocIndexRetriever/docker/Dockerfile
index 705f250b87..45294d7250 100644
--- a/DocIndexRetriever/docker/Dockerfile
+++ b/DocIndexRetriever/docker/Dockerfile
@@ -3,8 +3,6 @@
 
 FROM python:3.11-slim
 
-COPY GenAIComps /home/user/GenAIComps
-
 RUN apt-get update -y && apt-get install -y --no-install-recommends --fix-missing \
     libgl1-mesa-glx \
     libjemalloc-dev \
@@ -14,6 +12,11 @@ RUN useradd -m -s /bin/bash user && \
     mkdir -p /home/user && \
     chown -R user /home/user/
 
+
+RUN cd /home/user/ && \
+    git clone https://github.com/opea-project/GenAIComps.git
+
+
 WORKDIR /home/user/GenAIComps
 RUN pip install --no-cache-dir --upgrade pip && \
     pip install --no-cache-dir -r /home/user/GenAIComps/requirements.txt
diff --git a/DocIndexRetriever/docker/xeon/docker_compose.yaml b/DocIndexRetriever/docker/xeon/docker_compose.yaml
index abf78e032c..e0b29650e3 100644
--- a/DocIndexRetriever/docker/xeon/docker_compose.yaml
+++ b/DocIndexRetriever/docker/xeon/docker_compose.yaml
@@ -9,10 +9,10 @@ services:
     image: redis/redis-stack:7.2.0-v9
     container_name: redis-vector-db
     ports:
-      - "16379:6379"
+      - "6379:6379"
       - "8001:8001"
   dataprep-redis-service:
-    image: opea/dataprep-on-ray-redis:latest
+    image: opea/dataprep-redis:latest
     container_name: dataprep-redis-server
     depends_on:
       - redis-vector-db
@@ -76,7 +76,7 @@ services:
     image: opea/reranking-tei:latest
     container_name: reranking-tei-server
     ports:
-      - "18000:8000"
+      - "8000:8000"
     ipc: host
     entrypoint: python local_reranking.py
     environment:
@@ -103,9 +103,9 @@ services:
     ports:
       - "8889:8889"
     environment:
-      - no_proxy=${no_proxy}
-      - https_proxy=${https_proxy}
-      - http_proxy=${http_proxy}
+      # - no_proxy=${no_proxy}
+      # - https_proxy=${https_proxy}
+      # - http_proxy=${http_proxy}
       - MEGA_SERVICE_HOST_IP=${MEGA_SERVICE_HOST_IP}
       - EMBEDDING_SERVICE_HOST_IP=${EMBEDDING_SERVICE_HOST_IP}
       - RETRIEVER_SERVICE_HOST_IP=${RETRIEVER_SERVICE_HOST_IP}

From 653d73f53b175e8dd7c6c014d443084565d73a8a Mon Sep 17 00:00:00 2001
From: "pre-commit-ci[bot]"
 <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Date: Wed, 4 Sep 2024 22:13:37 +0000
Subject: [PATCH 23/39] [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci
---
 DocIndexRetriever/docker/xeon/docker_compose.yaml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/DocIndexRetriever/docker/xeon/docker_compose.yaml b/DocIndexRetriever/docker/xeon/docker_compose.yaml
index 54e0ae687e..1292736ba1 100644
--- a/DocIndexRetriever/docker/xeon/docker_compose.yaml
+++ b/DocIndexRetriever/docker/xeon/docker_compose.yaml
@@ -79,7 +79,7 @@ services:
       LANGCHAIN_TRACING_V2: ${LANGCHAIN_TRACING_V2}
       LANGCHAIN_PROJECT: "opea-retriever-service"
     restart: unless-stopped
-    
+
   tei-reranking-service:
     image: ghcr.io/huggingface/text-embeddings-inference:cpu-1.2
     container_name: tei-reranking-server

From 2ca3a03b7fc0ba764de88557aa8316fdb2f5abe2 Mon Sep 17 00:00:00 2001
From: minmin-intel <minmin.hou@intel.com>
Date: Wed, 4 Sep 2024 22:18:14 +0000
Subject: [PATCH 24/39] update docker compose yaml for DocIndexRetriever xeon

Signed-off-by: minmin-intel <minmin.hou@intel.com>
---
 .../docker/xeon/docker_compose.yaml           | 32 +++++++++++++++++--
 1 file changed, 29 insertions(+), 3 deletions(-)

diff --git a/DocIndexRetriever/docker/xeon/docker_compose.yaml b/DocIndexRetriever/docker/xeon/docker_compose.yaml
index e0b29650e3..54e0ae687e 100644
--- a/DocIndexRetriever/docker/xeon/docker_compose.yaml
+++ b/DocIndexRetriever/docker/xeon/docker_compose.yaml
@@ -18,17 +18,20 @@ services:
       - redis-vector-db
     ports:
       - "6007:6007"
+      - "6008:6008"
+      - "6009:6009"
     environment:
       no_proxy: ${no_proxy}
       http_proxy: ${http_proxy}
       https_proxy: ${https_proxy}
       REDIS_URL: ${REDIS_URL}
       INDEX_NAME: ${INDEX_NAME}
+      TEI_ENDPOINT: ${TEI_EMBEDDING_ENDPOINT}
   tei-embedding-service:
     image: ghcr.io/huggingface/text-embeddings-inference:cpu-1.2
     container_name: tei-embedding-server
     ports:
-      - "8090:80"
+      - "6006:80"
     volumes:
       - "./data:/data"
     shm_size: 1g
@@ -36,6 +39,7 @@ services:
       no_proxy: ${no_proxy}
       http_proxy: ${http_proxy}
       https_proxy: ${https_proxy}
+      HUGGINGFACEHUB_API_TOKEN: ${HUGGINGFACEHUB_API_TOKEN}
     command: --model-id ${EMBEDDING_MODEL_ID}
   embedding:
     image: opea/embedding-tei:latest
@@ -49,6 +53,7 @@ services:
       no_proxy: ${no_proxy}
       http_proxy: ${http_proxy}
       https_proxy: ${https_proxy}
+      HUGGINGFACEHUB_API_TOKEN: ${HUGGINGFACEHUB_API_TOKEN}
       TEI_EMBEDDING_ENDPOINT: ${TEI_EMBEDDING_ENDPOINT}
       LANGCHAIN_API_KEY: ${LANGCHAIN_API_KEY}
       LANGCHAIN_TRACING_V2: ${LANGCHAIN_TRACING_V2}
@@ -68,17 +73,38 @@ services:
       https_proxy: ${https_proxy}
       REDIS_URL: ${REDIS_URL}
       INDEX_NAME: ${INDEX_NAME}
+      HUGGINGFACEHUB_API_TOKEN: ${HUGGINGFACEHUB_API_TOKEN}
+      TEI_EMBEDDING_ENDPOINT: ${TEI_EMBEDDING_ENDPOINT}
       LANGCHAIN_API_KEY: ${LANGCHAIN_API_KEY}
       LANGCHAIN_TRACING_V2: ${LANGCHAIN_TRACING_V2}
       LANGCHAIN_PROJECT: "opea-retriever-service"
     restart: unless-stopped
+    
+  tei-reranking-service:
+    image: ghcr.io/huggingface/text-embeddings-inference:cpu-1.2
+    container_name: tei-reranking-server
+    ports:
+      - "8808:80"
+    volumes:
+      - ${HF_CACHE_DIR}:/data
+    shm_size: 1g
+    environment:
+      no_proxy: ${no_proxy}
+      http_proxy: ${http_proxy}
+      https_proxy: ${https_proxy}
+      HUGGINGFACEHUB_API_TOKEN: ${HUGGINGFACEHUB_API_TOKEN}
+      HF_HUB_DISABLE_PROGRESS_BARS: 1
+      HF_HUB_ENABLE_HF_TRANSFER: 0
+    command: --model-id ${RERANK_MODEL_ID}
+
   reranking:
     image: opea/reranking-tei:latest
-    container_name: reranking-tei-server
+    container_name: reranking-tei-xeon-server
+    depends_on:
+      - tei-reranking-service
     ports:
       - "8000:8000"
     ipc: host
-    entrypoint: python local_reranking.py
     environment:
       no_proxy: ${no_proxy}
       http_proxy: ${http_proxy}

From 54b21360457c585b63a9f3c2f2fb98f2e53f3651 Mon Sep 17 00:00:00 2001
From: minmin-intel <minmin.hou@intel.com>
Date: Wed, 4 Sep 2024 23:05:17 +0000
Subject: [PATCH 25/39] working DocIndexRetriever on xeon

Signed-off-by: minmin-intel <minmin.hou@intel.com>
---
 .../docker/Dockerfile_retrievaltool           |  31 ----
 .../docker/docker-compose-retrieval-tool.yaml | 153 ------------------
 .../docker/launch_retrieval_tool.sh           |   1 +
 .../retrieval_tool/docker/retrieval_tool.py   |  61 -------
 AgentQnA/retrieval_tool/index_data.py         |   3 -
 .../docker/xeon/docker_compose.yaml           |  15 +-
 6 files changed, 10 insertions(+), 254 deletions(-)
 delete mode 100644 AgentQnA/retrieval_tool/docker/Dockerfile_retrievaltool
 delete mode 100644 AgentQnA/retrieval_tool/docker/docker-compose-retrieval-tool.yaml
 delete mode 100644 AgentQnA/retrieval_tool/docker/retrieval_tool.py

diff --git a/AgentQnA/retrieval_tool/docker/Dockerfile_retrievaltool b/AgentQnA/retrieval_tool/docker/Dockerfile_retrievaltool
deleted file mode 100644
index f4c6627cda..0000000000
--- a/AgentQnA/retrieval_tool/docker/Dockerfile_retrievaltool
+++ /dev/null
@@ -1,31 +0,0 @@
-# Copyright (C) 2024 Intel Corporation
-# SPDX-License-Identifier: Apache-2.0
-
-FROM python:3.11-slim
-
-RUN apt-get update -y && apt-get install -y --no-install-recommends --fix-missing \
-    libgl1-mesa-glx \
-    libjemalloc-dev \
-    vim \
-    git
-
-RUN useradd -m -s /bin/bash user && \
-    mkdir -p /home/user && \
-    chown -R user /home/user/
-
-RUN cd /home/user/ && \
-    git clone https://github.com/opea-project/GenAIComps.git
-
-RUN cd /home/user/GenAIComps && pip install --no-cache-dir --upgrade pip && \
-    pip install -r /home/user/GenAIComps/requirements.txt
-
-RUN mkdir -p /home/user/script
-COPY ./retrieval_tool.py /home/user/script/retrieval_tool.py
-
-ENV PYTHONPATH=$PYTHONPATH:/home/user/GenAIComps
-
-USER user
-
-WORKDIR /home/user/script
-
-ENTRYPOINT ["python", "retrieval_tool.py"]
\ No newline at end of file
diff --git a/AgentQnA/retrieval_tool/docker/docker-compose-retrieval-tool.yaml b/AgentQnA/retrieval_tool/docker/docker-compose-retrieval-tool.yaml
deleted file mode 100644
index 66926e0a60..0000000000
--- a/AgentQnA/retrieval_tool/docker/docker-compose-retrieval-tool.yaml
+++ /dev/null
@@ -1,153 +0,0 @@
-
-# Copyright (C) 2024 Intel Corporation
-# SPDX-License-Identifier: Apache-2.0
-
-version: "3.8"
-
-services:
-  redis-vector-db:
-    image: redis/redis-stack:7.2.0-v9
-    container_name: redis-vector-db
-    ports:
-      - "6379:6379"
-      - "8001:8001"
-  tei-embedding-service:
-    image: ghcr.io/huggingface/text-embeddings-inference:cpu-1.2
-    container_name: tei-embedding-server
-    ports:
-      - "6006:80"
-    volumes:
-      - ${HF_CACHE_DIR}:/data
-    shm_size: 1g
-    environment:
-      no_proxy: ${no_proxy}
-      http_proxy: ${http_proxy}
-      https_proxy: ${https_proxy}
-    command: --model-id ${EMBEDDING_MODEL_ID} --auto-truncate
-  embedding:
-    image: opea/embedding-tei:latest
-    container_name: embedding-tei-server
-    # volumes:
-    #   - ${WORKDIR}/GenAIComps/comps/:/home/user/comps
-    depends_on:
-      - tei-embedding-service
-    ports:
-      - "6000:6000"
-    ipc: host
-    environment:
-      no_proxy: ${no_proxy}
-      http_proxy: ${http_proxy}
-      https_proxy: ${https_proxy}
-      TEI_EMBEDDING_ENDPOINT: ${TEI_EMBEDDING_ENDPOINT}
-      LANGCHAIN_API_KEY: ${LANGCHAIN_API_KEY}
-      LANGCHAIN_TRACING_V2: ${LANGCHAIN_TRACING_V2}
-      LANGCHAIN_PROJECT: "opea-embedding-service"
-    restart: unless-stopped
-  retriever:
-    image: opea/retriever-redis:latest
-    container_name: retriever-redis-server
-    # volumes:
-    #   - ${WORKDIR}/GenAIComps/comps/:/home/user/comps
-    depends_on:
-      - redis-vector-db
-    ports:
-      - "7000:7000"
-    ipc: host
-    environment:
-      no_proxy: ${no_proxy}
-      http_proxy: ${http_proxy}
-      https_proxy: ${https_proxy}
-      REDIS_URL: ${REDIS_URL}
-      INDEX_NAME: ${INDEX_NAME}
-      TEI_EMBEDDING_ENDPOINT: ${TEI_EMBEDDING_ENDPOINT}
-      LANGCHAIN_API_KEY: ${LANGCHAIN_API_KEY}
-      LANGCHAIN_TRACING_V2: ${LANGCHAIN_TRACING_V2}
-      LANGCHAIN_PROJECT: "opea-retriever-service"
-    restart: unless-stopped
-  tei-reranking-service:
-    image: ghcr.io/huggingface/text-embeddings-inference:cpu-1.2
-    container_name: tei-reranking-server
-    ports:
-      - "8808:80"
-    volumes:
-      - ${HF_CACHE_DIR}:/data
-    shm_size: 1g
-    environment:
-      no_proxy: ${no_proxy}
-      http_proxy: ${http_proxy}
-      https_proxy: ${https_proxy}
-      HUGGINGFACEHUB_API_TOKEN: ${HUGGINGFACEHUB_API_TOKEN}
-      HF_HUB_DISABLE_PROGRESS_BARS: 1
-      HF_HUB_ENABLE_HF_TRANSFER: 0
-    command: --model-id ${RERANK_MODEL_ID} --auto-truncate
-  reranking:
-    image: opea/reranking-tei:latest
-    container_name: reranking-tei-xeon-server
-    # volumes:
-    #   - ${WORKDIR}/GenAIComps/comps/:/home/user/comps
-    depends_on:
-      - tei-reranking-service
-    ports:
-      - "8000:8000"
-    ipc: host
-    environment:
-      no_proxy: ${no_proxy}
-      http_proxy: ${http_proxy}
-      https_proxy: ${https_proxy}
-      TEI_RERANKING_ENDPOINT: ${TEI_RERANKING_ENDPOINT}
-      HUGGINGFACEHUB_API_TOKEN: ${HUGGINGFACEHUB_API_TOKEN}
-      HF_HUB_DISABLE_PROGRESS_BARS: 1
-      HF_HUB_ENABLE_HF_TRANSFER: 0
-      LANGCHAIN_API_KEY: ${LANGCHAIN_API_KEY}
-      LANGCHAIN_TRACING_V2: ${LANGCHAIN_TRACING_V2}
-      LANGCHAIN_PROJECT: "opea-reranking-service"
-    restart: unless-stopped
-
-  dataprep-redis-service:
-    image: opea/dataprep-redis:latest
-    container_name: dataprep-redis-server
-    # volumes:
-    #   - ${WORKDIR}/GenAIComps/comps/:/home/user/comps/
-    depends_on:
-      - redis-vector-db
-    ports:
-      - "6007:6007"
-      - "6008:6008"
-      - "6009:6009"
-    environment:
-      no_proxy: ${no_proxy}
-      http_proxy: ${http_proxy}
-      https_proxy: ${https_proxy}
-      REDIS_URL: ${REDIS_URL}
-      INDEX_NAME: ${INDEX_NAME}
-      TEI_ENDPOINT: ${TEI_EMBEDDING_ENDPOINT}
-
-  retrievaltool-xeon-backend-server:
-    image: opea/retrievaltool:latest
-    container_name: retrievaltool-xeon-backend-server
-    # volumes:
-    #   - ${WORKDIR}/GenAIComps/comps/:/home/user/GenAIComps/comps/
-    #   - ${WORKDIR}/GenAIExamples/AgentQnA/retrieval_tool/docker/:/home/user/script/
-    depends_on:
-      - redis-vector-db
-      - tei-embedding-service
-      - embedding
-      - retriever
-      - tei-reranking-service
-      - reranking
-    ports:
-      - "8889:8889"
-    environment:
-      - no_proxy=${no_proxy}
-      - https_proxy=${https_proxy}
-      - http_proxy=${http_proxy}
-      - MEGA_SERVICE_HOST_IP=${MEGA_SERVICE_HOST_IP}
-      - EMBEDDING_SERVICE_HOST_IP=${EMBEDDING_SERVICE_HOST_IP}
-      - RETRIEVER_SERVICE_HOST_IP=${RETRIEVER_SERVICE_HOST_IP}
-      - RERANK_SERVICE_HOST_IP=${RERANK_SERVICE_HOST_IP}
-    ipc: host
-    restart: always
-
-networks:
-  default:
-    driver: bridge
diff --git a/AgentQnA/retrieval_tool/docker/launch_retrieval_tool.sh b/AgentQnA/retrieval_tool/docker/launch_retrieval_tool.sh
index 0c47dd3cce..5f062cc070 100644
--- a/AgentQnA/retrieval_tool/docker/launch_retrieval_tool.sh
+++ b/AgentQnA/retrieval_tool/docker/launch_retrieval_tool.sh
@@ -3,6 +3,7 @@
 
 host_ip=$(hostname -I | awk '{print $1}')
 export HF_CACHE_DIR=${HF_CACHE_DIR}
+export HUGGINGFACEHUB_API_TOKEN=${HUGGINGFACEHUB_API_TOKEN}
 export no_proxy=${no_proxy}
 export http_proxy=${http_proxy}
 export https_proxy=${https_proxy}
diff --git a/AgentQnA/retrieval_tool/docker/retrieval_tool.py b/AgentQnA/retrieval_tool/docker/retrieval_tool.py
deleted file mode 100644
index b2b766f118..0000000000
--- a/AgentQnA/retrieval_tool/docker/retrieval_tool.py
+++ /dev/null
@@ -1,61 +0,0 @@
-# Copyright (C) 2024 Intel Corporation
-# SPDX-License-Identifier: Apache-2.0
-
-import asyncio
-import os
-
-from comps import MicroService, RetrievalToolGateway, ServiceOrchestrator, ServiceType
-
-MEGA_SERVICE_HOST_IP = os.getenv("MEGA_SERVICE_HOST_IP", "0.0.0.0")
-MEGA_SERVICE_PORT = os.getenv("MEGA_SERVICE_PORT", 8889)
-EMBEDDING_SERVICE_HOST_IP = os.getenv("EMBEDDING_SERVICE_HOST_IP", "0.0.0.0")
-EMBEDDING_SERVICE_PORT = os.getenv("EMBEDDING_SERVICE_PORT", 6000)
-RETRIEVER_SERVICE_HOST_IP = os.getenv("RETRIEVER_SERVICE_HOST_IP", "0.0.0.0")
-RETRIEVER_SERVICE_PORT = os.getenv("RETRIEVER_SERVICE_PORT", 7000)
-RERANK_SERVICE_HOST_IP = os.getenv("RERANK_SERVICE_HOST_IP", "0.0.0.0")
-RERANK_SERVICE_PORT = os.getenv("RERANK_SERVICE_PORT", 8000)
-
-
-class RetrievalToolService:
-    def __init__(self, host="0.0.0.0", port=8000):
-        self.host = host
-        self.port = port
-        self.megaservice = ServiceOrchestrator()
-
-    def add_remote_service(self):
-        embedding = MicroService(
-            name="embedding",
-            host=EMBEDDING_SERVICE_HOST_IP,
-            port=EMBEDDING_SERVICE_PORT,
-            endpoint="/v1/embeddings",
-            use_remote_service=True,
-            service_type=ServiceType.EMBEDDING,
-        )
-        retriever = MicroService(
-            name="retriever",
-            host=RETRIEVER_SERVICE_HOST_IP,
-            port=RETRIEVER_SERVICE_PORT,
-            endpoint="/v1/retrieval",
-            use_remote_service=True,
-            service_type=ServiceType.RETRIEVER,
-        )
-        rerank = MicroService(
-            name="rerank",
-            host=RERANK_SERVICE_HOST_IP,
-            port=RERANK_SERVICE_PORT,
-            endpoint="/v1/reranking",
-            use_remote_service=True,
-            service_type=ServiceType.RERANK,
-        )
-
-        self.megaservice.add(embedding).add(retriever).add(rerank)
-        self.megaservice.flow_to(embedding, retriever)
-        self.megaservice.flow_to(retriever, rerank)
-
-        # self.megaservice.add(embedding)
-        self.gateway = RetrievalToolGateway(megaservice=self.megaservice, host="0.0.0.0", port=self.port)
-
-
-if __name__ == "__main__":
-    chatqna = RetrievalToolService(host=MEGA_SERVICE_HOST_IP, port=MEGA_SERVICE_PORT)
-    chatqna.add_remote_service()
diff --git a/AgentQnA/retrieval_tool/index_data.py b/AgentQnA/retrieval_tool/index_data.py
index 755eb68539..410a83cfb1 100644
--- a/AgentQnA/retrieval_tool/index_data.py
+++ b/AgentQnA/retrieval_tool/index_data.py
@@ -28,9 +28,6 @@ def split_jsonl_into_txts(jsonl_file):
         for line in f:
             data = json.loads(line)
             docs.append(data["doc"])
-            # n+=1
-            # if n>2:
-            #     break
     return docs
 
 
diff --git a/DocIndexRetriever/docker/xeon/docker_compose.yaml b/DocIndexRetriever/docker/xeon/docker_compose.yaml
index 54e0ae687e..038444971a 100644
--- a/DocIndexRetriever/docker/xeon/docker_compose.yaml
+++ b/DocIndexRetriever/docker/xeon/docker_compose.yaml
@@ -40,7 +40,7 @@ services:
       http_proxy: ${http_proxy}
       https_proxy: ${https_proxy}
       HUGGINGFACEHUB_API_TOKEN: ${HUGGINGFACEHUB_API_TOKEN}
-    command: --model-id ${EMBEDDING_MODEL_ID}
+    command: --model-id ${EMBEDDING_MODEL_ID} --auto-truncate
   embedding:
     image: opea/embedding-tei:latest
     container_name: embedding-tei-server
@@ -86,7 +86,7 @@ services:
     ports:
       - "8808:80"
     volumes:
-      - ${HF_CACHE_DIR}:/data
+      - "./data:/data"
     shm_size: 1g
     environment:
       no_proxy: ${no_proxy}
@@ -95,11 +95,13 @@ services:
       HUGGINGFACEHUB_API_TOKEN: ${HUGGINGFACEHUB_API_TOKEN}
       HF_HUB_DISABLE_PROGRESS_BARS: 1
       HF_HUB_ENABLE_HF_TRANSFER: 0
-    command: --model-id ${RERANK_MODEL_ID}
+    command: --model-id ${RERANK_MODEL_ID} --auto-truncate
 
   reranking:
     image: opea/reranking-tei:latest
     container_name: reranking-tei-xeon-server
+    volumes:
+      - ${WORKDIR}/GenAIComps/comps/:/home/user/comps
     depends_on:
       - tei-reranking-service
     ports:
@@ -125,13 +127,14 @@ services:
       - tei-embedding-service
       - embedding
       - retriever
+      - tei-reranking-service
       - reranking
     ports:
       - "8889:8889"
     environment:
-      # - no_proxy=${no_proxy}
-      # - https_proxy=${https_proxy}
-      # - http_proxy=${http_proxy}
+      - no_proxy=${no_proxy}
+      - https_proxy=${https_proxy}
+      - http_proxy=${http_proxy}
       - MEGA_SERVICE_HOST_IP=${MEGA_SERVICE_HOST_IP}
       - EMBEDDING_SERVICE_HOST_IP=${EMBEDDING_SERVICE_HOST_IP}
       - RETRIEVER_SERVICE_HOST_IP=${RETRIEVER_SERVICE_HOST_IP}

From 9ab800954a99bda3c68bc556c950a804a4e1b9a4 Mon Sep 17 00:00:00 2001
From: "Chendi.Xue" <chendi.xue@intel.com>
Date: Mon, 9 Sep 2024 19:49:06 +0000
Subject: [PATCH 26/39] update on UT

Signed-off-by: Chendi.Xue <chendi.xue@intel.com>
---
 .../retrieval_tool/docker/build_images.sh     | 79 +++++++++++++------
 AgentQnA/tests/1_build_images.sh              | 31 ++------
 AgentQnA/tests/test_agentqna_on_gaudi.sh      | 45 ++++++++---
 3 files changed, 92 insertions(+), 63 deletions(-)

diff --git a/AgentQnA/retrieval_tool/docker/build_images.sh b/AgentQnA/retrieval_tool/docker/build_images.sh
index d0bc5ed98f..8f7f0f0ecf 100644
--- a/AgentQnA/retrieval_tool/docker/build_images.sh
+++ b/AgentQnA/retrieval_tool/docker/build_images.sh
@@ -1,27 +1,58 @@
 # Copyright (C) 2024 Intel Corporation
 # SPDX-License-Identifier: Apache-2.0
 
-cd ${WORKDIR}/GenAIComps/
-echo $PWD
-
-# echo "==============Building dataprep image================="
-# docker build --no-cache -t opea/dataprep-redis:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/dataprep/redis/langchain/docker/Dockerfile .
-# echo "==============Successfully built dataprep image================="
-
-# echo "==============Building embedding-tei image================="
-# docker build --no-cache -t opea/embedding-tei:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/embeddings/langchain/docker/Dockerfile .
-# echo "==============Successfully built embedding-tei image================="
-
-# echo "==============Building retriever-redis image================="
-# docker build --no-cache -t opea/retriever-redis:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/retrievers/langchain/redis/docker/Dockerfile .
-# echo "==============Successfully built retriever-redis image================="
-
-# echo "==============Building reranking-tei image================="
-# docker build --no-cache -t opea/reranking-tei:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/reranks/tei/docker/Dockerfile .
-# echo "==============Successfully built reranking-tei image================="
-
-cd $WORKDIR
-echo $PWD
-echo "==============Building retrieval-tool image================="
-docker build --no-cache -t opea/doc-index-retriever:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f GenAIExamples/DocIndexRetriever/docker/Dockerfile .
-echo "==============Successfully built retrieval-tool image================="
+set -e
+WORKPATH=$(dirname "$PWD")/..
+export WORKDIR=$WORKPATH/../../
+echo "WORKDIR=${WORKDIR}"
+export ip_address=$(hostname -I | awk '{print $1}')
+
+function get_genai_comps() {
+    cd $WORKPATH/docker
+    echo "current_path: $PWD"
+    if [ ! -d "GenAIComps" ] ; then
+        git clone https://github.com/opea-project/GenAIComps.git
+    fi
+}
+
+function build_docker_images_for_retrieval_tool(){
+    cd $WORKPATH/docker/GenAIComps/
+    echo $PWD
+    echo "==============Building dataprep image================="
+    docker build -t opea/dataprep-on-ray-redis:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/dataprep/redis/langchain_ray/docker/Dockerfile .
+    echo "==============Successfully built dataprep image================="
+
+    echo "==============Building embedding-tei image================="
+    docker build -t opea/embedding-tei:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/embeddings/langchain/docker/Dockerfile .
+    echo "==============Successfully built embedding-tei image================="
+
+    echo "==============Building retriever-redis image================="
+    docker build -t opea/retriever-redis:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/retrievers/langchain/redis/docker/Dockerfile .
+    echo "==============Successfully built retriever-redis image================="
+
+    echo "==============Building reranking-tei image================="
+    docker build -t opea/reranking-tei:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/reranks/tei/docker/Dockerfile .
+    echo "==============Successfully built reranking-tei image================="
+
+    docker pull ghcr.io/huggingface/tgi-gaudi:latest
+    docker pull redis/redis-stack:7.2.0-v9
+
+    RETRIEVAL_TOOL_PATH=$WORKPATH/../DocIndexRetriever
+    cd $RETRIEVAL_TOOL_PATH/docker/
+    echo "==============Building retrieval-tool image================="
+    docker build -t opea/doc-index-retriever:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f ./Dockerfile .
+    echo "==============Successfully built retrieval-tool image================="
+}
+
+
+function main() {
+    echo "==================== Get GenAI components ===================="
+    get_genai_comps
+    echo "==================== GenAI components downloaded ===================="
+
+    echo "==================== Build docker images for retrieval tool ===================="
+    build_docker_images_for_retrieval_tool
+    echo "==================== Build docker images for retrieval tool completed ===================="
+}
+
+main
\ No newline at end of file
diff --git a/AgentQnA/tests/1_build_images.sh b/AgentQnA/tests/1_build_images.sh
index a2255ad382..86f61a1a1b 100644
--- a/AgentQnA/tests/1_build_images.sh
+++ b/AgentQnA/tests/1_build_images.sh
@@ -10,35 +10,18 @@ export ip_address=$(hostname -I | awk '{print $1}')
 
 
 function get_genai_comps() {
-    cd $WORKDIR
+    cd $WORKPATH/docker
     if [ ! -d "GenAIComps" ] ; then
         git clone https://github.com/opea-project/GenAIComps.git
     fi
 }
 
 function build_docker_images_for_retrieval_tool(){
-    cd $WORKDIR/GenAIComps/
-    echo $PWD
-    echo "==============Building dataprep image================="
-    docker build --no-cache -t opea/dataprep-redis:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/dataprep/redis/langchain/docker/Dockerfile .
-    echo "==============Successfully built dataprep image================="
-
-    echo "==============Building embedding-tei image================="
-    docker build --no-cache -t opea/embedding-tei:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/embeddings/langchain/docker/Dockerfile .
-    echo "==============Successfully built embedding-tei image================="
-
-    echo "==============Building retriever-redis image================="
-    docker build --no-cache -t opea/retriever-redis:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/retrievers/langchain/redis/docker/Dockerfile .
-    echo "==============Successfully built retriever-redis image================="
-
-    echo "==============Building reranking-tei image================="
-    docker build --no-cache -t opea/reranking-tei:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/reranks/tei/docker/Dockerfile .
-    echo "==============Successfully built reranking-tei image================="
-
-    cd $WORKDIR/GenAIExamples/AgentQnA/retrieval_tool/docker/
-    echo $PWD
+    RETRIEVAL_TOOL_PATH=$WORKPATH/retrieval_tool
+    cd $RETRIEVAL_TOOL_PATH/docker/
     echo "==============Building retrieval-tool image================="
-    docker build --no-cache -t opea/retrievaltool:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f Dockerfile_retrievaltool .
+    echo "current_path: $PWD"
+    bash build_images.sh
     echo "==============Successfully built retrieval-tool image================="
 }
 
@@ -47,10 +30,6 @@ function build_agent_docker_image() {
     docker build -t opea/comps-agent-langchain:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/agent/langchain/docker/Dockerfile .
 }
 
-
-
-
-
 function main() {
 
     echo "==================== Get GenAI components ===================="
diff --git a/AgentQnA/tests/test_agentqna_on_gaudi.sh b/AgentQnA/tests/test_agentqna_on_gaudi.sh
index 1fd7bd14b5..818ec23a6a 100644
--- a/AgentQnA/tests/test_agentqna_on_gaudi.sh
+++ b/AgentQnA/tests/test_agentqna_on_gaudi.sh
@@ -10,23 +10,44 @@ echo "WORKDIR=${WORKDIR}"
 export ip_address=$(hostname -I | awk '{print $1}')
 export HUGGINGFACEHUB_API_TOKEN=${HUGGINGFACEHUB_API_TOKEN}
 
-function stop_agent_and_api_server() {
-    echo "Stopping CRAG server"
-    docker stop $(docker ps -q --filter ancestor=docker.io/aicrowd/kdd-cup-24-crag-mock-api:v0)
-    echo "Stopping Agent services"
-    docker compose -f $WORKDIR/GenAIExamples/AgentQnA/docker/gaudi/compose.yaml down
+function stop_crag() {
+    container_list=$(docker ps -q --filter ancestor=docker.io/aicrowd/kdd-cup-24-crag-mock-api:v0)
+    for container_name in $container_list; do
+        cid=$(docker ps -aq --filter "name=$container_name")
+        echo "Stopping container $container_name"
+        if [[ ! -z "$cid" ]]; then docker stop $cid && sleep 1s; fi
+    done
+}
+
+function stop_docker() {
+    cd $WORKPATH/docker/gaudi
+    container_list=$(cat compose.yaml | grep container_name | cut -d':' -f2)
+    for container_name in $container_list; do
+        cid=$(docker ps -aq --filter "name=$container_name")
+        echo "Stopping container $container_name"
+        if [[ ! -z "$cid" ]]; then docker rm $cid -f && sleep 1s; fi
+    done
 }
 
 function stop_retrieval_tool() {
     echo "Stopping Retrieval tool"
-    docker compose -f $WORKDIR/GenAIExamples/AgentQnA/retrieval_tool/docker/docker-compose-retrieval-tool.yaml down
+    local RETRIEVAL_TOOL_PATH=$WORKPATH/../DocIndexRetriever
+    cd $RETRIEVAL_TOOL_PATH/docker/gaudi
+    container_list=$(cat docker_compose.yaml | grep container_name | cut -d':' -f2)
+    for container_name in $container_list; do
+        cid=$(docker ps -aq --filter "name=$container_name")
+        echo "Stopping container $container_name"
+        if [[ ! -z "$cid" ]]; then docker rm $cid -f && sleep 1s; fi
+    done
 }
-
+echo "workpath: $WORKPATH"
 echo "=================== Stop containers ===================="
-stop_agent_and_api_server
+stop_crag
+stop_docker
 stop_retrieval_tool
 
 echo "=================== #1 Building docker images===================="
+cd $WORKPATH/tests
 bash 1_build_images.sh
 echo "=================== #1 Building docker images completed===================="
 
@@ -43,11 +64,9 @@ bash 4_launch_and_validate_agent_tgi.sh
 echo "=================== #4 Agent test passed ===================="
 
 echo "=================== #5 Stop agent and API server===================="
-stop_agent_and_api_server
-echo "=================== #5 Agent and API server stopped===================="
-
-echo "=================== #6 Stop retrieval tool===================="
+stop_crag
+stop_docker
 stop_retrieval_tool
-echo "=================== #6 Retrieval tool stopped===================="
+echo "=================== #5 Agent and API server stopped===================="
 
 echo "ALL DONE!"

From 88f1470a6df1ba863c0704cd2d016de2584e492c Mon Sep 17 00:00:00 2001
From: chensuyue <suyue.chen@intel.com>
Date: Wed, 4 Sep 2024 14:07:05 +0800
Subject: [PATCH 27/39] update image build Signed-off-by: chensuyue
 <suyue.chen@intel.com>

Signed-off-by: chensuyue <suyue.chen@intel.com>

update image build
Signed-off-by: chensuyue <suyue.chen@intel.com>

Signed-off-by: chensuyue <suyue.chen@intel.com>

[pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

fix DocIndexRetriever
Signed-off-by: chensuyue <suyue.chen@intel.com>

Signed-off-by: chensuyue <suyue.chen@intel.com>

[pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

Fix CICD

Signed-off-by: Chendi.Xue <chendi.xue@intel.com>
---
 DocIndexRetriever/docker/Dockerfile           |  2 +-
 DocIndexRetriever/docker/README.md            |  3 +-
 .../docker/docker_build_compose.yaml          | 36 +++++++++++++++++++
 .../docker/gaudi/docker_compose.yaml          |  2 +-
 .../docker/xeon/docker_compose.yaml           |  1 -
 .../tests/test_docindexretriever_on_gaudi.sh  |  7 ++--
 .../docker/docker_build_compose.yaml          | 10 +++---
 .../tests/test_productivitysuite_on_xeon.sh   |  3 +-
 8 files changed, 49 insertions(+), 15 deletions(-)
 create mode 100644 DocIndexRetriever/docker/docker_build_compose.yaml

diff --git a/DocIndexRetriever/docker/Dockerfile b/DocIndexRetriever/docker/Dockerfile
index 45294d7250..1c1b4789e3 100644
--- a/DocIndexRetriever/docker/Dockerfile
+++ b/DocIndexRetriever/docker/Dockerfile
@@ -21,7 +21,7 @@ WORKDIR /home/user/GenAIComps
 RUN pip install --no-cache-dir --upgrade pip && \
     pip install --no-cache-dir -r /home/user/GenAIComps/requirements.txt
 
-COPY GenAIExamples/DocIndexRetriever/docker/retrieval_tool.py /home/user/retrieval_tool.py
+COPY ./retrieval_tool.py /home/user/retrieval_tool.py
 
 ENV PYTHONPATH=$PYTHONPATH:/home/user/GenAIComps
 
diff --git a/DocIndexRetriever/docker/README.md b/DocIndexRetriever/docker/README.md
index cd884112fd..aaa29208b4 100644
--- a/DocIndexRetriever/docker/README.md
+++ b/DocIndexRetriever/docker/README.md
@@ -35,7 +35,8 @@ DocRetriever are the most widely adopted use case for leveraging the different m
 ```bash
 cd ..
 git clone https://github.com/opea-project/GenAIExamples.git
-docker build --no-cache -t opea/doc-index-retriever:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f GenAIExamples/DocIndexRetriever/docker/Dockerfile .
+cd GenAIExamples/DocIndexRetriever/docker
+docker build --no-cache -t opea/doc-index-retriever:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f ./Dockerfile .
 ```
 
 ## 3. Start all the services Docker Containers
diff --git a/DocIndexRetriever/docker/docker_build_compose.yaml b/DocIndexRetriever/docker/docker_build_compose.yaml
new file mode 100644
index 0000000000..6f603f61c9
--- /dev/null
+++ b/DocIndexRetriever/docker/docker_build_compose.yaml
@@ -0,0 +1,36 @@
+# Copyright (C) 2024 Intel Corporation
+# SPDX-License-Identifier: Apache-2.0
+
+services:
+  doc-index-retriever:
+    build:
+      args:
+        http_proxy: ${http_proxy}
+        https_proxy: ${https_proxy}
+        no_proxy: ${no_proxy}
+      dockerfile: ./Dockerfile
+    image: ${REGISTRY:-opea}/doc-index-retriever:${TAG:-latest}
+  embedding-tei:
+    build:
+      context: GenAIComps
+      dockerfile: comps/embeddings/langchain/docker/Dockerfile
+    extends: doc-index-retriever
+    image: ${REGISTRY:-opea}/embedding-tei:${TAG:-latest}
+  retriever-redis:
+    build:
+      context: GenAIComps
+      dockerfile: comps/retrievers/langchain/redis/docker/Dockerfile
+    extends: chatqna
+    image: ${REGISTRY:-opea}/retriever-redis:${TAG:-latest}
+  reranking-tei:
+    build:
+      context: GenAIComps
+      dockerfile: comps/reranks/tei/docker/Dockerfile
+    extends: doc-index-retriever
+    image: ${REGISTRY:-opea}/reranking-tei:${TAG:-latest}
+  dataprep-on-ray-redis:
+    build:
+      context: GenAIComps
+      dockerfile: comps/dataprep/redis/langchain_ray/docker/Dockerfile
+    extends: doc-index-retriever
+    image: ${REGISTRY:-opea}/dataprep-on-ray-redis:${TAG:-latest}
diff --git a/DocIndexRetriever/docker/gaudi/docker_compose.yaml b/DocIndexRetriever/docker/gaudi/docker_compose.yaml
index 34eb62e46e..76bd24f35b 100644
--- a/DocIndexRetriever/docker/gaudi/docker_compose.yaml
+++ b/DocIndexRetriever/docker/gaudi/docker_compose.yaml
@@ -82,7 +82,7 @@ services:
     image: opea/reranking-tei:latest
     container_name: reranking-tei-server
     ports:
-      - "18000:8000"
+      - "8000:8000"
     ipc: host
     entrypoint: python local_reranking.py
     environment:
diff --git a/DocIndexRetriever/docker/xeon/docker_compose.yaml b/DocIndexRetriever/docker/xeon/docker_compose.yaml
index f4e0ed0c07..71e894d559 100644
--- a/DocIndexRetriever/docker/xeon/docker_compose.yaml
+++ b/DocIndexRetriever/docker/xeon/docker_compose.yaml
@@ -1,4 +1,3 @@
-
 # Copyright (C) 2024 Intel Corporation
 # SPDX-License-Identifier: Apache-2.0
 
diff --git a/DocIndexRetriever/tests/test_docindexretriever_on_gaudi.sh b/DocIndexRetriever/tests/test_docindexretriever_on_gaudi.sh
index 76231d89d6..fe71a0bab2 100644
--- a/DocIndexRetriever/tests/test_docindexretriever_on_gaudi.sh
+++ b/DocIndexRetriever/tests/test_docindexretriever_on_gaudi.sh
@@ -10,12 +10,11 @@ LOG_PATH="$WORKPATH/tests"
 ip_address=$(hostname -I | awk '{print $1}')
 
 function build_docker_images() {
-    cd $WORKPATH/../../
+    cd $WORKPATH/docker
     if [ ! -d "GenAIComps" ] ; then
         git clone https://github.com/opea-project/GenAIComps.git
     fi
     cd GenAIComps
-    git status
 
     docker build -t opea/embedding-tei:latest -f comps/embeddings/langchain/docker/Dockerfile .
     docker build -t opea/retriever-redis:latest -f comps/retrievers/langchain/redis/docker/Dockerfile .
@@ -25,8 +24,8 @@ function build_docker_images() {
     docker pull ghcr.io/huggingface/tgi-gaudi:latest
     docker pull redis/redis-stack:7.2.0-v9
 
-    cd $WORKPATH/../../
-    docker build -t opea/doc-index-retriever:latest -f GenAIExamples/DocIndexRetriever/docker/Dockerfile .
+    cd $WORKPATH/docker
+    docker build -t opea/doc-index-retriever:latest -f ./Dockerfile .
 }
 
 function start_services() {
diff --git a/ProductivitySuite/docker/docker_build_compose.yaml b/ProductivitySuite/docker/docker_build_compose.yaml
index 4b205a361f..87519188b1 100644
--- a/ProductivitySuite/docker/docker_build_compose.yaml
+++ b/ProductivitySuite/docker/docker_build_compose.yaml
@@ -41,19 +41,19 @@ services:
       dockerfile: comps/dataprep/redis/langchain/docker/Dockerfile
     extends: chatqna
     image: ${REGISTRY:-opea}/dataprep-redis:${TAG:-latest}
-  promptregistry-mongo:
+  promptregistry-mongo-server:
     build:
       context: GenAIComps
       dockerfile: comps/prompt_registry/mongo/docker/Dockerfile
     extends: chatqna
     image: ${REGISTRY:-opea}/promptregistry-mongo-server:${TAG:-latest}
-  chathistory-mongo:
+  chathistory-mongo-server:
     build:
       context: GenAIComps
       dockerfile: comps/chathistory/mongo/docker/Dockerfile
     extends: chatqna
     image: ${REGISTRY:-opea}/chathistory-mongo-server:${TAG:-latest}
-  productivity-suite-react-ui:
+  productivity-suite-react-ui-server:
     build:
       context: ui
       dockerfile: ./docker/Dockerfile.react
@@ -86,13 +86,13 @@ services:
       context: ../../FaqGen/docker/
       dockerfile: ./Dockerfile
     image: ${REGISTRY:-opea}/faqgen:${TAG:-latest}
-  llm_faqgen:
+  llm-faqgen-tgi:
     build:
       context: GenAIComps
       dockerfile: comps/llms/faq-generation/tgi/Dockerfile
     extends: faqgen
     image: ${REGISTRY:-opea}/llm-faqgen-tgi:${TAG:-latest}
-  llm_docsum_server:
+  llm-docsum-tgi:
     build:
       context: GenAIComps
       dockerfile: comps/llms/summarization/tgi/Dockerfile
diff --git a/ProductivitySuite/tests/test_productivitysuite_on_xeon.sh b/ProductivitySuite/tests/test_productivitysuite_on_xeon.sh
index e1f6bb4881..ecfa7659c7 100755
--- a/ProductivitySuite/tests/test_productivitysuite_on_xeon.sh
+++ b/ProductivitySuite/tests/test_productivitysuite_on_xeon.sh
@@ -19,8 +19,7 @@ function build_docker_images() {
     git clone https://github.com/opea-project/GenAIComps.git
 
     echo "Build all the images with --no-cache, check docker_image_build.log for details..."
-    service_list="chatqna dataprep-redis embedding-tei promptregistry-mongo llm_docsum_server llm_faqgen chathistory-mongo retriever-redis reranking-tei llm-tgi productivity-suite-react-ui codegen docsum faqgen"
-    docker compose -f docker_build_compose.yaml build ${service_list} --no-cache > ${LOG_PATH}/docker_image_build.log
+    docker compose -f docker_build_compose.yaml build --no-cache > ${LOG_PATH}/docker_image_build.log
 
     docker pull ghcr.io/huggingface/text-embeddings-inference:cpu-1.5
     docker pull ghcr.io/huggingface/text-generation-inference:2.1.0

From d0b76fb67180451c27f581a544f6d8c6b3f50900 Mon Sep 17 00:00:00 2001
From: "Chendi.Xue" <chendi.xue@intel.com>
Date: Mon, 9 Sep 2024 20:52:39 +0000
Subject: [PATCH 28/39] update CICD

Signed-off-by: Chendi.Xue <chendi.xue@intel.com>
---
 AgentQnA/docker/gaudi/compose.yaml            |  2 +-
 .../gaudi/launch_agent_service_tgi_gaudi.sh   | 19 +++++++++++++++++++
 .../4_launch_and_validate_agent_openai.sh     |  2 +-
 .../tests/4_launch_and_validate_agent_tgi.sh  |  5 +----
 AgentQnA/tests/test_agentqna_on_gaudi.sh      | 11 ++++-------
 5 files changed, 26 insertions(+), 13 deletions(-)

diff --git a/AgentQnA/docker/gaudi/compose.yaml b/AgentQnA/docker/gaudi/compose.yaml
index 2b475e5023..2d5b8e1285 100644
--- a/AgentQnA/docker/gaudi/compose.yaml
+++ b/AgentQnA/docker/gaudi/compose.yaml
@@ -23,7 +23,7 @@ services:
     cap_add:
       - SYS_NICE
     ipc: host
-    command: --model-id ${LLM_MODEL_ID} --max-input-length 4096 --max-total-tokens 8192 --sharded true --num-shard 4
+    command: --model-id ${LLM_MODEL_ID} --max-input-length 4096 --max-total-tokens 8192 --sharded true --num-shard ${NUM_SHARDS}
   worker-docgrader-agent:
     image: opea/comps-agent-langchain:latest
     container_name: docgrader-agent-endpoint
diff --git a/AgentQnA/docker/gaudi/launch_agent_service_tgi_gaudi.sh b/AgentQnA/docker/gaudi/launch_agent_service_tgi_gaudi.sh
index c2ccedb3b1..128bd5d0ea 100644
--- a/AgentQnA/docker/gaudi/launch_agent_service_tgi_gaudi.sh
+++ b/AgentQnA/docker/gaudi/launch_agent_service_tgi_gaudi.sh
@@ -1,12 +1,17 @@
 # Copyright (C) 2024 Intel Corporation
 # SPDX-License-Identifier: Apache-2.0
 
+WORKPATH=$(dirname "$PWD")/..
+export WORKDIR=$WORKPATH/../../
+echo "WORKDIR=${WORKDIR}"
 export ip_address=$(hostname -I | awk '{print $1}')
+export HUGGINGFACEHUB_API_TOKEN=${HUGGINGFACEHUB_API_TOKEN}
 
 # LLM related environment variables
 export HF_CACHE_DIR=${HF_CACHE_DIR}
 export HUGGINGFACEHUB_API_TOKEN=${HUGGINGFACEHUB_API_TOKEN}
 export LLM_MODEL_ID="meta-llama/Meta-Llama-3.1-70B-Instruct"
+export NUM_SHARDS=4
 export LLM_ENDPOINT_URL="http://${ip_address}:8085"
 export temperature=0.01
 export max_new_tokens=512
@@ -20,3 +25,17 @@ export RETRIEVAL_TOOL_URL="http://${ip_address}:8889/v1/retrievaltool"
 export CRAG_SERVER=http://${ip_address}:8080
 
 docker compose -f compose.yaml up -d
+
+sleep 5s
+echo "Waiting tgi gaudi ready"
+n=0
+until [[ "$n" -ge 100 ]] || [[ $ready == true ]]; do
+    docker logs tgi-server &> ${WORKPATH}/tests/tgi-gaudi-service.log
+    n=$((n+1))
+    if grep -q Connected ${WORKPATH}/tests/tgi-gaudi-service.log; then
+        break
+    fi
+    sleep 5s
+done
+sleep 5s
+echo "Service started successfully"
diff --git a/AgentQnA/tests/4_launch_and_validate_agent_openai.sh b/AgentQnA/tests/4_launch_and_validate_agent_openai.sh
index 2c37291301..fb9a8949f1 100644
--- a/AgentQnA/tests/4_launch_and_validate_agent_openai.sh
+++ b/AgentQnA/tests/4_launch_and_validate_agent_openai.sh
@@ -13,7 +13,7 @@ export TOOLSET_PATH=$WORKDIR/GenAIExamples/AgentQnA/tools/
 
 function start_agent_and_api_server() {
     echo "Starting CRAG server"
-    docker run -d -p=8080:8000 docker.io/aicrowd/kdd-cup-24-crag-mock-api:v0
+    docker run -d --runtime=runc --name=kdd-cup-24-crag-service -p=8080:8000 docker.io/aicrowd/kdd-cup-24-crag-mock-api:v0
 
     echo "Starting Agent services"
     cd $WORKDIR/GenAIExamples/AgentQnA/docker/openai
diff --git a/AgentQnA/tests/4_launch_and_validate_agent_tgi.sh b/AgentQnA/tests/4_launch_and_validate_agent_tgi.sh
index 410ac5fb54..0148f829a7 100644
--- a/AgentQnA/tests/4_launch_and_validate_agent_tgi.sh
+++ b/AgentQnA/tests/4_launch_and_validate_agent_tgi.sh
@@ -20,7 +20,7 @@ ls $HF_CACHE_DIR
 
 function start_agent_and_api_server() {
     echo "Starting CRAG server"
-    docker run -d -p=8080:8000 docker.io/aicrowd/kdd-cup-24-crag-mock-api:v0
+    docker run -d --runtime=runc --name=kdd-cup-24-crag-service -p=8080:8000 docker.io/aicrowd/kdd-cup-24-crag-mock-api:v0
 
     echo "Starting Agent services"
     cd $WORKDIR/GenAIExamples/AgentQnA/docker/gaudi
@@ -66,9 +66,6 @@ function validate_agent_service() {
 function main() {
     echo "==================== Start agent ===================="
     start_agent_and_api_server
-    echo "Waiting for LLM endpoint to be ready"
-    sleep 300
-    docker logs tgi-server
     echo "==================== Agent started ===================="
 
     echo "==================== Validate agent service ===================="
diff --git a/AgentQnA/tests/test_agentqna_on_gaudi.sh b/AgentQnA/tests/test_agentqna_on_gaudi.sh
index 818ec23a6a..3d639a9385 100644
--- a/AgentQnA/tests/test_agentqna_on_gaudi.sh
+++ b/AgentQnA/tests/test_agentqna_on_gaudi.sh
@@ -11,12 +11,9 @@ export ip_address=$(hostname -I | awk '{print $1}')
 export HUGGINGFACEHUB_API_TOKEN=${HUGGINGFACEHUB_API_TOKEN}
 
 function stop_crag() {
-    container_list=$(docker ps -q --filter ancestor=docker.io/aicrowd/kdd-cup-24-crag-mock-api:v0)
-    for container_name in $container_list; do
-        cid=$(docker ps -aq --filter "name=$container_name")
-        echo "Stopping container $container_name"
-        if [[ ! -z "$cid" ]]; then docker stop $cid && sleep 1s; fi
-    done
+    cid=$(docker ps -aq --filter "name=kdd-cup-24-crag-service")
+    echo "Stopping container kdd-cup-24-crag-service with cid $cid"
+    if [[ ! -z "$cid" ]]; then docker rm $cid -f && sleep 1s; fi
 }
 
 function stop_docker() {
@@ -48,7 +45,7 @@ stop_retrieval_tool
 
 echo "=================== #1 Building docker images===================="
 cd $WORKPATH/tests
-bash 1_build_images.sh
+#bash 1_build_images.sh
 echo "=================== #1 Building docker images completed===================="
 
 echo "=================== #2 Start retrieval tool===================="

From 2510966667de87a9e45de1e7a1d5eb5995b7a749 Mon Sep 17 00:00:00 2001
From: "pre-commit-ci[bot]"
 <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Date: Mon, 9 Sep 2024 21:03:58 +0000
Subject: [PATCH 29/39] [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci
---
 AgentQnA/retrieval_tool/docker/build_images.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/AgentQnA/retrieval_tool/docker/build_images.sh b/AgentQnA/retrieval_tool/docker/build_images.sh
index 8f7f0f0ecf..0f22084357 100644
--- a/AgentQnA/retrieval_tool/docker/build_images.sh
+++ b/AgentQnA/retrieval_tool/docker/build_images.sh
@@ -55,4 +55,4 @@ function main() {
     echo "==================== Build docker images for retrieval tool completed ===================="
 }
 
-main
\ No newline at end of file
+main

From f5a6471e95c72f2fab4c44f7131ab3cdf272c43e Mon Sep 17 00:00:00 2001
From: "Chendi.Xue" <chendi.xue@intel.com>
Date: Mon, 9 Sep 2024 21:40:43 +0000
Subject: [PATCH 30/39] fix haolint issue

Signed-off-by: Chendi.Xue <chendi.xue@intel.com>
---
 AgentQnA/tests/test_agentqna_on_gaudi.sh | 2 +-
 DocIndexRetriever/docker/Dockerfile      | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/AgentQnA/tests/test_agentqna_on_gaudi.sh b/AgentQnA/tests/test_agentqna_on_gaudi.sh
index 3d639a9385..776673a88a 100644
--- a/AgentQnA/tests/test_agentqna_on_gaudi.sh
+++ b/AgentQnA/tests/test_agentqna_on_gaudi.sh
@@ -45,7 +45,7 @@ stop_retrieval_tool
 
 echo "=================== #1 Building docker images===================="
 cd $WORKPATH/tests
-#bash 1_build_images.sh
+bash 1_build_images.sh
 echo "=================== #1 Building docker images completed===================="
 
 echo "=================== #2 Start retrieval tool===================="
diff --git a/DocIndexRetriever/docker/Dockerfile b/DocIndexRetriever/docker/Dockerfile
index 1c1b4789e3..ecbe6166e1 100644
--- a/DocIndexRetriever/docker/Dockerfile
+++ b/DocIndexRetriever/docker/Dockerfile
@@ -13,8 +13,8 @@ RUN useradd -m -s /bin/bash user && \
     chown -R user /home/user/
 
 
-RUN cd /home/user/ && \
-    git clone https://github.com/opea-project/GenAIComps.git
+WORKDIR /home/user/
+RUN git clone https://github.com/opea-project/GenAIComps.git
 
 
 WORKDIR /home/user/GenAIComps

From 09e25344afbe2ddec0ca93a6ce50151ba90bc637 Mon Sep 17 00:00:00 2001
From: "Chendi.Xue" <chendi.xue@intel.com>
Date: Tue, 10 Sep 2024 03:08:12 +0000
Subject: [PATCH 31/39] revert DocIndexRetriever change

Signed-off-by: Chendi.Xue <chendi.xue@intel.com>
---
 DocIndexRetriever/docker/Dockerfile | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/DocIndexRetriever/docker/Dockerfile b/DocIndexRetriever/docker/Dockerfile
index ecbe6166e1..7c9b49e302 100644
--- a/DocIndexRetriever/docker/Dockerfile
+++ b/DocIndexRetriever/docker/Dockerfile
@@ -3,6 +3,8 @@
 
 FROM python:3.11-slim
 
+COPY GenAIComps /home/user/GenAIComps
+
 RUN apt-get update -y && apt-get install -y --no-install-recommends --fix-missing \
     libgl1-mesa-glx \
     libjemalloc-dev \
@@ -12,11 +14,6 @@ RUN useradd -m -s /bin/bash user && \
     mkdir -p /home/user && \
     chown -R user /home/user/
 
-
-WORKDIR /home/user/
-RUN git clone https://github.com/opea-project/GenAIComps.git
-
-
 WORKDIR /home/user/GenAIComps
 RUN pip install --no-cache-dir --upgrade pip && \
     pip install --no-cache-dir -r /home/user/GenAIComps/requirements.txt

From d102c14e1bb5b55cece39134a12bb07ef288ce9b Mon Sep 17 00:00:00 2001
From: "Chendi.Xue" <chendi.xue@intel.com>
Date: Tue, 10 Sep 2024 03:18:16 +0000
Subject: [PATCH 32/39] download genaicomps for DocIndexRetriever

Signed-off-by: Chendi.Xue <chendi.xue@intel.com>
---
 AgentQnA/retrieval_tool/docker/build_images.sh | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/AgentQnA/retrieval_tool/docker/build_images.sh b/AgentQnA/retrieval_tool/docker/build_images.sh
index 0f22084357..1b1ab34cd9 100644
--- a/AgentQnA/retrieval_tool/docker/build_images.sh
+++ b/AgentQnA/retrieval_tool/docker/build_images.sh
@@ -39,6 +39,9 @@ function build_docker_images_for_retrieval_tool(){
 
     RETRIEVAL_TOOL_PATH=$WORKPATH/../DocIndexRetriever
     cd $RETRIEVAL_TOOL_PATH/docker/
+    if [ ! -d "GenAIComps" ] ; then
+        git clone https://github.com/opea-project/GenAIComps.git
+    fi
     echo "==============Building retrieval-tool image================="
     docker build -t opea/doc-index-retriever:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f ./Dockerfile .
     echo "==============Successfully built retrieval-tool image================="

From b0ef81b92269cfa7a44f334f715d8702f92053f4 Mon Sep 17 00:00:00 2001
From: "pre-commit-ci[bot]"
 <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Date: Tue, 10 Sep 2024 18:29:52 +0000
Subject: [PATCH 33/39] [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci
---
 AgentQnA/docker_image_build/build.yaml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/AgentQnA/docker_image_build/build.yaml b/AgentQnA/docker_image_build/build.yaml
index 9804ffdb5c..1522660190 100644
--- a/AgentQnA/docker_image_build/build.yaml
+++ b/AgentQnA/docker_image_build/build.yaml
@@ -10,4 +10,4 @@ services:
         http_proxy: ${http_proxy}
         https_proxy: ${https_proxy}
         no_proxy: ${no_proxy}
-    image: ${REGISTRY:-opea}/comps-agent-langchain:${TAG:-latest}
\ No newline at end of file
+    image: ${REGISTRY:-opea}/comps-agent-langchain:${TAG:-latest}

From cb5cf48d655cbb9911e9e2e68405cdb8c5622e3b Mon Sep 17 00:00:00 2001
From: minmin-intel <minmin.hou@intel.com>
Date: Tue, 10 Sep 2024 18:34:33 +0000
Subject: [PATCH 34/39] reorg folder and update test

Signed-off-by: minmin-intel <minmin.hou@intel.com>
---
 .../intel/hpu}/gaudi/compose.yaml             |   0
 .../gaudi/launch_agent_service_tgi_gaudi.sh   |   0
 AgentQnA/docker_image_build/build.yaml        |  13 +++
 .../{docker => }/launch_retrieval_tool.sh     |   2 +-
 AgentQnA/tests/1_build_images.sh              |  31 +++---
 AgentQnA/tests/2_start_retrieval_tool.sh      |   2 +-
 AgentQnA/tests/run_test_agent_service.sh      |   8 --
 AgentQnA/tests/src/commons.py                 |   4 -
 AgentQnA/tests/src/test_agent_service.py      | 105 ------------------
 ...a_on_gaudi.sh => test_compose_on_gaudi.sh} |  48 ++++----
 .../intel/cpu/xeon/compose.yaml               |   4 +-
 .../docker_image_build/build.yaml             |   8 +-
 12 files changed, 62 insertions(+), 163 deletions(-)
 rename AgentQnA/{docker => docker_compose/intel/hpu}/gaudi/compose.yaml (100%)
 rename AgentQnA/{docker => docker_compose/intel/hpu}/gaudi/launch_agent_service_tgi_gaudi.sh (100%)
 create mode 100644 AgentQnA/docker_image_build/build.yaml
 rename AgentQnA/retrieval_tool/{docker => }/launch_retrieval_tool.sh (96%)
 delete mode 100644 AgentQnA/tests/run_test_agent_service.sh
 delete mode 100644 AgentQnA/tests/src/commons.py
 delete mode 100644 AgentQnA/tests/src/test_agent_service.py
 rename AgentQnA/tests/{test_agentqna_on_gaudi.sh => test_compose_on_gaudi.sh} (57%)

diff --git a/AgentQnA/docker/gaudi/compose.yaml b/AgentQnA/docker_compose/intel/hpu/gaudi/compose.yaml
similarity index 100%
rename from AgentQnA/docker/gaudi/compose.yaml
rename to AgentQnA/docker_compose/intel/hpu/gaudi/compose.yaml
diff --git a/AgentQnA/docker/gaudi/launch_agent_service_tgi_gaudi.sh b/AgentQnA/docker_compose/intel/hpu/gaudi/launch_agent_service_tgi_gaudi.sh
similarity index 100%
rename from AgentQnA/docker/gaudi/launch_agent_service_tgi_gaudi.sh
rename to AgentQnA/docker_compose/intel/hpu/gaudi/launch_agent_service_tgi_gaudi.sh
diff --git a/AgentQnA/docker_image_build/build.yaml b/AgentQnA/docker_image_build/build.yaml
new file mode 100644
index 0000000000..9804ffdb5c
--- /dev/null
+++ b/AgentQnA/docker_image_build/build.yaml
@@ -0,0 +1,13 @@
+# Copyright (C) 2024 Intel Corporation
+# SPDX-License-Identifier: Apache-2.0
+
+services:
+  agent-endpoint:
+    build:
+      context: GenAIComps
+      dockerfile: comps/agent/langchain/Dockerfile
+      args:
+        http_proxy: ${http_proxy}
+        https_proxy: ${https_proxy}
+        no_proxy: ${no_proxy}
+    image: ${REGISTRY:-opea}/comps-agent-langchain:${TAG:-latest}
\ No newline at end of file
diff --git a/AgentQnA/retrieval_tool/docker/launch_retrieval_tool.sh b/AgentQnA/retrieval_tool/launch_retrieval_tool.sh
similarity index 96%
rename from AgentQnA/retrieval_tool/docker/launch_retrieval_tool.sh
rename to AgentQnA/retrieval_tool/launch_retrieval_tool.sh
index 5f062cc070..1a142abf8e 100644
--- a/AgentQnA/retrieval_tool/docker/launch_retrieval_tool.sh
+++ b/AgentQnA/retrieval_tool/launch_retrieval_tool.sh
@@ -22,4 +22,4 @@ export DATAPREP_SERVICE_ENDPOINT="http://${host_ip}:6007/v1/dataprep"
 export DATAPREP_GET_FILE_ENDPOINT="http://${host_ip}:6008/v1/dataprep/get_file"
 export DATAPREP_DELETE_FILE_ENDPOINT="http://${host_ip}:6009/v1/dataprep/delete_file"
 
-docker compose -f $WORKDIR/GenAIExamples/DocIndexRetriever/docker/xeon/docker_compose.yaml up -d
+docker compose -f $WORKDIR/GenAIExamples/DocIndexRetriever/docker_compose/intel/cpu/xeon/compose.yaml up -d
diff --git a/AgentQnA/tests/1_build_images.sh b/AgentQnA/tests/1_build_images.sh
index 86f61a1a1b..abac17682b 100644
--- a/AgentQnA/tests/1_build_images.sh
+++ b/AgentQnA/tests/1_build_images.sh
@@ -10,32 +10,33 @@ export ip_address=$(hostname -I | awk '{print $1}')
 
 
 function get_genai_comps() {
-    cd $WORKPATH/docker
     if [ ! -d "GenAIComps" ] ; then
-        git clone https://github.com/opea-project/GenAIComps.git
+        git clone https://github.com/opea-project/GenAIComps.git && cd GenAIComps && git checkout "${opea_branch:-"main"}" && cd ../
     fi
 }
 
+
 function build_docker_images_for_retrieval_tool(){
-    RETRIEVAL_TOOL_PATH=$WORKPATH/retrieval_tool
-    cd $RETRIEVAL_TOOL_PATH/docker/
-    echo "==============Building retrieval-tool image================="
-    echo "current_path: $PWD"
-    bash build_images.sh
-    echo "==============Successfully built retrieval-tool image================="
+    cd $WORKDIR/GenAIExamples/DocIndexRetriever/docker_image_build/
+    # git clone https://github.com/opea-project/GenAIComps.git && cd GenAIComps && git checkout "${opea_branch:-"main"}" && cd ../
+    get_genai_comps
+    echo "Build all the images with --no-cache..."
+    service_list="doc-index-retriever dataprep-redis embedding-tei retriever-redis reranking-tei"
+    docker compose -f build.yaml build ${service_list} --no-cache
+    docker pull ghcr.io/huggingface/text-embeddings-inference:cpu-1.5
+
+    docker images && sleep 1s
 }
 
 function build_agent_docker_image() {
-    cd $WORKDIR/GenAIComps
-    docker build -t opea/comps-agent-langchain:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/agent/langchain/docker/Dockerfile .
+    cd $WORKDIR/GenAIExamples/AgentQnA/docker_image_build/
+    get_genai_comps
+    echo "Build agent image with --no-cache..."
+    service_list="agent-endpoint"
+    docker compose -f build.yaml build ${service_list} --no-cache
 }
 
 function main() {
-
-    echo "==================== Get GenAI components ===================="
-    get_genai_comps
-    echo "==================== GenAI components downloaded ===================="
-
     echo "==================== Build docker images for retrieval tool ===================="
     build_docker_images_for_retrieval_tool
     echo "==================== Build docker images for retrieval tool completed ===================="
diff --git a/AgentQnA/tests/2_start_retrieval_tool.sh b/AgentQnA/tests/2_start_retrieval_tool.sh
index 66d5c8108d..df080e40d8 100644
--- a/AgentQnA/tests/2_start_retrieval_tool.sh
+++ b/AgentQnA/tests/2_start_retrieval_tool.sh
@@ -16,7 +16,7 @@ fi
 
 function start_retrieval_tool() {
     echo "Starting Retrieval tool"
-    cd $WORKDIR/GenAIExamples/AgentQnA/retrieval_tool/docker/
+    cd $WORKDIR/GenAIExamples/AgentQnA/retrieval_tool/
     bash launch_retrieval_tool.sh
 }
 
diff --git a/AgentQnA/tests/run_test_agent_service.sh b/AgentQnA/tests/run_test_agent_service.sh
deleted file mode 100644
index 4f9828f7e6..0000000000
--- a/AgentQnA/tests/run_test_agent_service.sh
+++ /dev/null
@@ -1,8 +0,0 @@
-# Copyright (C) 2024 Intel Corporation
-# SPDX-License-Identifier: Apache-2.0
-
-QUERYFILE=$WORKDIR/datasets/crag_qas/crag_20_answerable_queries.csv
-OUTFILE=$WORKDIR/datasets/crag_results/validation_5outof20.jsonl
-PORT=9095
-
-python src/test_agent_service.py --query_file $QUERYFILE --output_file $OUTFILE --port $PORT #--quick_test
diff --git a/AgentQnA/tests/src/commons.py b/AgentQnA/tests/src/commons.py
deleted file mode 100644
index 09c38489f3..0000000000
--- a/AgentQnA/tests/src/commons.py
+++ /dev/null
@@ -1,4 +0,0 @@
-# Copyright (C) 2024 Intel Corporation
-# SPDX-License-Identifier: Apache-2.0
-
-QUERY_SEPERATOR = "========THIS IS A NEW QUERY========"
diff --git a/AgentQnA/tests/src/test_agent_service.py b/AgentQnA/tests/src/test_agent_service.py
deleted file mode 100644
index efe190b7f5..0000000000
--- a/AgentQnA/tests/src/test_agent_service.py
+++ /dev/null
@@ -1,105 +0,0 @@
-# Copyright (C) 2024 Intel Corporation
-# SPDX-License-Identifier: Apache-2.0
-
-import argparse
-import json
-import os
-
-import pandas as pd
-import requests
-from commons import QUERY_SEPERATOR
-
-
-def get_test_data(args):
-    if args.query_file.endswith(".jsonl"):
-        df = pd.read_json(args.query_file, lines=True, convert_dates=False)
-    elif args.query_file.endswith(".csv"):
-        df = pd.read_csv(args.query_file)
-    return df
-
-
-def generate_answer(url, prompt):
-    proxies = {"http": ""}
-    payload = {
-        "query": prompt,
-    }
-    response = requests.post(url, json=payload, proxies=proxies)
-    answer = response.json()["text"]
-    return answer
-
-
-def save_results(output_file, output_list):
-    with open(output_file, "w") as f:
-        for output in output_list:
-            f.write(json.dumps(output))
-            f.write("\n")
-
-
-def save_as_csv(output):
-    df = pd.read_json(output, lines=True, convert_dates=False)
-    df.to_csv(output.replace(".jsonl", ".csv"), index=False)
-
-
-if __name__ == "__main__":
-    parser = argparse.ArgumentParser()
-    parser.add_argument("--host_ip", type=str, default="localhost", help="host ip of the retrieval tool")
-    parser.add_argument("--port", type=str, default="9095", help="port of the retrieval tool")
-    parser.add_argument("--query_file", type=str, default=None, help="query jsonl file")
-    parser.add_argument("--output_file", type=str, default="output.jsonl", help="output jsonl file")
-    parser.add_argument("--quick_test", action="store_true", help="run quick test")
-    args = parser.parse_args()
-
-    host_ip = args.host_ip
-    port = args.port
-    endpoint = "{port}/v1/chat/completions".format(port=port)
-    url = "http://{host_ip}:{endpoint}".format(host_ip=host_ip, endpoint=endpoint)
-
-    if args.quick_test:
-        query = [
-            "Taylor Swift hometown",
-            # "how many songs has the band the beatles released that have been recorded at abbey road studios?",
-            # "what's the most recent album from the founder of ysl records?",
-            # "when did dolly parton's song, blown away, come out?"
-            # "what song topped the billboard chart on 2004-02-04?",
-            # "what grammy award did edgar barrera win this year?",
-            # "who has had more number one hits on the us billboard hot 100 chart, michael jackson or elvis presley?",
-        ]
-        query_time = [
-            "08/11/2024, 23:37:29 PT",
-            # "03/21/2024, 23:37:29 PT",
-            # "03/21/2024, 23:37:29 PT",
-            # "03/21/2024, 23:37:29 PT",
-        ]
-        df = pd.DataFrame({"query": query, "query_time": query_time})
-    else:
-        df = get_test_data(args)
-        df = df.head()  # for validation purpose
-
-    output_list = []
-    n = 0
-    for _, row in df.iterrows():
-        q = row["query"]
-        t = row["query_time"]
-        prompt = "Question: {}\nThe question was asked at: {}".format(q, t)
-        print(QUERY_SEPERATOR)
-        print("******Query:\n", prompt)
-        print("******Agent is working on the query")
-        answer = generate_answer(url, prompt)
-        print("******Answer from agent:\n", answer)
-        print("=" * 50)
-        output_list.append(
-            {
-                "query": q,
-                "query_time": t,
-                # "ref_answer": row["answer"],
-                "answer": answer,
-                # "question_type": row["question_type"],
-                # "static_or_dynamic": row["static_or_dynamic"],
-            }
-        )
-        save_results(args.output_file, output_list)
-        # n += 1
-        # if n > 1:
-        #     break
-    save_results(args.output_file, output_list)
-    save_as_csv(args.output_file)
diff --git a/AgentQnA/tests/test_agentqna_on_gaudi.sh b/AgentQnA/tests/test_compose_on_gaudi.sh
similarity index 57%
rename from AgentQnA/tests/test_agentqna_on_gaudi.sh
rename to AgentQnA/tests/test_compose_on_gaudi.sh
index 776673a88a..c5f2f82f02 100644
--- a/AgentQnA/tests/test_agentqna_on_gaudi.sh
+++ b/AgentQnA/tests/test_compose_on_gaudi.sh
@@ -16,8 +16,8 @@ function stop_crag() {
     if [[ ! -z "$cid" ]]; then docker rm $cid -f && sleep 1s; fi
 }
 
-function stop_docker() {
-    cd $WORKPATH/docker/gaudi
+function stop_agent_docker() {
+    cd $WORKPATH/docker_compose/intel/hpu/gaudi
     container_list=$(cat compose.yaml | grep container_name | cut -d':' -f2)
     for container_name in $container_list; do
         cid=$(docker ps -aq --filter "name=$container_name")
@@ -29,24 +29,26 @@ function stop_docker() {
 function stop_retrieval_tool() {
     echo "Stopping Retrieval tool"
     local RETRIEVAL_TOOL_PATH=$WORKPATH/../DocIndexRetriever
-    cd $RETRIEVAL_TOOL_PATH/docker/gaudi
-    container_list=$(cat docker_compose.yaml | grep container_name | cut -d':' -f2)
-    for container_name in $container_list; do
-        cid=$(docker ps -aq --filter "name=$container_name")
-        echo "Stopping container $container_name"
-        if [[ ! -z "$cid" ]]; then docker rm $cid -f && sleep 1s; fi
-    done
+    cd $RETRIEVAL_TOOL_PATH/docker_compose/intel/cpu/xeon/
+    # container_list=$(cat compose.yaml | grep container_name | cut -d':' -f2)
+    # for container_name in $container_list; do
+    #     cid=$(docker ps -aq --filter "name=$container_name")
+    #     echo "Stopping container $container_name"
+    #     if [[ ! -z "$cid" ]]; then docker rm $cid -f && sleep 1s; fi
+    # done
+    docker compose -f compose.yaml down
 }
 echo "workpath: $WORKPATH"
 echo "=================== Stop containers ===================="
-stop_crag
-stop_docker
+# stop_crag
+# stop_agent_docker
 stop_retrieval_tool
 
-echo "=================== #1 Building docker images===================="
 cd $WORKPATH/tests
-bash 1_build_images.sh
-echo "=================== #1 Building docker images completed===================="
+
+# echo "=================== #1 Building docker images===================="
+# bash 1_build_images.sh
+# echo "=================== #1 Building docker images completed===================="
 
 echo "=================== #2 Start retrieval tool===================="
 bash 2_start_retrieval_tool.sh
@@ -56,14 +58,14 @@ echo "=================== #3 Ingest data and validate retrieval=================
 bash 3_ingest_data_and_validate_retrieval.sh
 echo "=================== #3 Data ingestion and validation completed===================="
 
-echo "=================== #4 Start agent and API server===================="
-bash 4_launch_and_validate_agent_tgi.sh
-echo "=================== #4 Agent test passed ===================="
+# echo "=================== #4 Start agent and API server===================="
+# bash 4_launch_and_validate_agent_tgi.sh
+# echo "=================== #4 Agent test passed ===================="
 
-echo "=================== #5 Stop agent and API server===================="
-stop_crag
-stop_docker
-stop_retrieval_tool
-echo "=================== #5 Agent and API server stopped===================="
+# echo "=================== #5 Stop agent and API server===================="
+# stop_crag
+# stop_docker
+# stop_retrieval_tool
+# echo "=================== #5 Agent and API server stopped===================="
 
-echo "ALL DONE!"
+# echo "ALL DONE!"
diff --git a/DocIndexRetriever/docker_compose/intel/cpu/xeon/compose.yaml b/DocIndexRetriever/docker_compose/intel/cpu/xeon/compose.yaml
index 71e894d559..5f66bb7423 100644
--- a/DocIndexRetriever/docker_compose/intel/cpu/xeon/compose.yaml
+++ b/DocIndexRetriever/docker_compose/intel/cpu/xeon/compose.yaml
@@ -27,7 +27,7 @@ services:
       INDEX_NAME: ${INDEX_NAME}
       TEI_ENDPOINT: ${TEI_EMBEDDING_ENDPOINT}
   tei-embedding-service:
-    image: ghcr.io/huggingface/text-embeddings-inference:cpu-1.2
+    image: ghcr.io/huggingface/text-embeddings-inference:cpu-1.5
     container_name: tei-embedding-server
     ports:
       - "6006:80"
@@ -80,7 +80,7 @@ services:
     restart: unless-stopped
 
   tei-reranking-service:
-    image: ghcr.io/huggingface/text-embeddings-inference:cpu-1.2
+    image: ghcr.io/huggingface/text-embeddings-inference:cpu-1.5
     container_name: tei-reranking-server
     ports:
       - "8808:80"
diff --git a/DocIndexRetriever/docker_image_build/build.yaml b/DocIndexRetriever/docker_image_build/build.yaml
index 07005e89ae..3ed44fa24a 100644
--- a/DocIndexRetriever/docker_image_build/build.yaml
+++ b/DocIndexRetriever/docker_image_build/build.yaml
@@ -21,7 +21,7 @@ services:
     build:
       context: GenAIComps
       dockerfile: comps/retrievers/redis/langchain/Dockerfile
-    extends: chatqna
+    extends: doc-index-retriever
     image: ${REGISTRY:-opea}/retriever-redis:${TAG:-latest}
   reranking-tei:
     build:
@@ -29,9 +29,9 @@ services:
       dockerfile: comps/reranks/tei/Dockerfile
     extends: doc-index-retriever
     image: ${REGISTRY:-opea}/reranking-tei:${TAG:-latest}
-  dataprep-on-ray-redis:
+  dataprep-redis:
     build:
       context: GenAIComps
-      dockerfile: comps/dataprep/redis/langchain_ray/Dockerfile
+      dockerfile: comps/dataprep/redis/langchain/Dockerfile
     extends: doc-index-retriever
-    image: ${REGISTRY:-opea}/dataprep-on-ray-redis:${TAG:-latest}
+    image: ${REGISTRY:-opea}/dataprep-redis:${TAG:-latest}

From c63c1153f91e1346c52cfc59dc230fdfbdbbc028 Mon Sep 17 00:00:00 2001
From: "pre-commit-ci[bot]"
 <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Date: Tue, 10 Sep 2024 18:50:56 +0000
Subject: [PATCH 35/39] [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci
---
 AgentQnA/retrieval_tool/README.md | 1 +
 1 file changed, 1 insertion(+)

diff --git a/AgentQnA/retrieval_tool/README.md b/AgentQnA/retrieval_tool/README.md
index 3dfc49c84b..fc5a2da43c 100644
--- a/AgentQnA/retrieval_tool/README.md
+++ b/AgentQnA/retrieval_tool/README.md
@@ -3,6 +3,7 @@
 The retrieval tool in this example is an OPEA megaservice that is comprised of a query embedder, a document retriever and a document reranker.
 
 ## Launch microservices
+
 ```
 bash launch_retrieval_tool.sh
 ```

From e3038a2b08c774826c68523ab4c6a9d8e60683a3 Mon Sep 17 00:00:00 2001
From: minmin-intel <minmin.hou@intel.com>
Date: Tue, 10 Sep 2024 18:54:46 +0000
Subject: [PATCH 36/39] update test script

Signed-off-by: minmin-intel <minmin.hou@intel.com>
---
 .../gaudi/launch_agent_service_tgi_gaudi.sh   |  8 ++-
 AgentQnA/retrieval_tool/README.md             | 12 +---
 .../retrieval_tool/docker/build_images.sh     | 61 -------------------
 .../tests/4_launch_and_validate_agent_tgi.sh  |  2 +-
 AgentQnA/tests/test_compose_on_gaudi.sh       | 37 +++++------
 5 files changed, 26 insertions(+), 94 deletions(-)
 delete mode 100644 AgentQnA/retrieval_tool/docker/build_images.sh

diff --git a/AgentQnA/docker_compose/intel/hpu/gaudi/launch_agent_service_tgi_gaudi.sh b/AgentQnA/docker_compose/intel/hpu/gaudi/launch_agent_service_tgi_gaudi.sh
index 128bd5d0ea..f4154fb229 100644
--- a/AgentQnA/docker_compose/intel/hpu/gaudi/launch_agent_service_tgi_gaudi.sh
+++ b/AgentQnA/docker_compose/intel/hpu/gaudi/launch_agent_service_tgi_gaudi.sh
@@ -2,13 +2,14 @@
 # SPDX-License-Identifier: Apache-2.0
 
 WORKPATH=$(dirname "$PWD")/..
-export WORKDIR=$WORKPATH/../../
+# export WORKDIR=$WORKPATH/../../
 echo "WORKDIR=${WORKDIR}"
 export ip_address=$(hostname -I | awk '{print $1}')
 export HUGGINGFACEHUB_API_TOKEN=${HUGGINGFACEHUB_API_TOKEN}
 
 # LLM related environment variables
 export HF_CACHE_DIR=${HF_CACHE_DIR}
+ls $HF_CACHE_DIR
 export HUGGINGFACEHUB_API_TOKEN=${HUGGINGFACEHUB_API_TOKEN}
 export LLM_MODEL_ID="meta-llama/Meta-Llama-3.1-70B-Instruct"
 export NUM_SHARDS=4
@@ -18,6 +19,7 @@ export max_new_tokens=512
 
 # agent related environment variables
 export TOOLSET_PATH=$WORKDIR/GenAIExamples/AgentQnA/tools/
+echo "TOOLSET_PATH=${TOOLSET_PATH}"
 export recursion_limit_worker=12
 export recursion_limit_supervisor=10
 export WORKER_AGENT_URL="http://${ip_address}:9095/v1/chat/completions"
@@ -30,9 +32,9 @@ sleep 5s
 echo "Waiting tgi gaudi ready"
 n=0
 until [[ "$n" -ge 100 ]] || [[ $ready == true ]]; do
-    docker logs tgi-server &> ${WORKPATH}/tests/tgi-gaudi-service.log
+    docker logs tgi-server &> tgi-gaudi-service.log
     n=$((n+1))
-    if grep -q Connected ${WORKPATH}/tests/tgi-gaudi-service.log; then
+    if grep -q Connected tgi-gaudi-service.log; then
         break
     fi
     sleep 5s
diff --git a/AgentQnA/retrieval_tool/README.md b/AgentQnA/retrieval_tool/README.md
index 841d613443..3dfc49c84b 100644
--- a/AgentQnA/retrieval_tool/README.md
+++ b/AgentQnA/retrieval_tool/README.md
@@ -2,17 +2,7 @@
 
 The retrieval tool in this example is an OPEA megaservice that is comprised of a query embedder, a document retriever and a document reranker.
 
-## Follow the instructions here to launch microservices.
-
-1. Build images
-
-```
-cd docker
-build_images.sh
-```
-
-2. Launch services
-
+## Launch microservices
 ```
 bash launch_retrieval_tool.sh
 ```
diff --git a/AgentQnA/retrieval_tool/docker/build_images.sh b/AgentQnA/retrieval_tool/docker/build_images.sh
deleted file mode 100644
index 1b1ab34cd9..0000000000
--- a/AgentQnA/retrieval_tool/docker/build_images.sh
+++ /dev/null
@@ -1,61 +0,0 @@
-# Copyright (C) 2024 Intel Corporation
-# SPDX-License-Identifier: Apache-2.0
-
-set -e
-WORKPATH=$(dirname "$PWD")/..
-export WORKDIR=$WORKPATH/../../
-echo "WORKDIR=${WORKDIR}"
-export ip_address=$(hostname -I | awk '{print $1}')
-
-function get_genai_comps() {
-    cd $WORKPATH/docker
-    echo "current_path: $PWD"
-    if [ ! -d "GenAIComps" ] ; then
-        git clone https://github.com/opea-project/GenAIComps.git
-    fi
-}
-
-function build_docker_images_for_retrieval_tool(){
-    cd $WORKPATH/docker/GenAIComps/
-    echo $PWD
-    echo "==============Building dataprep image================="
-    docker build -t opea/dataprep-on-ray-redis:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/dataprep/redis/langchain_ray/docker/Dockerfile .
-    echo "==============Successfully built dataprep image================="
-
-    echo "==============Building embedding-tei image================="
-    docker build -t opea/embedding-tei:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/embeddings/langchain/docker/Dockerfile .
-    echo "==============Successfully built embedding-tei image================="
-
-    echo "==============Building retriever-redis image================="
-    docker build -t opea/retriever-redis:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/retrievers/langchain/redis/docker/Dockerfile .
-    echo "==============Successfully built retriever-redis image================="
-
-    echo "==============Building reranking-tei image================="
-    docker build -t opea/reranking-tei:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/reranks/tei/docker/Dockerfile .
-    echo "==============Successfully built reranking-tei image================="
-
-    docker pull ghcr.io/huggingface/tgi-gaudi:latest
-    docker pull redis/redis-stack:7.2.0-v9
-
-    RETRIEVAL_TOOL_PATH=$WORKPATH/../DocIndexRetriever
-    cd $RETRIEVAL_TOOL_PATH/docker/
-    if [ ! -d "GenAIComps" ] ; then
-        git clone https://github.com/opea-project/GenAIComps.git
-    fi
-    echo "==============Building retrieval-tool image================="
-    docker build -t opea/doc-index-retriever:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f ./Dockerfile .
-    echo "==============Successfully built retrieval-tool image================="
-}
-
-
-function main() {
-    echo "==================== Get GenAI components ===================="
-    get_genai_comps
-    echo "==================== GenAI components downloaded ===================="
-
-    echo "==================== Build docker images for retrieval tool ===================="
-    build_docker_images_for_retrieval_tool
-    echo "==================== Build docker images for retrieval tool completed ===================="
-}
-
-main
diff --git a/AgentQnA/tests/4_launch_and_validate_agent_tgi.sh b/AgentQnA/tests/4_launch_and_validate_agent_tgi.sh
index 0148f829a7..f7b36da2a3 100644
--- a/AgentQnA/tests/4_launch_and_validate_agent_tgi.sh
+++ b/AgentQnA/tests/4_launch_and_validate_agent_tgi.sh
@@ -23,7 +23,7 @@ function start_agent_and_api_server() {
     docker run -d --runtime=runc --name=kdd-cup-24-crag-service -p=8080:8000 docker.io/aicrowd/kdd-cup-24-crag-mock-api:v0
 
     echo "Starting Agent services"
-    cd $WORKDIR/GenAIExamples/AgentQnA/docker/gaudi
+    cd $WORKDIR/GenAIExamples/AgentQnA/docker_compose/intel/hpu/gaudi
     bash launch_agent_service_tgi_gaudi.sh
 }
 
diff --git a/AgentQnA/tests/test_compose_on_gaudi.sh b/AgentQnA/tests/test_compose_on_gaudi.sh
index c5f2f82f02..90dad74655 100644
--- a/AgentQnA/tests/test_compose_on_gaudi.sh
+++ b/AgentQnA/tests/test_compose_on_gaudi.sh
@@ -18,12 +18,13 @@ function stop_crag() {
 
 function stop_agent_docker() {
     cd $WORKPATH/docker_compose/intel/hpu/gaudi
-    container_list=$(cat compose.yaml | grep container_name | cut -d':' -f2)
-    for container_name in $container_list; do
-        cid=$(docker ps -aq --filter "name=$container_name")
-        echo "Stopping container $container_name"
-        if [[ ! -z "$cid" ]]; then docker rm $cid -f && sleep 1s; fi
-    done
+    # container_list=$(cat compose.yaml | grep container_name | cut -d':' -f2)
+    # for container_name in $container_list; do
+    #     cid=$(docker ps -aq --filter "name=$container_name")
+    #     echo "Stopping container $container_name"
+    #     if [[ ! -z "$cid" ]]; then docker rm $cid -f && sleep 1s; fi
+    # done
+    docker compose -f compose.yaml down
 }
 
 function stop_retrieval_tool() {
@@ -40,9 +41,9 @@ function stop_retrieval_tool() {
 }
 echo "workpath: $WORKPATH"
 echo "=================== Stop containers ===================="
-# stop_crag
-# stop_agent_docker
-stop_retrieval_tool
+stop_crag
+stop_agent_docker
+# stop_retrieval_tool
 
 cd $WORKPATH/tests
 
@@ -50,17 +51,17 @@ cd $WORKPATH/tests
 # bash 1_build_images.sh
 # echo "=================== #1 Building docker images completed===================="
 
-echo "=================== #2 Start retrieval tool===================="
-bash 2_start_retrieval_tool.sh
-echo "=================== #2 Retrieval tool started===================="
+# echo "=================== #2 Start retrieval tool===================="
+# bash 2_start_retrieval_tool.sh
+# echo "=================== #2 Retrieval tool started===================="
 
-echo "=================== #3 Ingest data and validate retrieval===================="
-bash 3_ingest_data_and_validate_retrieval.sh
-echo "=================== #3 Data ingestion and validation completed===================="
+# echo "=================== #3 Ingest data and validate retrieval===================="
+# bash 3_ingest_data_and_validate_retrieval.sh
+# echo "=================== #3 Data ingestion and validation completed===================="
 
-# echo "=================== #4 Start agent and API server===================="
-# bash 4_launch_and_validate_agent_tgi.sh
-# echo "=================== #4 Agent test passed ===================="
+echo "=================== #4 Start agent and API server===================="
+bash 4_launch_and_validate_agent_tgi.sh
+echo "=================== #4 Agent test passed ===================="
 
 # echo "=================== #5 Stop agent and API server===================="
 # stop_crag

From 6f551aa328110d6df7455266cb3ad6b815d79ac8 Mon Sep 17 00:00:00 2001
From: minmin-intel <minmin.hou@intel.com>
Date: Tue, 10 Sep 2024 21:47:21 +0000
Subject: [PATCH 37/39] update docker compose and test script

Signed-off-by: minmin-intel <minmin.hou@intel.com>
---
 .../intel/hpu/gaudi/compose.yaml              |  4 +-
 .../tests/4_launch_and_validate_agent_tgi.sh  | 16 +++----
 AgentQnA/tests/test_compose_on_gaudi.sh       | 47 +++++++------------
 3 files changed, 28 insertions(+), 39 deletions(-)

diff --git a/AgentQnA/docker_compose/intel/hpu/gaudi/compose.yaml b/AgentQnA/docker_compose/intel/hpu/gaudi/compose.yaml
index 2d5b8e1285..e68d7e9c3a 100644
--- a/AgentQnA/docker_compose/intel/hpu/gaudi/compose.yaml
+++ b/AgentQnA/docker_compose/intel/hpu/gaudi/compose.yaml
@@ -30,7 +30,7 @@ services:
     depends_on:
       - tgi-server
     volumes:
-      - ${WORKDIR}/GenAIComps/comps/agent/langchain/:/home/user/comps/agent/langchain/
+      # - ${WORKDIR}/GenAIExamples/AgentQnA/docker_image_build/GenAIComps/comps/agent/langchain/:/home/user/comps/agent/langchain/
       - ${TOOLSET_PATH}:/home/user/tools/
     ports:
       - "9095:9095"
@@ -65,7 +65,7 @@ services:
       - tgi-server
       - worker-docgrader-agent
     volumes:
-      - ${WORKDIR}/GenAIComps/comps/agent/langchain/:/home/user/comps/agent/langchain/
+      # - ${WORKDIR}/GenAIExamples/AgentQnA/docker_image_build/GenAIComps/comps/agent/langchain/:/home/user/comps/agent/langchain/
       - ${TOOLSET_PATH}:/home/user/tools/
     ports:
       - "9090:9090"
diff --git a/AgentQnA/tests/4_launch_and_validate_agent_tgi.sh b/AgentQnA/tests/4_launch_and_validate_agent_tgi.sh
index f7b36da2a3..03f20a9666 100644
--- a/AgentQnA/tests/4_launch_and_validate_agent_tgi.sh
+++ b/AgentQnA/tests/4_launch_and_validate_agent_tgi.sh
@@ -43,14 +43,14 @@ function validate() {
 
 function validate_agent_service() {
     echo "----------------Test agent ----------------"
-    local CONTENT=$(http_proxy="" curl http://${ip_address}:9095/v1/chat/completions -X POST -H "Content-Type: application/json" -d '{
-     "query": "Tell me about Michael Jackson song thriller"
-    }')
-    local EXIT_CODE=$(validate "$CONTENT" "Thriller" "react-agent-endpoint")
-    docker logs docgrader-agent-endpoint
-    if [ "$EXIT_CODE" == "1" ]; then
-        exit 1
-    fi
+    # local CONTENT=$(http_proxy="" curl http://${ip_address}:9095/v1/chat/completions -X POST -H "Content-Type: application/json" -d '{
+    #  "query": "Tell me about Michael Jackson song thriller"
+    # }')
+    # local EXIT_CODE=$(validate "$CONTENT" "Thriller" "react-agent-endpoint")
+    # docker logs docgrader-agent-endpoint
+    # if [ "$EXIT_CODE" == "1" ]; then
+    #     exit 1
+    # fi
 
     local CONTENT=$(http_proxy="" curl http://${ip_address}:9090/v1/chat/completions -X POST -H "Content-Type: application/json" -d '{
      "query": "Tell me about Michael Jackson song thriller"
diff --git a/AgentQnA/tests/test_compose_on_gaudi.sh b/AgentQnA/tests/test_compose_on_gaudi.sh
index 90dad74655..c98083a1d7 100644
--- a/AgentQnA/tests/test_compose_on_gaudi.sh
+++ b/AgentQnA/tests/test_compose_on_gaudi.sh
@@ -9,6 +9,7 @@ export WORKDIR=$WORKPATH/../../
 echo "WORKDIR=${WORKDIR}"
 export ip_address=$(hostname -I | awk '{print $1}')
 export HUGGINGFACEHUB_API_TOKEN=${HUGGINGFACEHUB_API_TOKEN}
+export TOOLSET_PATH=$WORKDIR/GenAIExamples/AgentQnA/tools/
 
 function stop_crag() {
     cid=$(docker ps -aq --filter "name=kdd-cup-24-crag-service")
@@ -17,13 +18,7 @@ function stop_crag() {
 }
 
 function stop_agent_docker() {
-    cd $WORKPATH/docker_compose/intel/hpu/gaudi
-    # container_list=$(cat compose.yaml | grep container_name | cut -d':' -f2)
-    # for container_name in $container_list; do
-    #     cid=$(docker ps -aq --filter "name=$container_name")
-    #     echo "Stopping container $container_name"
-    #     if [[ ! -z "$cid" ]]; then docker rm $cid -f && sleep 1s; fi
-    # done
+    cd $WORKPATH/docker_compose/intel/hpu/gaudi/
     docker compose -f compose.yaml down
 }
 
@@ -31,42 +26,36 @@ function stop_retrieval_tool() {
     echo "Stopping Retrieval tool"
     local RETRIEVAL_TOOL_PATH=$WORKPATH/../DocIndexRetriever
     cd $RETRIEVAL_TOOL_PATH/docker_compose/intel/cpu/xeon/
-    # container_list=$(cat compose.yaml | grep container_name | cut -d':' -f2)
-    # for container_name in $container_list; do
-    #     cid=$(docker ps -aq --filter "name=$container_name")
-    #     echo "Stopping container $container_name"
-    #     if [[ ! -z "$cid" ]]; then docker rm $cid -f && sleep 1s; fi
-    # done
     docker compose -f compose.yaml down
 }
 echo "workpath: $WORKPATH"
 echo "=================== Stop containers ===================="
 stop_crag
 stop_agent_docker
-# stop_retrieval_tool
+stop_retrieval_tool
 
 cd $WORKPATH/tests
 
-# echo "=================== #1 Building docker images===================="
-# bash 1_build_images.sh
-# echo "=================== #1 Building docker images completed===================="
+echo "=================== #1 Building docker images===================="
+bash 1_build_images.sh
+echo "=================== #1 Building docker images completed===================="
 
-# echo "=================== #2 Start retrieval tool===================="
-# bash 2_start_retrieval_tool.sh
-# echo "=================== #2 Retrieval tool started===================="
+echo "=================== #2 Start retrieval tool===================="
+bash 2_start_retrieval_tool.sh
+echo "=================== #2 Retrieval tool started===================="
 
-# echo "=================== #3 Ingest data and validate retrieval===================="
-# bash 3_ingest_data_and_validate_retrieval.sh
-# echo "=================== #3 Data ingestion and validation completed===================="
+echo "=================== #3 Ingest data and validate retrieval===================="
+bash 3_ingest_data_and_validate_retrieval.sh
+echo "=================== #3 Data ingestion and validation completed===================="
 
 echo "=================== #4 Start agent and API server===================="
 bash 4_launch_and_validate_agent_tgi.sh
 echo "=================== #4 Agent test passed ===================="
 
-# echo "=================== #5 Stop agent and API server===================="
-# stop_crag
-# stop_docker
-# stop_retrieval_tool
-# echo "=================== #5 Agent and API server stopped===================="
+echo "=================== #5 Stop agent and API server===================="
+stop_crag
+stop_docker
+stop_retrieval_tool
+echo "=================== #5 Agent and API server stopped===================="
 
-# echo "ALL DONE!"
+echo "ALL DONE!"

From 068f945daa58ebdfabc3c95fdcb3accd21fe6ecc Mon Sep 17 00:00:00 2001
From: minmin-intel <minmin.hou@intel.com>
Date: Tue, 10 Sep 2024 22:02:03 +0000
Subject: [PATCH 38/39] update test script

Signed-off-by: minmin-intel <minmin.hou@intel.com>
---
 .../docker_compose/intel/hpu/gaudi/compose.yaml  |  2 +-
 AgentQnA/tests/test_compose_on_gaudi.sh          | 16 ++++++++++++++--
 2 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/AgentQnA/docker_compose/intel/hpu/gaudi/compose.yaml b/AgentQnA/docker_compose/intel/hpu/gaudi/compose.yaml
index e68d7e9c3a..3f47f7de7d 100644
--- a/AgentQnA/docker_compose/intel/hpu/gaudi/compose.yaml
+++ b/AgentQnA/docker_compose/intel/hpu/gaudi/compose.yaml
@@ -16,7 +16,7 @@ services:
       HF_TOKEN: ${HUGGINGFACEHUB_API_TOKEN}
       HF_HUB_DISABLE_PROGRESS_BARS: 1
       HF_HUB_ENABLE_HF_TRANSFER: 0
-      HABANA_VISIBLE_DEVICES: all #0,1,4,5
+      HABANA_VISIBLE_DEVICES: all
       OMPI_MCA_btl_vader_single_copy_mechanism: none
       PT_HPU_ENABLE_LAZY_COLLECTIVES: true
     runtime: habana
diff --git a/AgentQnA/tests/test_compose_on_gaudi.sh b/AgentQnA/tests/test_compose_on_gaudi.sh
index c98083a1d7..72d0fa0b1b 100644
--- a/AgentQnA/tests/test_compose_on_gaudi.sh
+++ b/AgentQnA/tests/test_compose_on_gaudi.sh
@@ -19,14 +19,26 @@ function stop_crag() {
 
 function stop_agent_docker() {
     cd $WORKPATH/docker_compose/intel/hpu/gaudi/
-    docker compose -f compose.yaml down
+    # docker compose -f compose.yaml down
+    container_list=$(cat compose.yaml | grep container_name | cut -d':' -f2)
+    for container_name in $container_list; do
+        cid=$(docker ps -aq --filter "name=$container_name")
+        echo "Stopping container $container_name"
+        if [[ ! -z "$cid" ]]; then docker rm $cid -f && sleep 1s; fi
+    done
 }
 
 function stop_retrieval_tool() {
     echo "Stopping Retrieval tool"
     local RETRIEVAL_TOOL_PATH=$WORKPATH/../DocIndexRetriever
     cd $RETRIEVAL_TOOL_PATH/docker_compose/intel/cpu/xeon/
-    docker compose -f compose.yaml down
+    # docker compose -f compose.yaml down
+    container_list=$(cat compose.yaml | grep container_name | cut -d':' -f2)
+    for container_name in $container_list; do
+        cid=$(docker ps -aq --filter "name=$container_name")
+        echo "Stopping container $container_name"
+        if [[ ! -z "$cid" ]]; then docker rm $cid -f && sleep 1s; fi
+    done
 }
 echo "workpath: $WORKPATH"
 echo "=================== Stop containers ===================="

From dbefa2fbc84201b94cda979e44198d41a7416a37 Mon Sep 17 00:00:00 2001
From: minmin-intel <minmin.hou@intel.com>
Date: Tue, 10 Sep 2024 22:36:21 +0000
Subject: [PATCH 39/39] set tgi-gaudi version

Signed-off-by: minmin-intel <minmin.hou@intel.com>
---
 AgentQnA/docker_compose/intel/hpu/gaudi/compose.yaml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/AgentQnA/docker_compose/intel/hpu/gaudi/compose.yaml b/AgentQnA/docker_compose/intel/hpu/gaudi/compose.yaml
index 3f47f7de7d..ba890cf34d 100644
--- a/AgentQnA/docker_compose/intel/hpu/gaudi/compose.yaml
+++ b/AgentQnA/docker_compose/intel/hpu/gaudi/compose.yaml
@@ -3,7 +3,7 @@
 
 services:
   tgi-server:
-    image: ghcr.io/huggingface/tgi-gaudi:latest
+    image: ghcr.io/huggingface/tgi-gaudi:2.0.4
     container_name: tgi-server
     ports:
       - "8085:80"
