InferenceAI

Enter at least two characters to search.

Start free
Repository challenges

Deduplicate embedding work

Performance · Intermediate · AI engineering · 35 minutes

Engineering ticket

Implement prepare(texts). Call embeddings.embed(text) once per distinct input string, preserving original output order. Return {"vectors": [...], "calls": integer}. Empty input makes zero calls. The included embedding fixture returns [len(text)]. Calls and vectors are checked; timing is not scored.

Review rubric

  • Correctness on documented inputs
  • Tests and edge cases
  • Clear explanation of trade-offs

Reading the ticket and starter files is public. Sign in to save edits, run tests and submit evidence. Code-review quality requires human review.

Starter repository

README.md
# InferenceAI engineering lab

Read the ticket, inspect the files, reproduce the issue and implement the contract. Run visible tests while working. Submit checks protected cases. Explain your changes and limitations.
pipeline.py
import embeddings
def prepare(texts):
    embeddings.calls = 0
    vectors = [embeddings.embed(text) for text in texts]
    return {"vectors": vectors, "calls": embeddings.calls}
embeddings.py
calls = 0
def embed(text):
    global calls
    calls += 1
    return [len(text)]
tests/test_pipeline.py
import unittest
from pipeline import *

class ContractTest(unittest.TestCase):
    def test_example(self):
        self.assertEqual(prepare(["hello", "hello"]), {"vectors": [[5],[5]], "calls": 1})