-
Notifications
You must be signed in to change notification settings - Fork 70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Integration tests for Similarity Search API. #450
base: main
Are you sure you want to change the base?
Conversation
@Lavriz |
hey! sorry for the delay, you're absolutely right on upgrading the version! thanks for noticing it |
I included the vitest upgrade, let me know if there's anything else needed |
Putting this on draft for now, as Evgeny pointed out that additional tests for vectorization and vector DB querying should be added. I've researched Cloudflare docs on how to properly test auxiliary workers, but no success yet. |
…or vectorization and db querying, refactered existing tests
|
describe("Functionality", () => { | ||
it("runs AI model and gets vectorized string back", async () => { | ||
const response = await env.AI.run("@cf/baai/bge-base-en-v1.5", { | ||
text: ["Sample text"], | ||
}) | ||
expect(response).toHaveProperty("data") | ||
}) | ||
|
||
it("queries vector database and gets proper response", async () => { | ||
const response = await env.VECTORIZE_INDEX.query([1, 2, 3], { | ||
namespace: "test-namespace", | ||
topK: 1, | ||
}) | ||
expect(response).toHaveProperty("matches") | ||
expect(response.matches.length).toBeGreaterThan(0) | ||
}) | ||
|
||
it("returns similarity score for valid requests", async () => { | ||
const response = await SELF.fetch("https://example.com/", { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
"X-API-Key": "test-api-key", | ||
}, | ||
body: JSON.stringify({ | ||
text: "Sample text", | ||
namespace: "test-namespace", | ||
}), | ||
}) | ||
|
||
expect(response.status).toBe(200) | ||
const jsonResponse: SimilarityCheckResponse = await response.json() | ||
expect(jsonResponse).toHaveProperty("similarity_score") | ||
expect(typeof jsonResponse.similarity_score).toBe("number") | ||
}) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These look like unit tests to me. For example, you can't trigger Worker AI yourself - this function is an internal component of the worker you are testing. Same for querying vectorize. The only trigger at your disposal is user's request. You can, however, assert all other worker interactions, including worker AI being called and vector DB being queried.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These look like unit tests to me.
That's what I thought initially when you told me that these services behavior should be tested too. But now I see what you are talking about.
I changed it so now we are just looking at what AI and DB are called with and what they return during normal request to a service, instead of calling them directly. I don't know if this is sufficient, or the abstraction has to be even deeper.
Closes #430
Hello! I am glad to take part in your challenge program. I started with the easiest one, but I plan to try harder ones later.
My process was:
I ended up making two new tests out of an authentication test that was already there, to cover all cases. Plus I added tests for validation and functionality.
One more thing to consider is that we are currently using vitest 1.2, but the docs mention that they only support 1.5.
I haven't upgraded the package, as I wanted to consult first.