Skip to content

Commit 3c5a466

Browse files
committed
update example
1 parent 65a08b1 commit 3c5a466

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

docs/examples.rst

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,38 @@ Combining Text and Images
9797
client.close()
9898
9999
100+
Loading Data from S3
101+
--------------------
102+
103+
If you already have data stored in S3, you can use an ``s3://`` url to load the image(s):
104+
105+
.. code-block:: python
106+
107+
import os
108+
from pymongo_voyageai import PyMongoVoyageAI
109+
110+
client = PyMongoVoyageAI(
111+
voyageai_api_key=os.environ["VOYAGEAI_API_KEY"],
112+
s3_bucket_name=os.environ["S3_BUCKET_NAME"],
113+
mongo_connection_string=os.environ["MONGODB_URI"],
114+
collection_name="test",
115+
database_name="test_db",
116+
)
117+
118+
query = "The consequences of a dictator's peace"
119+
url = "s3://my-bucket-name/readingcopy.pdf"
120+
images = client.url_to_images(url)
121+
resp = client.add_documents(images)
122+
client.wait_for_indexing()
123+
data = client.similarity_search(query, extract_images=True)
124+
125+
# We expect page 5 to be the best match.
126+
assert data[0]["inputs"][0].page_number == 5
127+
assert len(client.get_by_ids([d["_id"] for d in resp])) == len(resp)
128+
client.delete_by_ids([d["_id"] for d in resp])
129+
client.close()
130+
131+
100132
Using Async API
101133
---------------
102134

0 commit comments

Comments
 (0)