Spaces:
Runtime error
Runtime error
File size: 1,264 Bytes
4962437 |
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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
```python
import hashlib
import json
from urllib.request import urlopen
from decouple import config
from swarms.drivers import PineconeVectorStoreDriver
def load_data(driver: PineconeVectorStoreDriver) -> None:
response = urlopen(
"https://raw.githubusercontent.com/wedeploy-examples/"
"supermarket-web-example/master/products.json"
)
for product in json.loads(response.read()):
driver.upsert_text(
product["description"],
vector_id=hashlib.md5(product["title"].encode()).hexdigest(),
meta={
"title": product["title"],
"description": product["description"],
"type": product["type"],
"price": product["price"],
"rating": product["rating"]
},
namespace="supermarket-products"
)
vector_driver = PineconeVectorStoreDriver(
api_key=config("PINECONE_API_KEY"),
environment=config("PINECONE_ENVIRONMENT"),
index_name=config("PINECONE_INDEX_NAME")
)
load_data(vector_driver)
result = vector_driver.query(
"fruit",
count=3,
filter={
"price": {"$lte": 15},
"rating": {"$gte": 4}
},
namespace="supermarket-products"
)
print(result)
``` |