I’m studying immigrating to RedisGraph from ArangoDB and so far I’ve re-written our “Recommended Products” query as below. However, it’s showing weaker performance compared to ArangoDB.
The following are the details, and the query I used to get the recommended products to show to an online shopper user based on other user’s views of other products, filtering out the current user’s views, and also sorting by the products that occured the most.
Schema:
- Nodes:
-
user
(indexed on ID) -
product
(indexed on ID)
- Relations:
purchased
viewed
Query:
MATCH (:product {id: 123})<-[:purchased]-(:user)-[r:purchased]->(p:product)
WHERE NOT (:user {id: 321})-[:purchased]->(p)
WITH p, COUNT(r) as count
WHERE count > 9
RETURN p.id as id, count
ORDER BY count DESC
LIMIT 5
Execution time: 6177.225 ms
As you can see this took over 6 seconds! Compared to what I have on ArangoDB:
Schema:
- Vertices:
users
products
- Edges:
-
purchases
(._from = ‘users/[id]’ , ._to = ‘products/[id]’) -
views
(._from = ‘users/[id]’ , ._to = ‘products/[id]’)
-
Query:
LET userPurchases = (FOR purchase IN OUTBOUND 'users/321' purchases RETURN purchase._id)
FOR product,purchase IN 2..2 ANY 'products/123' purchases
FILTER purchase._to NOT IN userPurchases
FILTER purchase._from != 'user/321'
COLLECT id = product._key WITH COUNT INTO count
FILTER count > 9
FILTER id != null
SORT count DESC
LIMIT 5
RETURN DISTINCT {id:id,count:count}
Execution time: 33.256 ms
Similarly, I’ve tried using this query to get recommended products based on other user’s views, while filtering out the current user’s views/purchases:
MATCH (:product {id: 4483906})<-[:viewed]-(:user)-[r:viewed]->(p:product)
WHERE NOT (:user {id: 65738229})-[:viewed]->(p)
AND NOT (:user {id: 65738229})-[:purchased]->(p)
WITH p, COUNT(r) as count
WHERE count > 9
RETURN p.id as id, count
ORDER BY count DESC
LIMIT 5
And it failed to execute since it took longer than 30 seconds.
Is there a way I can enhance the performance of these queries?
Thanks,