ChrisC
Convex Community5mo ago
1 reply
Chris

Inconsistent behavior with Convex Agent Text & Vector Search

When I try to search for messages using the generate text or stream text functions, I receive an error stating that there are no messages to search. However, when I call the fetch context message function, I can search for messages. I'm wondering what's going on or what I might be missing.

Error --[Error: No messages to search]

const stream = createUIMessageStream({
      execute: async ({ writer }) => {
        try {
          const result = await thread.streamText(
            { ...streamTextConfig },
            {
              saveStreamDeltas: true,
              contextOptions: {
                searchOptions: {
                  //   textSearch: true,
                  vectorSearch: true,
                  limit: 10,
                },
                searchOtherThreads: true,
              },
            }
          );
        //   console.log(await result.steps);
          writer.merge(result.toUIMessageStream({ originalMessages: [] }));
        } catch (error) {
          console.log("Something went wrong");
          console.error(error);
        }
      },
    });


But this fetches the messages:

const messages: MessageDoc[] = await agent.fetchContextMessages(ctx, {
    threadId,
    messages: [{ role: "user", content: args.input.prompt }],
    userId, // Optional, unless `searchOtherThreads` is true.
    contextOptions: {
      searchOptions: {
        vectorSearch: true,
        limit: 10,
      },
      searchOtherThreads: true,
    },
  });
Was this page helpful?