-
Notifications
You must be signed in to change notification settings - Fork 483
Expand file tree
/
Copy pathpaper.py
More file actions
28 lines (22 loc) · 815 Bytes
/
Copy pathpaper.py
File metadata and controls
28 lines (22 loc) · 815 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
"""Parse a local PDF and retrieve page-aware evidence."""
import asyncio
from pathlib import Path
from quantmind.preprocess.format import parse_pdf
from quantmind.rag import chunk_parsed_document, retrieve_parsed_document
async def main() -> None:
"""Parse one PDF and print page-aware BM25 evidence."""
pdf_path = Path("tests/fixtures/paper/golden/paper.pdf")
document = await parse_pdf(pdf_path.read_bytes())
chunks = chunk_parsed_document(document)
hits = retrieve_parsed_document(
chunks,
"How is the long-short portfolio constructed?",
top_k=3,
)
for hit in hits:
print(
f"page={hit.chunk.page_number} score={hit.score:.3f} "
f"text={hit.chunk.text[:120]!r}"
)
if __name__ == "__main__":
asyncio.run(main())