Weaviate with OpenAi

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 however it has Pinecone integration, I would like to use Weaviate since it supports running on localhost.

Thanks in advance.

Hi @starskiin3d ! Welcome to our community :hugs:

Weaviate is a great the best solution for this. :wink:

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

      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:

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:

Also, we have a set of great examples in:

Let me know if that helps. Thanks!

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’
   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.

1 Like

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:

This is the import you need:

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

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

Thanks!

Now that is Amazing !!!

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

Once i set wcs|query to

{
  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 :slight_smile:

  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.

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

Response()
    • 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

{
  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.

                                **To sum things up** 
    

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.

2 Likes

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

1 Like

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!

1 Like