Skip to content

Commit

Permalink
Fix SDK tests
Browse files Browse the repository at this point in the history
  • Loading branch information
javitonino committed May 23, 2024
1 parent 87302a6 commit d74b22a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 26 deletions.
30 changes: 5 additions & 25 deletions nucliadb/nucliadb/ingest/service/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ async def _create_kb_hosted(self, request: KnowledgeBoxNew) -> str:
await self.proc.create_kb(
request.slug,
request.config,
parse_model_metadata_from_request(request),
parse_model_metadata_from_json(request.learning_config),
forceuuid=kbid,
release_channel=release_channel,
)
Expand Down Expand Up @@ -778,31 +778,11 @@ def parse_model_metadata_from_learning_config(
return model


def parse_model_metadata_from_request(
request: KnowledgeBoxNew,
def parse_model_metadata_from_json(
data: str,
) -> SemanticModelMetadata:
model = SemanticModelMetadata()
model.similarity_function = request.similarity
if request.HasField("vector_dimension"):
model.vector_dimension = request.vector_dimension
else:
logger.warning(
"Vector dimension not set. Will be detected automatically on the first vector set."
)

if len(request.matryoshka_dimensions) > 0:
if model.vector_dimension not in request.matryoshka_dimensions:
logger.warning(
"Vector dimensions is inconsistent with matryoshka dimensions! Ignoring them",
extra={
"kbid": request.forceuuid,
"kbslug": request.slug,
},
)
else:
model.matryoshka_dimensions.extend(request.matryoshka_dimensions)

return model
config = json.loads(data)
return SemanticModelMetadata(**config)


def get_release_channel(request: KnowledgeBoxNew) -> utils_pb2.ReleaseChannel.ValueType:
Expand Down
2 changes: 1 addition & 1 deletion nucliadb_sdk/nucliadb_sdk/tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ async def init_fixture(
):
sdk = nucliadb_sdk.NucliaDB(region=nucliadb_sdk.Region.ON_PREM, url=nucliadb.url)
slug = uuid.uuid4().hex
kb_obj = sdk.create_knowledge_box(slug=slug)
kb_obj = sdk.create_knowledge_box(slug=slug,learning_configuration={"similarity_function":"COSINE","vector_dimension":768})
kbid = kb_obj.uuid

import_resp = requests.get(dataset_location)
Expand Down

0 comments on commit d74b22a

Please sign in to comment.