# Weaviate with OpenAi

**URL:** <https://forum.weaviate.io/t/weaviate-with-openai/540>\
**Category:** Support\
**Created:** [August 16, 2023, 10:03am UTC](https://forum.weaviate.io/t/weaviate-with-openai/540 "2023-08-16T10:03:34Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![starskiin3d](https://avatars.discourse-cdn.com/v4/letter/s/ed8c4c/32.png) [@starskiin3d](https://forum.weaviate.io/u/starskiin3d)\
**Post date:** [August 16, 2023, 10:03am UTC](https://forum.weaviate.io/t/weaviate-with-openai/540/1 "2023-08-16T10:03:34Z")

</div>

Hello,

I was wondering if anyone has ever done the following, and is Weaviate good solution for this.

1. Connect to OpenAi.
2. Feed Weaviate with different documents (text only no images).
3. Have server run on localhost via docker or any other means.
4. Have users ask questions via http-client and OpenAI could work with Weaviate to get faster and more accurate response.

If so is there any tutorial/repo where someone might point me to.

I was using [GitHub - mayooear/gpt4-pdf-chatbot-langchain: GPT4 & LangChain Chatbot for large PDF docs](https://github.com/mayooear/gpt4-pdf-chatbot-langchain) however it has Pinecone integration, I would like to use Weaviate since it supports running on localhost.

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![DudaNogueira](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/dudanogueira/32/7846_2.png) [@DudaNogueira](https://forum.weaviate.io/u/DudaNogueira)\
**Post date:** [August 16, 2023, 6:53pm UTC](https://forum.weaviate.io/t/weaviate-with-openai/540/2 "2023-08-16T18:53:29Z")

</div>

Hi @starskiin3d ! Welcome to our community 🤗

Weaviate is ~~a great~~ the best solution for this. 😉

Considering the Github repository you mentioned, as it’s using Langchain, you can ingest the PDFs into weaviate by changing the Vectorstore, like so:

[At this line](https://github.com/mayooear/gpt4-pdf-chatbot-langchain/blob/66d183f6b207fa1d92153a430c620c58b01e9b1c/scripts/ingest-data.ts#L39)

```typescript
      const client = weaviate.client({
        scheme: process.env.WEAVIATE_SCHEME || "http",
        host: process.env.WEAVIATE_HOST || "localhost:8080"
        // apiKey: new (weaviate as any).ApiKey(
        // process.env.WEAVIATE_API_KEY || "default"
        // ),
      });
      await WeaviateStore.fromDocuments(docs, embeddings, {client: client, indexName: "Document", textKey:"text"})

```

For that you will have to run Weaviate locally, using docker. Here is a nice docker configurator tool that will guide you into creating the perfect docker-compose.yaml:

> **[Docker Compose | Weaviate - vector database](https://weaviate.io/developers/weaviate/installation/docker-compose)**
>
> Configurator

that should be enough to store your embeddings into Weaviate. **You will also need to change the querying part to adapt it.**

Checkout this [recipe notebook on how to use generative search with Open AI](https://github.com/weaviate/recipes/blob/main/generative-search/generative_search_openai.ipynb):

Also, we have a set of great examples in:

> **[GitHub - weaviate/weaviate-examples: Weaviate vector database – examples](https://github.com/weaviate/weaviate-examples)**
>
> Weaviate vector database – examples. Contribute to weaviate/weaviate-examples development by creating an account on GitHub.

Let me know if that helps. Thanks!

---

<div class="post-metadata">

**Author:** ![starskiin3d](https://avatars.discourse-cdn.com/v4/letter/s/ed8c4c/32.png) [@starskiin3d](https://forum.weaviate.io/u/starskiin3d)\
**Post date:** [August 17, 2023, 10:07am UTC](https://forum.weaviate.io/t/weaviate-with-openai/540/3 "2023-08-17T10:07:56Z")

</div>

Hi,

First of all thanks for the fast reply, it seems I have chosen the right software with you guys.

Following up what you wrote:

1. Managed to get docker locally, can’t believe it was that easy.
2. Changed the line where you pointed out but first i had to import weaviate from:

import weaviate from ‘weaviate-ts-client’

1. After I added suggested code i get following error: Cannot find name ‘WeaviateStore’

```auto
   const client = weaviate.client({
      scheme: process.env.WEAVIATE_SCHEME || "http",
      host: process.env.WEAVIATE_HOST || "localhost:8080"
      // apiKey: new (weaviate as any).ApiKey(
      // process.env.WEAVIATE_API_KEY || "default"
      // ),
    });

    /*create and store the embeddings in the vectorStore*/
    const embeddings = new OpenAIEmbeddings();

    await WeaviateStore.fromDocuments(docs, embeddings, {client: client, indexName: "Document", textKey:"text"})

```

Also thanks for the provided links, I will go through them and try to find info i need.

Best of luck.

---

<div class="post-metadata">

**Author:** ![DudaNogueira](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/dudanogueira/32/7846_2.png) [@DudaNogueira](https://forum.weaviate.io/u/DudaNogueira)\
**Post date:** [August 17, 2023, 10:24am UTC](https://forum.weaviate.io/t/weaviate-with-openai/540/4 "2023-08-17T10:24:34Z")

</div>

Oh, sorry.

Forgot to mention tha you will need to import the WeaviateStore.

Here is the Langchain JS docs, where you can find more info:

> **[Weaviate | 🦜️🔗 Langchain](https://js.langchain.com/docs/modules/data_connection/vectorstores/integrations/weaviate)**
>
> Weaviate is an open source vector database that stores both objects and vectors, allowing for combining vector search with structured filtering. LangChain connects to Weaviate via the weaviate-ts-client package, the official Typescript client for...

This is the import you need:

```auto
import { WeaviateStore } from "langchain/vectorstores/weaviate";

```

Glad to know you are enjoying Weaviate! We are here to help!

Thanks!

---

<div class="post-metadata">

**Author:** ![starskiin3d](https://avatars.discourse-cdn.com/v4/letter/s/ed8c4c/32.png) [@starskiin3d](https://forum.weaviate.io/u/starskiin3d)\
**Post date:** [August 17, 2023, 11:27am UTC](https://forum.weaviate.io/t/weaviate-with-openai/540/5 "2023-08-17T11:27:10Z")

</div>

Now that is Amazing !!!

Managed to read from documents and push do my local docker :).

Once i set wcs|query to

```auto
{
  Get{
  Document{
     text
     source
  }
  }
}

```

I got source document and text that it read nicely, its just that not entire text is shown in query, unsure since documents are really long does it just shows me some part and hides rest or there is command to get full.

**I got two last questions before i give you 5/5 stars 🙂**

1. Would this be a proper way to get text from ingested files, have to use async function since await will give await error unable to use it at top level and i’m new in typescript.

```auto

async function Response(){
    const response = await client.graphql
    .get()
    .withClassName('Document')
    .withFields('text' 'sources')
    .do();
  
  console.log(response['data']['Get']['Document']);
}

Response()

```

1. 
  - `await WeaviateStore.fromDocuments(docs, embeddings, {client: client, indexName: "Document", textKey:"text"}) - Will ingest text into my local docker.`

- I will use following code in wcs|query to get source file and text

```auto

{
  Get{
  Document{
     text
     source
  }
  }
}

```

- Text is not fully displayed in wcs query, I can see it has gone through documents, but docs are really long and I can see only about 10-13 lines of text displayed per ingested document, while there is a lot lot more of text in those docs.

Experience with forum: Immense help from your team, I am already more than happy with the way you assisted me.

Final questions:

1. Is code query good.
2. Why does query display only partial text from files rather than whole.

Once more thanks for assistance and have a nice day.

---

<div class="post-metadata">

**Author:** ![starskiin3d](https://avatars.discourse-cdn.com/v4/letter/s/ed8c4c/32.png) [@starskiin3d](https://forum.weaviate.io/u/starskiin3d)\
**Post date:** [August 18, 2023, 10:26am UTC](https://forum.weaviate.io/t/weaviate-with-openai/540/7 "2023-08-18T10:26:13Z")

</div>

I will answer this myself, most of stuff i asked is in links you provided. Made it all work. Thanks again.

---

<div class="post-metadata">

**Author:** ![DudaNogueira](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/dudanogueira/32/7846_2.png) [@DudaNogueira](https://forum.weaviate.io/u/DudaNogueira)\
**Post date:** [August 18, 2023, 2:47pm UTC](https://forum.weaviate.io/t/weaviate-with-openai/540/8 "2023-08-18T14:47:09Z")

</div>

Oh, Glad you were able to solve it!!

I missed this last message and just go to it now.

Let’s keep in touch! We are also very active on our Slack, so let us know thru here or at Slack if you need any further assistance!

Thanks!
