Skip to content

Commit

Permalink
Resolved find db bug
Browse files Browse the repository at this point in the history
  • Loading branch information
TJ202 committed Jan 15, 2025
1 parent 833e9e2 commit e00ee20
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions libs/agentc_core/agentc_core/catalog/catalog/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ def find(
"""Returns the catalog items that best match a query."""

# Catalog item has to be queried directly
if name is not None and snapshot is not None:
if name is not None:
if snapshot == LATEST_SNAPSHOT_VERSION:
snapshot = self.version.identifier
# TODO (GLENN): Need to add some validation around bucket (to prevent injection)
# TODO (GLENN): Need to add some validation around name (to prevent injection)
item_query = f"""
Expand All @@ -77,18 +79,6 @@ def find(
return []
query_embeddings = None

elif name is not None:
item_query = f"""
FROM `{self.bucket}`.`{DEFAULT_CATALOG_SCOPE}`.`{self.kind}_catalog` AS a
WHERE a.name = $name
SELECT a.*;
"""
res, err = execute_query_with_parameters(self.cluster, item_query, {"name": name})
if err is not None:
logger.error(err)
return []
query_embeddings = None

else:
# Generate embeddings for user query
query_embeddings = self.embedding_model.encode(query)
Expand Down Expand Up @@ -202,6 +192,9 @@ def find(
descriptors.append(descriptor)

# We compute the true cosine distance here (Couchbase uses a different score :-)).
if name is not None:
return [SearchResult(entry=descriptors[0], delta=1)]

deltas = self.get_deltas(query_embeddings, [t.embedding for t in descriptors])
results = [SearchResult(entry=descriptors[i], delta=deltas[i]) for i in range(len(deltas))]
return sorted(results, key=lambda t: t.delta, reverse=True)
Expand Down

0 comments on commit e00ee20

Please sign in to comment.