# Using GPT to Search & Pull Recommendations from a Database?

**URL:** <https://community.openai.com/t/using-gpt-to-search-pull-recommendations-from-a-database/186228>\
**Category:** API\
**Created:** [April 30, 2023, 9:53pm UTC](https://community.openai.com/t/using-gpt-to-search-pull-recommendations-from-a-database/186228 "2023-04-30T21:53:32Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![outdone-jon](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/outdone-jon/32/120667_2.png) [@outdone-jon](https://community.openai.com/u/outdone-jon)\
**Post date:** [April 30, 2023, 9:53pm UTC](https://community.openai.com/t/using-gpt-to-search-pull-recommendations-from-a-database/186228/1 "2023-04-30T21:53:32Z")

</div>

Hi! Like the title says, I’m wondering if I can use the GPT API to search a product database I’m building and make product recommendations based on user inputs in my web app.

Essentially a user would describe attributes about themselves and I’m hoping GPT could search my product database to find and present the most relevant recommendations.

I’ve seen similar questions asked here previously, but none was exactly this scenario + the answers weren’t totally clear.

---

<div class="post-metadata">

**Author:** ![IanBod](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/ianbod/32/32766_2.png) [@IanBod](https://community.openai.com/u/IanBod)\
**Post date:** [April 30, 2023, 11:00pm UTC](https://community.openai.com/t/using-gpt-to-search-pull-recommendations-from-a-database/186228/2 "2023-04-30T23:00:33Z")

</div>

Does your database content change regularly?

If not then you want to hit the Embeddings API with the text content from your database. Store the vector that is returned in your database. Then, when a user makes a query, you pass that query to the Embeddings API and compare the returned vector to each vector in your database.

My implementation is to store the vector as a CSV string in a TEXT field. The vector is used atomically so no need to break it down. Then to compare the query vector to each vector in your database and store the results in a temporary table that you can easily search in order.

The vector comparison is done with Cosine Similarity.

---

<div class="post-metadata">

**Author:** ![outdone-jon](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/outdone-jon/32/120667_2.png) [@outdone-jon](https://community.openai.com/u/outdone-jon)\
**Post date:** [May 3, 2023, 3:35am UTC](https://community.openai.com/t/using-gpt-to-search-pull-recommendations-from-a-database/186228/3 "2023-05-03T03:35:44Z")

</div>

Thanks for the response, Ian! The database is fairly static, so it sounds like this might be a viable route. I’m not very familiar with the embeddings API. Are you saying that each row in the database would be assigned a unique vector?

---

<div class="post-metadata">

**Author:** ![outdone-jon](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/outdone-jon/32/120667_2.png) [@outdone-jon](https://community.openai.com/u/outdone-jon)\
**Post date:** [May 3, 2023, 3:54am UTC](https://community.openai.com/t/using-gpt-to-search-pull-recommendations-from-a-database/186228/4 "2023-05-03T03:54:50Z")

</div>

It seems like this might only work if the query was very similar to the product descriptions. Meaning, if the user is telling us “I’m looking for \_\_\_\_ type of product”, we could user the embeddings to find a product in our database that’s the closest match.

Instead we’re asking the user to describe themselves and are hoping GPT can extrapolate to recommend products based on the attributes of the user. Does that make sense? Do you still think the embedding approach would work here?

---

<div class="post-metadata">

**Author:** ![Gaouzief](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/gaouzief/32/16161_2.png) [@Gaouzief](https://community.openai.com/u/Gaouzief)\
**Post date:** [May 17, 2023, 2:50pm UTC](https://community.openai.com/t/using-gpt-to-search-pull-recommendations-from-a-database/186228/5 "2023-05-17T14:50:59Z")

</div>

> [@outdone-jon](#):
>
> Instead we’re asking the user to describe themselves and are hoping GPT can extrapolate to recommend products based on the attributes of the user. Does that make sense? Do you still think the embedding approach would work here?

w’re working on the exact same problem it seems 🙂  
has you search evolved since this message ? I’m leaning towards this approach:

- pre-processing: narrow the data set to be “searched” by GPT by starting the conversation with a “tag” selection of product ranges, and also keywords"
- feed only the remaining data to gpt through the prompt repeating it in every response
- if the dataset is still too large, cut the process in 2 or 4 (wizard) based on product categories or whatever splits your data

but we have not tested this yet, we are waiting for access to GPT4-32K

---

<div class="post-metadata">

**Author:** ![outdone-jon](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/outdone-jon/32/120667_2.png) [@outdone-jon](https://community.openai.com/u/outdone-jon)\
**Post date:** [May 17, 2023, 9:28pm UTC](https://community.openai.com/t/using-gpt-to-search-pull-recommendations-from-a-database/186228/6 "2023-05-17T21:28:52Z")

</div>

That’s a great idea! Using tags to filter might actually reduce the database to a size that the entire new subset could fit in the prompt.

Of course, that’d still be a super token-heavy approach versus GPT just “knowing” our entire database to begin with. But I really like this idea as a start, so I’m gonna mess around with it.

I’d be interested to hearing more about your specific use case and what you’re working on!

---

<div class="post-metadata">

**Author:** ![Gaouzief](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/gaouzief/32/16161_2.png) [@Gaouzief](https://community.openai.com/u/Gaouzief)\
**Post date:** [May 19, 2023, 12:01pm UTC](https://community.openai.com/t/using-gpt-to-search-pull-recommendations-from-a-database/186228/7 "2023-05-19T12:01:00Z")

</div>

> [@outdone-jon](#):
>
> I’d be interested to hearing more about your specific use case and what you’re working on!

an in-store sales recommendation chatbot

---

<div class="post-metadata">

**Author:** ![sperez](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/sperez/32/514357_2.png) [@sperez](https://community.openai.com/u/sperez)\
**Post date:** [May 19, 2023, 1:04pm UTC](https://community.openai.com/t/using-gpt-to-search-pull-recommendations-from-a-database/186228/8 "2023-05-19T13:04:45Z")

</div>

I’m not sure this will work, but it might be cheaper to operate. Ask ChatGPT to read your produce descriptions and then have it pretend to be a user describing attributes of themselves. You can ask it to generate as many (100s?) of these user descriptions as you want. You can even create one or two for each product manually as examples for ChatGPT to iterate on. Create embeddings for each generated user self-description, associate with the product in question, and push the embedding into something like pinecone. Then, when a new user comes to your site and provides their self-description, create embeddings for that and query pinecone with it. Creating and querying with embeddings is cheaper than having to invoke ChatGPT for each user. This way you just have to use it for each new product or product update.

---

<div class="post-metadata">

**Author:** ![outdone-jon](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/outdone-jon/32/120667_2.png) [@outdone-jon](https://community.openai.com/u/outdone-jon)\
**Post date:** [May 21, 2023, 11:26pm UTC](https://community.openai.com/t/using-gpt-to-search-pull-recommendations-from-a-database/186228/9 "2023-05-21T23:26:54Z")

</div>

That’s interesting. So you’re saying that GPT would then calculate the semantic distance from any new user description and compare it to one in our dataset — and therefore, it’d know corresponding good recommendations?

---

<div class="post-metadata">

**Author:** ![nelson](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/nelson/32/2573_2.png) [@nelson](https://community.openai.com/u/nelson)\
**Post date:** [May 22, 2023, 3:34am UTC](https://community.openai.com/t/using-gpt-to-search-pull-recommendations-from-a-database/186228/10 "2023-05-22T03:34:54Z")

</div>

Hi Jon,

Sounds like your database is very static, and assuming your database can export to a CSV file, you can turn the CSV into embeddings and run GPT on top of it.  
Here is a thread on how to use it on top of CSV files…

> [@Send CSV file for use in Chat Completion?](https://community.openai.com/t/send-csv-file-for-use-in-chat-completion/197866/5):
>
> Hello @oliver.drobnik Yes you can, and it works very well. Here are the steps you can take. Parse the CSV file and for every row, modify the row to one line of key value sentence. For example Name, Product, Review Oliver, SD Card, I think this SD Card is great Nelson, SD Card, This SD Card is horrible will turn into multiple lines of the following… Name: Oliver, Product: SD Card, Review: I think this SD Card is great Name: Nelson, Product: SD Card, Review: This SD Card is horrible …

---

<div class="post-metadata">

**Author:** ![outdone-jon](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/outdone-jon/32/120667_2.png) [@outdone-jon](https://community.openai.com/u/outdone-jon)\
**Post date:** [May 23, 2023, 12:30am UTC](https://community.openai.com/t/using-gpt-to-search-pull-recommendations-from-a-database/186228/11 "2023-05-23T00:30:15Z")

</div>

Hi Nelson! Thanks for the insight. That sounds like a good approach if my use case was to build a chatbot that could answer questions about our product list, but I’m looking for GPT to make a selection from a product list based on attributes of our user, so it’s slightly different. And I’m not sure it would work in that sense.

Do you have any thoughts on that?

---

<div class="post-metadata">

**Author:** ![nelson](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/nelson/32/2573_2.png) [@nelson](https://community.openai.com/u/nelson)\
**Post date:** [May 23, 2023, 10:17pm UTC](https://community.openai.com/t/using-gpt-to-search-pull-recommendations-from-a-database/186228/12 "2023-05-23T22:17:45Z")

</div>

Hi Jon,  
Do you mind sharing a sample CSV file of your products?  
I assume you will like GPT to answer product questions and do product recommendations right?  
Thanks @outdone-jon

---

<div class="post-metadata">

**Author:** ![jochenschultz](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/jochenschultz/32/772274_2.png) [@jochenschultz](https://community.openai.com/u/jochenschultz)\
**Post date:** [May 23, 2023, 10:37pm UTC](https://community.openai.com/t/using-gpt-to-search-pull-recommendations-from-a-database/186228/13 "2023-05-23T22:37:40Z")

</div>

You can build a plugin instead of using embeddings. Which also gives you more customer opportunities and other options.  
And then let the model ask the api.

---

<div class="post-metadata">

**Author:** ![outdone-jon](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/outdone-jon/32/120667_2.png) [@outdone-jon](https://community.openai.com/u/outdone-jon)\
**Post date:** [May 24, 2023, 1:07am UTC](https://community.openai.com/t/using-gpt-to-search-pull-recommendations-from-a-database/186228/14 "2023-05-24T01:07:14Z")

</div>

Are there things you can do when building the plugin that you couldn’t do building through the API?

---

<div class="post-metadata">

**Author:** ![jochenschultz](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/jochenschultz/32/772274_2.png) [@jochenschultz](https://community.openai.com/u/jochenschultz)\
**Post date:** [May 24, 2023, 6:08am UTC](https://community.openai.com/t/using-gpt-to-search-pull-recommendations-from-a-database/186228/15 "2023-05-24T06:08:45Z")

</div>

You can put it into chatgpt… It’s called plugin first approach 🤗

---

<div class="post-metadata">

**Author:** ![sperez](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/sperez/32/514357_2.png) [@sperez](https://community.openai.com/u/sperez)\
**Post date:** [May 26, 2023, 4:47am UTC](https://community.openai.com/t/using-gpt-to-search-pull-recommendations-from-a-database/186228/16 "2023-05-26T04:47:17Z")

</div>

Once the user provides their description you just call the OpenAI embeddings endpoint and then use that to query pinecone (or any vector db). That query calculates the semantic distances and can return all the “hits” along with their distance. A pinecone query (they even have a free tier and you can host your own vector db very easily) is dirt cheap compared to ChatGPT’s API. Of course you can mix-in as much “chat” as you want (e.g. asking the user to provide their description).

---

<div class="post-metadata">

**Author:** ![diego.cardenas](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/diego.cardenas/32/243048_2.png) [@diego.cardenas](https://community.openai.com/u/diego.cardenas)\
**Post date:** [November 10, 2023, 5:23am UTC](https://community.openai.com/t/using-gpt-to-search-pull-recommendations-from-a-database/186228/17 "2023-11-10T05:23:28Z")

</div>

Hey to everyone here! I think this is a critical issue a lot of uf are facing. Has this changed with the new “Retrieval”?

> **[OpenAI Platform](https://platform.openai.com/docs/assistants/tools/knowledge-retrieval)**
>
> Explore developer resources, tutorials, API docs, and dynamic examples to get the most out of OpenAI's platform.

---

<div class="post-metadata">

**Author:** ![roopak](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/roopak/32/146764_2.png) [@roopak](https://community.openai.com/u/roopak)\
**Post date:** [February 21, 2024, 2:50pm UTC](https://community.openai.com/t/using-gpt-to-search-pull-recommendations-from-a-database/186228/18 "2024-02-21T14:50:42Z")

</div>

Have anyone found a solution or a correct approach for this?

---

<div class="post-metadata">

**Author:** ![SomebodySysop](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/somebodysysop/32/17613_2.png) [@SomebodySysop](https://community.openai.com/u/SomebodySysop)\
**Post date:** [February 22, 2024, 1:23am UTC](https://community.openai.com/t/using-gpt-to-search-pull-recommendations-from-a-database/186228/19 "2024-02-22T01:23:25Z")

</div>

Which part do you have a question about? Creating embeddings for your data, or calling your existing data from it’s existing database?

Here are some thoughts on the latter:

- OpenAI Text to SQL
  - Prompt Example - Natural Language to SQL
  - [https://platform.openai.com/examples/default-sql-translate](https://platform.openai.com/examples/default-sql-translate)

- OpenAI Functions calling the Poor Developers Vector Database
  - [OpenAI Functions Calling the Poor Developer's Vector Database](https://blazorhelpwebsite.com/ViewBlogPost/6067)

- Private Chat with CSV Data (@DevGirl explanation):
  - [Private Chat with CSV data - #7 by DevGirl](https://community.openai.com/t/private-chat-with-csv-data/620115/7)

---

<div class="post-metadata">

**Author:** ![roopak](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/roopak/32/146764_2.png) [@roopak](https://community.openai.com/u/roopak)\
**Post date:** [February 22, 2024, 1:40am UTC](https://community.openai.com/t/using-gpt-to-search-pull-recommendations-from-a-database/186228/20 "2024-02-22T01:40:40Z")

</div>

my 1st question is about the approach:

- can it be done with gpt4-1106-preview, retrieval, functioncalling and file
- or it be done using vector db

in vector embedding

- which model would be better for creating embeddings

in assistant api, with retrieval - when tried to upload a .txt or .md file - it gives an error mime type not supported application/octet-stream

[Next page](https://community.openai.com/t/using-gpt-to-search-pull-recommendations-from-a-database/186228.md?page=2)
