generated from oracle/template-repo
-
Notifications
You must be signed in to change notification settings - Fork 19
Open
Description
Using a filter like the following, you can perform a search while filtering on metadata:
filter_dict = {"category": search_category}
vector_store.similarity_search(user_question, 8, filter=filter_dict)
Internally, this results in a JSON_EXISTS predicate being added to the WHERE clause, as shown below:
SELECT text, metadata,
vector_distance(embedding, :embedding, COSINE) AS distance
FROM "ORAVS_DOCUMENTS"
WHERE JSON_EXISTS(
metadata,
'$.category?(@ == $val)'
PASSING :value0 AS "val"
)
ORDER BY distance
FETCH APPROX FIRST 8 ROWS ONLY;
For performance reasons, a JSON Search Index is typically created using the CREATE SEARCH INDEX statement.
With this query:
- If no JSON Search Index exists, the optimizer uses the Vector Index.
- If a JSON Search Index exists, only the JSON Search Index is used, and the Vector Index is not applied.
Therefore, it is necessary to add a hint to the query, such as:
SELECT /*+ VECTOR_INDEX_TRANSFORM(ORAVS_DOCUMENTS) */
text, metadata,
...
to ensure the desired execution plan.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels