Generate Titles, Descriptions and Keywords For Text

SearchBlox provides two ways to generate Titles, Descriptions and Keywords for Text using LLM based on Llama-2-based model:

Using Python

📘

Prerequisite:

  • Download Python source-code using the following link:
    Python code
  • IDE to execute the Python source-code.

Steps to Execute Python

  1. Create a virtual environment using the following steps:

    • Open the downloaded source-code on the IDE and in terminal type python -m venv .venv
    • Activate the virtual environment using the following command:
      .venv\\Scripts\\activate
    • Install all the required libraries using the following command:
      pip install -r requirements.txt
  2. Run the following command on the virtual environment to run the FastAPI.
    uvicorn main:app --reload

  3. Once the FastAPI is running, the following message will be shown in the terminal:

  4. Click on the IP-Address or the link as shown in previous step (http://127.0.0.1:8000) to start the FastAPI UI on the browser.

  5. Add /docs to the end of the URL as http://127.0.0.1:8000/docs in the browser to use the FastAPI UI.

  6. In the FastAPI UI, click on the POST method for API pretext_update and click on Try it out.

  7. After clicking on the Try it out button, find the Request body. In the request body, replace the indexname, host(IP Address), port, username and password with the corresponding server credentials (for the indexname, add idx as prefix. If the collection has only two digits as the collection id, add a 0 in front of the collection id for Example idx056).

  8. Let the POST method run. Logs about the entity generated and the corresponding results can be seen on the terminal.

  9. Once the POST method has completed executing, find the list of JSON objects for the title, description and keywords as shown in the following example.

  10. After completing the execution of previous step , go to the SearchBlox Console > Manage Collection, look for the Collection which was used in step 7 and click on the search icon on that collection as show in the following example.

  11. Login into the search page as shown below:

  12. At the end of the search URL, add &debug=TRUE to open the metadata section.

  13. Search for the term ml_ and you will find the three entities as shown in the following example:

Using Google Colab Notebook

To use Google Colab Notebook click on the following link:
SearchBlox_LLM

Steps to run the Google Colab Notebook

  1. To connect to a runtime, click on the connect button on the upper-right corner as shown in the following:

  2. Choose the preferred runtime by clicking Runtime>Change runtime type.

  3. After connecting to your runtime, there are two ways to continue:

    • You can connect to the normal runtime, which is free and consumes the least amount of Google-provided resources.
    • You can connect to the GPU-accelerated runtime, which comes with certain limitations and has a time limit (if using the free version of Google Colab).
  4. Run the first code block under the install the required libraries section, by clicking the play button marked in red to execute the code block, as shown in the following screenshot:

  5. After selecting your preferred runtime and executing the first code block, there are two options:

    • If normal runtime is selected, execute the following code block:

    • If GPU accelerated runtime is selected, execute the following code block:

      NOTE: Depending on your preferred runtime, you can run only one of these code blocks.

  6. Using the GPU runtime can decrease the time taken to generate the description, title or keywords.

  7. Execute the import the libraries code block similar to the above.

  8. Execute the downloading and loading the model code blocks similar to the above.

  9. Under user credentials code block, input your host address, port number and username and password inside the auth() variable. Enter the desired collection id for the index_name variable as shown in the following example:

  10. Execute the checking cluster health code block.

  11. Execute the retrieving and cleaning the data code block.

  12. Execute the prompts for the desired outputs code block.

  13. Execute the Generating the relevant output and pushing it onto the metadata code block.

📘

NOTE:

To check the results of the above mentioned code blocks, follow steps 10-13 from the section Using Python .