Feat: take multiple spaceIds while ingesting

This commit is contained in:
Manoj 2025-10-09 11:16:44 +05:30
parent 0a75a68d1d
commit f132833832
5 changed files with 33 additions and 22 deletions

View File

@ -29,7 +29,6 @@ export const addToQueue = async (
const queuePersist = await prisma.ingestionQueue.create({
data: {
spaceId: body.spaceId ? body.spaceId : null,
data: body,
type: body.type,
status: IngestionStatus.PENDING,

View File

@ -16,7 +16,7 @@ export const IngestBodyRequest = z.object({
referenceTime: z.string(),
metadata: z.record(z.union([z.string(), z.number(), z.boolean()])).optional(),
source: z.string(),
spaceId: z.string().optional(),
spaceIds: z.array(z.string()).optional(),
sessionId: z.string().optional(),
type: z
.enum([EpisodeType.CONVERSATION, EpisodeType.DOCUMENT])
@ -151,25 +151,28 @@ export const ingestTask = task({
// Handle space assignment after successful ingestion
try {
// If spaceId was explicitly provided, immediately assign the episode to that space
if (episodeBody.spaceId && episodeDetails.episodeUuid) {
logger.info(`Assigning episode to explicitly provided space`, {
// If spaceIds were explicitly provided, immediately assign the episode to those spaces
if (episodeBody.spaceIds && episodeBody.spaceIds.length > 0 && episodeDetails.episodeUuid) {
logger.info(`Assigning episode to explicitly provided spaces`, {
userId: payload.userId,
episodeId: episodeDetails.episodeUuid,
spaceId: episodeBody.spaceId,
spaceIds: episodeBody.spaceIds,
});
// Assign episode to each space
for (const spaceId of episodeBody.spaceIds) {
await assignEpisodesToSpace(
[episodeDetails.episodeUuid],
episodeBody.spaceId,
spaceId,
payload.userId,
);
}
logger.info(
`Skipping LLM space assignment - episode explicitly assigned to space ${episodeBody.spaceId}`,
`Skipping LLM space assignment - episode explicitly assigned to ${episodeBody.spaceIds.length} space(s)`,
);
} else {
// Only trigger automatic LLM space assignment if no explicit spaceId was provided
// Only trigger automatic LLM space assignment if no explicit spaceIds were provided
logger.info(
`Triggering LLM space assignment after successful ingestion`,
{

View File

@ -49,9 +49,12 @@ const IngestSchema = {
type: "string",
description: "The data to ingest in text format",
},
spaceId: {
spaceIds: {
type: "array",
items: {
type: "string",
description: "Optional: UUID of the space to associate this memory with. If working on a specific project, provide the space ID to organize the memory in that project's context.",
},
description: "Optional: Array of space UUIDs to associate this memory with. If working on specific projects, provide space IDs to organize the memory in those project contexts. The episode will be assigned to all specified spaces.",
},
},
required: ["message"],
@ -244,7 +247,7 @@ async function handleMemoryIngest(args: any) {
referenceTime: new Date().toISOString(),
source: args.source,
type: EpisodeTypeEnum.CONVERSATION,
spaceId: args.spaceId,
spaceIds: args.spaceIds,
},
args.userId,
);

View File

@ -0,0 +1,11 @@
/*
Warnings:
- You are about to drop the column `spaceId` on the `IngestionQueue` table. All the data in the column will be lost.
*/
-- DropForeignKey
ALTER TABLE "IngestionQueue" DROP CONSTRAINT "IngestionQueue_spaceId_fkey";
-- AlterTable
ALTER TABLE "IngestionQueue" DROP COLUMN "spaceId";

View File

@ -113,10 +113,6 @@ model ConversationHistory {
model IngestionQueue {
id String @id @default(cuid())
// Relations
space Space? @relation(fields: [spaceId], references: [id])
spaceId String?
// Queue metadata
data Json // The actual data to be processed
output Json? // The processed output data
@ -494,7 +490,6 @@ model Space {
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
IngestionQueue IngestionQueue[]
SpacePattern SpacePattern[]
}