2025-02-28 12:16:06 -05:00
|
|
|
import os
|
2025-04-20 16:34:29 -07:00
|
|
|
|
2025-02-28 12:16:06 -05:00
|
|
|
from dotenv import load_dotenv
|
2025-04-20 16:34:29 -07:00
|
|
|
from morphik import Morphik
|
2025-02-28 12:16:06 -05:00
|
|
|
from PIL import Image
|
|
|
|
|
|
|
|
load_dotenv()
|
|
|
|
|
2025-04-09 18:46:00 -07:00
|
|
|
## Connect to the Morphik instance
|
|
|
|
db = Morphik(os.getenv("MORPHIK_URI"), timeout=10000, is_local=True)
|
2025-02-28 12:16:06 -05:00
|
|
|
|
|
|
|
## Ingestion Pathway
|
2025-03-20 22:54:18 -04:00
|
|
|
db.ingest_file("examples/assets/colpali_example.pdf", use_colpali=True)
|
2025-02-28 12:16:06 -05:00
|
|
|
|
2025-03-20 22:54:18 -04:00
|
|
|
## Retrieving sources
|
|
|
|
chunks = db.retrieve_chunks("At what frequency do we achieve the highest Image Rejection Ratio?", use_colpali=True, k=3)
|
2025-02-28 12:16:06 -05:00
|
|
|
|
|
|
|
for chunk in chunks:
|
|
|
|
if isinstance(chunk.content, Image.Image):
|
|
|
|
# image chunks will automatically be parsed as PIL.Image.Image objects
|
|
|
|
chunk.content.show()
|
|
|
|
else:
|
|
|
|
print(chunk.content)
|
|
|
|
|
2025-04-09 18:46:00 -07:00
|
|
|
# You can also directly query a VLM as defined in the configuration
|
2025-02-28 12:16:06 -05:00
|
|
|
response = db.query("At what frequency do we achieve the highest Image Rejection Ratio?", use_colpali=True, k=3)
|
|
|
|
print(response.completion)
|