2023-07-21 16:20:24 +00:00
|
|
|
"""Test splitting with page numbers included."""
|
|
|
|
import os
|
|
|
|
|
2024-01-02 21:47:11 +00:00
|
|
|
from langchain_community.document_loaders import PyPDFLoader
|
2024-01-02 20:32:16 +00:00
|
|
|
from langchain_community.embeddings.openai import OpenAIEmbeddings
|
2024-01-02 21:47:11 +00:00
|
|
|
from langchain_community.vectorstores import FAISS
|
2023-07-21 16:20:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_pdf_pagesplitter() -> None:
|
|
|
|
"""Test splitting with page numbers included."""
|
|
|
|
script_dir = os.path.dirname(__file__)
|
|
|
|
loader = PyPDFLoader(os.path.join(script_dir, "examples/hello.pdf"))
|
|
|
|
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
|