Skip to content

Workshop 3

Plai edited this page Aug 12, 2024 · 5 revisions

Let's do search

Make sure to finish workshop 1 and 2 first, or you can switch to branch pre-workshop-3 to start from the check point.

Step 1: Start dependencies

We still use the same embedding API and its vector database.

But this time, the vector database is also prepared with embedding of ~4,000 dummy medical records. It has patient description, categories, doctor's transcription, and in some case it also include prescription medicines.

Run the following command to start the API.

docker compose up -d db embedding-api

Step 2: Start developing search UI

Let's start the search UI with the following command.

fastapi dev search_web

You should have the search UI running at http://localhost:8000.

If you try searching now. You should only see the empty result as it's not connected with the embedding API yet.

Step 3: Implement search

In the file search_web/server.py, we have a function search that renders the search page. Currently, it only renders the search page with a search bar without searching anything.

Let's modify the search function to include the search results. Replace the embeddings = [] with the code below.

    response_json = requests.get(
        f"http://{config.embedding_api_host}/text?text={term}&top_n=10"
    ).json()
    embeddings = [GetTextResponse(**item) for item in response_json]

Now we have the embeddings results. Let's see the search results in the search page by trying the search term...

women patients with problems in digestive system

Or try to search for any medical condition.

Clone this wiki locally