Michael Rea
Michael Rea
CCConvex Community
Created by Michael Rea on 4/30/2024 in #support-community
How to approach Streaming Audio
https://docs.play.ht/reference/integrating-with-chatgpt So I'm wanting to use Play.ai text to speech where you can stream text results from an LLM like chatGPT and stream the audio back to the client. I'm having trouble conceptualising how I could even do this in convex if at all. My LLM logic and RAG is all happening in convex logic. Is it even possible to pipe a audio-stream back to the browser from a convex action? Not sure how to integrate something like this with my existing convex functions. I'm using NextJS. Cheers
2 replies
CCConvex Community
Created by Michael Rea on 4/10/2024 in #support-community
Vector search filter: Id NOT in array
const similarMessagesVectors = await ctx.vectorSearch("messageEmbeddings", "by_embedding", {
vector: promptEmbedding,
limit: 5,
filter: (q) => q.eq("userId", userId) && q.eq("chatId", chatId),
});
const similarMessagesVectors = await ctx.vectorSearch("messageEmbeddings", "by_embedding", {
vector: promptEmbedding,
limit: 5,
filter: (q) => q.eq("userId", userId) && q.eq("chatId", chatId),
});
I'm trying to vector search on messages but want to exclude a message (the most recent user prompt) based on Id before the search. Is this possible with the filter or does it just have to be done after?
3 replies
CCConvex Community
Created by Michael Rea on 3/25/2024 in #support-community
Query Caching
I'm trying to understand which approach is best. Do queries cache only on the level of the whole query? ---------- Option A:
//Schema
export const Chats = Table("chats", {
userId: v.id("users"),
});

export const Messages = Table("messages", {
userId: v.id("users"),
chatId: v.id("chats"),
role: v.string(),
content: v.string(),
});


.......messages: Messages.table.index("by_chatId_userId", ["chatId", "userId"]),
//Schema
export const Chats = Table("chats", {
userId: v.id("users"),
});

export const Messages = Table("messages", {
userId: v.id("users"),
chatId: v.id("chats"),
role: v.string(),
content: v.string(),
});


.......messages: Messages.table.index("by_chatId_userId", ["chatId", "userId"]),
export const get = queryWithUser({
args: { chatId: v.id("chats") },
handler: async (ctx, { chatId }): Promise<Doc<"messages">[]> => {
const messages = await ctx.db
.query("messages")
.withIndex("by_chatId_userId", (q) => q.eq("chatId", chatId).eq("userId", ctx.userId))
.order("desc")
.collect();
// .take(50);

if (messages.length === 0) {
return [];
}
return messages.reverse();
},
});
export const get = queryWithUser({
args: { chatId: v.id("chats") },
handler: async (ctx, { chatId }): Promise<Doc<"messages">[]> => {
const messages = await ctx.db
.query("messages")
.withIndex("by_chatId_userId", (q) => q.eq("chatId", chatId).eq("userId", ctx.userId))
.order("desc")
.collect();
// .take(50);

if (messages.length === 0) {
return [];
}
return messages.reverse();
},
});
---------- Option B:
export const Chats = Table("chats", {
userId: v.id("users"),
messageIds: v.array(v.id("messages")),
});

export const Messages = Table("messages", {
userId: v.id("users"),
chatId: v.id("chats"),
role: v.string(),
content: v.string(),
});
export const Chats = Table("chats", {
userId: v.id("users"),
messageIds: v.array(v.id("messages")),
});

export const Messages = Table("messages", {
userId: v.id("users"),
chatId: v.id("chats"),
role: v.string(),
content: v.string(),
});
export const getByIds = queryWithUser({
args: { messageIds: v.array(v.id("messages")) },
handler: async (ctx, { messageIds }): Promise<Doc<"messages">[]> => {
const messages = await Promise.all(
messageIds.map((Id: Id<"messages">) => {
return ctx.db.get(Id);
})
);
if (messages.length === 0) {
return [];
}
return messages.reverse();
},
});
export const getByIds = queryWithUser({
args: { messageIds: v.array(v.id("messages")) },
handler: async (ctx, { messageIds }): Promise<Doc<"messages">[]> => {
const messages = await Promise.all(
messageIds.map((Id: Id<"messages">) => {
return ctx.db.get(Id);
})
);
if (messages.length === 0) {
return [];
}
return messages.reverse();
},
});
----- Lets say a new message comes in, will option B be using the cached queries on each ID and get a non-cached for the new message? Compared to option A (where I'm unclear) does that get all the messages without cache OR actually uses the cache under the hood?
10 replies
CCConvex Community
Created by Michael Rea on 2/29/2024 in #support-community
queryWithUser on internalAction?
I've been using the convex helpers. I'm trying to use queryWithUser from an Action (thats is called from a mutationWithUser initially. For authentication on mutations and queries on internalActions how should I do it? I'm guessing Auth is not available on internalAction? Should I just not worry about Auth since my Action is spawning from a mutationWithUser anyway? Or should I just use actionWithUser instead?
3 replies
CCConvex Community
Created by Michael Rea on 2/9/2024 in #support-community
query that runs once?
Is there a way to load data from a query once and stop it from being updated on db change. I've got a collaborative text editor that I'm loading the initial data from convex using useQuery but I'm only using the data once when loading the component for the first time. Every time I make changes in the text editor the update note mutation is run and useQuery is run. Is it costing me to get the new data from useQuery everytime the user types? Since I only need to load the data intially it seems like a waste. So basically I'm looking for a non-realtime query read.
35 replies
CCConvex Community
Created by Michael Rea on 2/9/2024 in #support-community
Cancel scheduled func - Counted towards billing
No description
7 replies
CCConvex Community
Created by Michael Rea on 12/20/2023 in #support-community
Database bandwidth
No description
35 replies
CCConvex Community
Created by Michael Rea on 11/22/2023 in #support-community
ActionCtx depreciated?
No description
3 replies
CCConvex Community
Created by Michael Rea on 11/19/2023 in #support-community
Use helper functions or internalAction?
No description
4 replies
CCConvex Community
Created by Michael Rea on 11/13/2023 in #support-community
Authenticate actions?
Is it possible / needed to authenticate actions? const identity = await ctx.auth.getUserIdentity(); console.log("identity", identity); if (identity === null) { throw new Error("Unauthenticated call to action"); } identity is always null here....
5 replies