How to utilize the vector store for direct text while using Chat Models?
Labels: name: area: embeddings, name: area: doc loader, name: area: vector store, name: auto:question, name: auto:documentation, name: area: models

### Issue with current documentation:

I'm attempting to use Meilisearch as a vector store with Chat Models, however I'm a little confused about how to use the following code to send the input from Meilisearch to Chat Models. Below is the code which you gave

```
from langchain.vectorstores import Meilisearch
from langchain.embeddings.openai import OpenAIEmbeddings
from langchain.documents import Document
from langchain.document_loaders.pdf import PyPDFLoader
import meilisearch

# Assuming you have a list of PDF files
pdf_files = ["file1.pdf", "file2.pdf", ...]

# Create a PDF loader
pdf_loader = PyPDFLoader()

# Load the documents from the PDF files
pdf_documents = [pdf_loader.load(file) for file in pdf_files]

# Create a Meilisearch client
client = meilisearch.Client(url='http://127.0.0.1:7700', api_key='***')
embeddings = OpenAIEmbeddings()
vectorstore = Meilisearch(
    embedding=embeddings,
    client=client,
    index_name='langchain_demo',
    text_key='text')

# Extract the texts from the documents
texts = [doc.page_content for doc in pdf_documents]
# Add the texts to the vector store
vectorstore.add_texts(texts)
```

Below is the code which i wrote initially which is not utilizing the vector store

```
from langchain.chat_models import ChatOpenAI
from langchain.prompts import PromptTemplate
from langchain.chains import LLMChain
from dotenv import load_dotenv
from pytesseract import image_to_string
from langchain.text_splitter import RecursiveCharacterTextSplitter, Document
from PIL import Image
from io import BytesIO
import pypdfium2 as pdfium
import pandas as pd
import pytesseract
import json
import os
import requests

pytesseract.pytesseract.tesseract_cmd = r'C:\Program Files\Tesseract-OCR\tesseract.exe'

load_dotenv()
os.environ["OPENAI_API_KEY"] = "sk-H......."


class DocumentProcessor:
    def __init__(self):
        self.llm = ChatOpenAI(temperature=0, model="gpt-3.5-turbo-0613")

    def convert_pdf_to_images(self, file_path, scale=300 / 72):
        pdf_file = pdfium.PdfDocument(file_path)
        page_indices = [i for i in range(len(pdf_file))]
        renderer = pdf_file.render(
            pdfium.PdfBitmap.to_pil,
            page_indices=page_indices,
            scale=scale,
        )
        final_images = []
        for i, image in zip(page_indices, renderer):
            image_byte_array = BytesIO()
            image.save(image_byte_array, format='jpeg', optimize=True)
            image_byte_array = image_byte_array.getvalue()
            final_images.append(dict({i: image_byte_array}))
        return final_images

    def extract_text_from_img(self, list_dict_final_images):
        image_list = [list(data.values())[0] for data in list_dict_final_images]
        image_content = []
        for index, image_bytes in enumerate(image_list):
            image = Image.open(BytesIO(image_bytes))
            raw_text = str(image_to_string(image))
            image_content.append(raw_text)
        return "\\n".join(image_content)

    def extract_content_from_url(self, url):
        images_list = self.convert_pdf_to_images(url)
        text_with_pytesseract = self.extract_text_from_img(images_list)
        return text_with_pytesseract

    def extract_structured_data(self, content):
        template = """
        You are an expert admin people who will extract core information from documents

        {content}

        Above is the content; please try to return the abstract and extractive summary

        """
        prompt = PromptTemplate(
            input_variables=["content"],
            template=template,
        )
        chain = LLMChain(llm=self.llm, prompt=prompt)

        text_splitter = RecursiveCharacterTextSplitter(
            chunk_size=1024,  # Maximum size of chunks to return
            chunk_overlap=50,  # Overlap in tokens between chunks
        )

        # Create a Document object for each document
        documents = [Document(page_content=text) for text in content]

        # Split the documents into chunks
        chunks = text_splitter.split_documents(documents)

        results = [chain.run(content=chunk) for chunk in chunks]

        print(results)
        return results

    def process_documents(self, file_paths):
        results = []
        for file_path in file_paths:
            content = self.extract_content_from_url(file_path)
            data = self.extract_structured_data(content)
            if isinstance(data, list):
                results.extend(data)
            else:
                results.append(data)
        return results


# Example usage
if __name__ == '__main__':
    document_processor = DocumentProcessor()
    uploaded_files_paths = [r'Questionnaire_2021 (1).pdf']
    processed_results = document_processor.process_documents(uploaded_files_paths)
    if len(processed_results) > 0:
        try:
            df = pd.DataFrame(processed_results)
            print("Results:")
            df.to_excel('output.xlsx', index=False)
            print(df)
        except Exception as e:
            print(f"An error occurred while creating the DataFrame: {e}")
```

Can you please try to update the above code which I wrote with the code which you gave i.e. the code which has the vector store?

### Idea or request for content:

_No response_