Is there any option to store direct text to VectorDB to get faster response? 
Labels: name: area: vector store, name: auto:question, name: auto:improvement, name: area: models

### Issue with current documentation:

Instead of embeddings, I'm using chat models with RecursiveTextSplitter because they simply return the response without any further justification. The input PDF files that I'm providing have a 36k input length. It takes a long time to return the output when using straight code. Can we store the direct text in any vector database and use it to get faster response?

Note: I'm not talking about embeddings, i'm trying to use direct chat models from OpenAI

Below is the code which i'm using

```
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 anyone please help me with this?

### Idea or request for content:

_No response_