mirror of
https://github.com/langchain-ai/langchain.git
synced 2026-10-06 01:45:27 +03:00
2.3 KiB
2.3 KiB
In [1]:
from langchain.embeddings.openai import OpenAIEmbeddings
from langchain.vectorstores.faiss import FAISS
from langchain.text_splitter import CharacterTextSplitter
from langchain import OpenAI, VectorDBQAIn [3]:
with open('../state_of_the_union.txt') as f:
state_of_the_union = f.read()
text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
texts = text_splitter.split_text(state_of_the_union)
embeddings = OpenAIEmbeddings()
docsearch = FAISS.from_texts(texts, embeddings)In [4]:
qa = VectorDBQA(llm=OpenAI(), vectorstore=docsearch)In [5]:
query = "What did the president say about Ketanji Brown Jackson"
qa.run(query)Out [5]:
' The President said that Ketanji Brown Jackson is a consensus builder and has received a broad range of support since she was nominated.'
In [ ]: