Skip to content

Commit a011d00

Browse files
Feat/improvements post sdsc (#18)
* remove security aspects and clean up similarity score chip for mobile view * remove unused function * move index name var
1 parent e07070f commit a011d00

File tree

18 files changed

+1957
-2302
lines changed

18 files changed

+1957
-2302
lines changed

app/vecsim_app/api/auth_routes.py

Lines changed: 0 additions & 74 deletions
This file was deleted.

app/vecsim_app/api/routes.py

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
import asyncio
12
import typing as t
23
import redis.asyncio as redis
34

45
from fastapi import APIRouter
6+
57
from vecsim_app import config
68
from vecsim_app import TEXT_MODEL
79
from vecsim_app.schema import (
@@ -38,28 +40,23 @@ async def products_from_results(total, results) -> list:
3840
operation_id="get_products_samples")
3941
async def get_products(limit: int = 20, skip: int = 0, gender: str = "", category: str = ""):
4042
products = []
41-
# TODO - if we can generalize this - that would be sick
43+
expressions = []
4244
if gender and category:
43-
products = await Product.find(
45+
expressions.append(
4446
(Product.product_metadata.gender == gender) & \
4547
(Product.product_metadata.master_category == category)
46-
).copy(offset=skip, limit=limit).execute()
47-
48+
)
4849
elif gender and not category:
49-
products = await Product.find(
50-
Product.product_metadata.gender == gender
51-
).copy(offset=skip, limit=limit).execute()
52-
50+
expressions.append(Product.product_metadata.gender == gender)
5351
elif category and not gender:
54-
products = await Product.find(
55-
Product.product_metadata.master_category == category
56-
).copy(offset=skip, limit=limit).execute()
57-
58-
else:
59-
products = await Product.find().copy(offset=skip, limit=limit).execute()
52+
expressions.append(Product.product_metadata.master_category == category)
53+
# Run query
54+
products = await Product.find(*expressions)\
55+
.copy(offset=skip, limit=limit)\
56+
.execute(exhaust_results=False)
6057
# Get total count
6158
total = (
62-
await redis_client.ft().search(
59+
await redis_client.ft(config.INDEX_NAME).search(
6360
count(gender=gender, category=category)
6461
)
6562
).total
@@ -104,11 +101,13 @@ async def find_products_by_image(similarity_request: SimilarityRequest) -> t.Dic
104101
vector = await redis_client.hget(product_vector_key, "img_vector")
105102

106103
# obtain results of the query
107-
total = (await redis_client.ft().search(count_query)).total
108-
results = await redis_client.ft().search(query, query_params={"vec_param": vector})
104+
total, results = await asyncio.gather(
105+
redis_client.ft(config.INDEX_NAME).search(count_query),
106+
redis_client.ft(config.INDEX_NAME).search(query, query_params={"vec_param": vector})
107+
)
109108

110109
# Get Product records of those results
111-
return await products_from_results(total, results)
110+
return await products_from_results(total.total, results)
112111

113112

114113
@r.post("/vectorsearch/text",
@@ -134,11 +133,13 @@ async def find_products_by_text(similarity_request: SimilarityRequest) -> t.Dict
134133
vector = await redis_client.hget(product_vector_key, "text_vector")
135134

136135
# obtain results of the query
137-
total = (await redis_client.ft().search(count_query)).total
138-
results = await redis_client.ft().search(query, query_params={"vec_param": vector})
136+
total, results = await asyncio.gather(
137+
redis_client.ft(config.INDEX_NAME).search(count_query),
138+
redis_client.ft(config.INDEX_NAME).search(query, query_params={"vec_param": vector})
139+
)
139140

140141
# Get Product records of those results
141-
return await products_from_results(total, results)
142+
return await products_from_results(total.total, results)
142143

143144

144145
@r.post("/vectorsearch/text/user",
@@ -163,8 +164,10 @@ async def find_products_by_user_text(similarity_request: UserTextSimilarityReque
163164
vector = TEXT_MODEL.encode(similarity_request.user_text)
164165

165166
# obtain results of the query
166-
total = (await redis_client.ft().search(count_query)).total
167-
results = await redis_client.ft().search(query, query_params={"vec_param": vector})
167+
total, results = await asyncio.gather(
168+
redis_client.ft(config.INDEX_NAME).search(count_query),
169+
redis_client.ft(config.INDEX_NAME).search(query, query_params={"vec_param": vector})
170+
)
168171

169172
# Get Product records of those results
170-
return await products_from_results(total, results)
173+
return await products_from_results(total.total, results)

app/vecsim_app/api/user_routes.py

Lines changed: 0 additions & 88 deletions
This file was deleted.

app/vecsim_app/auth.py

Lines changed: 0 additions & 86 deletions
This file was deleted.

app/vecsim_app/config.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
PROJECT_NAME = "vecsim_app"
44
API_DOCS = "/api/docs"
55
OPENAPI_DOCS = "/api/openapi.json"
6+
INDEX_NAME = "products"
67
INDEX_TYPE = os.environ.get("VECSIM_INDEX_TYPE", "HNSW")
78
REDIS_HOST = os.environ.get("REDIS_HOST", "redis-vector-db")
89
REDIS_PORT = os.environ.get("REDIS_PORT", 6379)
@@ -13,8 +14,3 @@
1314
os.environ["REDIS_OM_URL"] = REDIS_URL
1415
API_V1_STR = "/api/v1"
1516
DATA_LOCATION = os.environ.get("DATA_LOCATION", "../../data")
16-
SUPERUSER_EMAIL = os.environ.get("SUPER_EMAIL", "[email protected]")
17-
SUPERUSER_PASS = os.environ.get("SUPER_PASS", "secret")
18-
SUPERUSER_FIRST = os.environ.get("SUPER_FIRST", "sam")
19-
SUPERUSER_LAST = os.environ.get("SUPER_LAST", "lastname")
20-
SECRET_KEY = os.environ.get("SECRET_KEY", "supersecretkey")

app/vecsim_app/crud/__init__.py

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)