from langchain.vectorstores import Chroma
from langchain.embeddings import OpenAIEmbeddings
from langchain.chains import RetrievalQA
from langchain.chat_models import ChatOpenAI
from redundant_filter_retriever import RedundantFilterRetriever
from dotenv import load_dotenv
import langchain

langchain.debug = True

load_dotenv()

chat = ChatOpenAI()
embeddings = OpenAIEmbeddings()
db = Chroma(
    persist_directory="emb",
    embedding_function=embeddings
)
retriever = RedundantFilterRetriever(
    embeddings=embeddings,
    chroma=db
)

chain = RetrievalQA.from_chain_type(
    llm=chat,
    retriever=retriever,
    chain_type="stuff"
)

result = chain.run("What is an interesting fact about the English language?")

print(result)

langchain.vectorstores.Chroma langchain.embeddings.OpenAIEmbeddings langchain.chains.RetrievalQA.from_chain_type langchain.chat_models.ChatOpenAI
[((315, 328), 'dotenv.load_dotenv', 'load_dotenv', ([], {}), '()\n', (326, 328), False, 'from dotenv import load_dotenv\n'), ((337, 349), 'langchain.chat_models.ChatOpenAI', 'ChatOpenAI', ([], {}), '()\n', (347, 349), False, 'from langchain.chat_models import ChatOpenAI\n'), ((363, 381), 'langchain.embeddings.OpenAIEmbeddings', 'OpenAIEmbeddings', ([], {}), '()\n', (379, 381), False, 'from langchain.embeddings import OpenAIEmbeddings\n'), ((387, 449), 'langchain.vectorstores.Chroma', 'Chroma', ([], {'persist_directory': '"""emb"""', 'embedding_function': 'embeddings'}), "(persist_directory='emb', embedding_function=embeddings)\n", (393, 449), False, 'from langchain.vectorstores import Chroma\n'), ((472, 530), 'redundant_filter_retriever.RedundantFilterRetriever', 'RedundantFilterRetriever', ([], {'embeddings': 'embeddings', 'chroma': 'db'}), '(embeddings=embeddings, chroma=db)\n', (496, 530), False, 'from redundant_filter_retriever import RedundantFilterRetriever\n'), ((550, 628), 'langchain.chains.RetrievalQA.from_chain_type', 'RetrievalQA.from_chain_type', ([], {'llm': 'chat', 'retriever': 'retriever', 'chain_type': '"""stuff"""'}), "(llm=chat, retriever=retriever, chain_type='stuff')\n", (577, 628), False, 'from langchain.chains import RetrievalQA\n')]