2023-02-10 18:07:26 +00:00
|
|
|
"""Test splitting with page numbers included."""
|
|
|
|
import os
|
|
|
|
|
2023-03-14 06:06:50 +00:00
|
|
|
from langchain.document_loaders import PyPDFLoader
|
2023-02-10 18:07:26 +00:00
|
|
|
from langchain.embeddings.openai import OpenAIEmbeddings
|
|
|
|
from langchain.vectorstores import FAISS
|
|
|
|
|
|
|
|
|
|
|
|
def test_pdf_pagesplitter() -> None:
|
|
|
|
"""Test splitting with page numbers included."""
|
|
|
|
script_dir = os.path.dirname(__file__)
|
2023-03-14 06:06:50 +00:00
|
|
|
loader = PyPDFLoader(os.path.join(script_dir, "examples/hello.pdf"))
|
2023-02-10 18:07:26 +00:00
|
|
|
docs = loader.load()
|
|
|
|
assert "page" in docs[0].metadata
|
|
|
|
assert "source" in docs[0].metadata
|
|
|
|
|
|
|
|
faiss_index = FAISS.from_documents(docs, OpenAIEmbeddings())
|
|
|
|
docs = faiss_index.similarity_search("Complete this sentence: Hello", k=1)
|
|
|
|
assert "Hello world" in docs[0].page_content
|