Vector Search ✖ TypeScript typecheck via tsc failed.
Hello everyone, I'm building on the Vector Search feature and I'm encountering an issue like this:
-----------------------------------------
✖ TypeScript typecheck via tsc failed.
To ignore failing typecheck, use --typecheck=disable.
convex/messages.ts:144:34 - error TS2339: Property 'vectorSearch' does not exist on type 'GenericDatabaseReader<{ messages: { document: { _id: Id<"messages">; _creationTime: number; format?: string | undefined; fileId?: Id<"_storage"> | undefined; fileName?: string | undefined; author: string; body: string; }; fieldPaths: "_id" | ExtractFieldPaths<...>; indexes: { ...; }; searchIndexes: {}; vectorIndexes...'.
144 const results = await ctx.db.vectorSearch("vectorDocuments", "by_embedding", {
~~
convex/messages.ts:148:36 - error TS2339: Property 'getMany' does not exist on type 'GenericDatabaseReader<{ messages: { document: { _id: Id<"messages">; _creationTime: number; format?: string | undefined; fileId?: Id<"_storage"> | undefined; fileName?: string | undefined; author: string; body: string; }; fieldPaths: "_id" | ExtractFieldPaths<...>; indexes: { ...; }; searchIndexes: {}; vectorIndexes...'.
148 const documents = await ctx.db.getMany("vectorDocuments", results.map((result: any) => result._id));
~
Found 2 errors in the same file, starting at: convex/messages.ts:144
----------------------------------------------
Looking forward to everyone's help, thank you very much.
4 Replies
Thanks for posting in <#1088161997662724167>.
Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets.
- Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.)
- Use search.convex.dev to search Docs, Stack, and Discord all at once.
- Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI.
- Avoid tagging staff unless specifically instructed.
Thank you!
Re: the first error, you're trying to do a vector search in a mutation, but vector searches are only available in Convex actions, per this page in the docs: https://docs.convex.dev/search/vector-search
Re: the second error, the error message spells it out pretty clearly:
getMany
isn't a property on the db
object. It's a helper function, so you call it directly and pass the db
value to it. Check the Stack post about the helper functions to see examples of correct usage: https://stack.convex.dev/functional-relationships-helpersVector Search | Convex Developer Hub
Run vector search queries on embeddings
Database Relationship Helpers
Traverse database relationships in a readable, predictable, and debuggable way. Support for one-to-one, one-to-many, and many-to-many via utility func...
Thank you!
This is the next error that occurs, hope you can help me resolve it.
------------------------------------
✖ TypeScript typecheck via
tsc
failed.
To ignore failing typecheck, use --typecheck=disable
.
convex/messages.ts:153:41 - error TS2339: Property 'db' does not exist on type 'GenericActionCtx<{ messages: { document: { _id: Id<"messages">; _creationTime: number; format?: string | undefined; fileId?: Id<"_storage"> | undefined; fileName?: string | undefined; author: string; body: string; }; fieldPaths: "_id" | ExtractFieldPaths<...>; indexes: { ...; }; searchIndexes: {}; vectorIndexes: {};...'.
153 const documents = await getMany(ctx.db, "vectorDocuments", results.map((result: any) => result._id));
~~
Found 1 error in convex/messages.ts:153Please refer again to the Stack article I mentioned above. In that article, there's no mention of a
getMany
relationship helper function. There are two functions that begin with that prefix, but they serve different purposes. Please read about each of them, then use the correct function name based on what you're trying to do.