Skip to content

Commit 588cc7e

Browse files
committed
add ingestion purpose to space ingest
1 parent 679f342 commit 588cc7e

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

src/index.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import { AlkemioClient, createConfigUsingEnvVars } from '@alkemio/client-lib';
33

44
import Documents, { DocumentType } from './documents';
55
import logger from './logger';
6-
import ingest from './ingest';
6+
import ingest, { SpaceIngestionPurpose } from './ingest';
77
import generateDocument from './generate-document';
88

9-
export const main = async (spaceId: string) => {
9+
export const main = async (spaceId: string, purpose: SpaceIngestionPurpose) => {
1010
logger.info(`Ingest invoked for space ${spaceId}`);
1111
const config = createConfigUsingEnvVars();
1212
const alkemioCliClient = new AlkemioClient(config);
@@ -68,7 +68,7 @@ export const main = async (spaceId: string) => {
6868
);
6969
}
7070
}
71-
await ingest(space.nameID, documents);
71+
await ingest(space.nameID, documents, purpose);
7272
logger.info('Space ingested.');
7373
};
7474

@@ -83,7 +83,7 @@ export const main = async (spaceId: string) => {
8383
const connectionString = `amqp://${RABBITMQ_USER}:${RABBITMQ_PASSWORD}@${RABBITMQ_HOST}:${RABBITMQ_PORT}`;
8484

8585
const conn = await amqplib.connect(connectionString);
86-
const queue = RABBITMQ_QUEUE ?? 'virtual-contributor-added-to-space';
86+
const queue = RABBITMQ_QUEUE ?? 'ingest-space';
8787

8888
const channel = await conn.createChannel();
8989
await channel.assertQueue(queue);
@@ -94,7 +94,7 @@ export const main = async (spaceId: string) => {
9494
//maybe share them in a package
9595
//publish a confifrmation
9696
const decoded = JSON.parse(JSON.parse(msg.content.toString()));
97-
await main(decoded.spaceId);
97+
await main(decoded.spaceId, decoded.purpose);
9898
// add rety mechanism as well
9999
channel.ack(msg);
100100
} else {

src/ingest.ts

+17-7
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
import { ChromaClient } from 'chromadb';
22
import Documents from './documents';
33
import { OpenAIClient, AzureKeyCredential } from '@azure/openai';
4-
5-
export default async (space: string, docs: Documents) => {
4+
import { logger } from '@alkemio/client-lib';
5+
6+
export enum SpaceIngestionPurpose {
7+
Knowledge = 'kwnowledge',
8+
Context = 'context',
9+
}
10+
11+
export default async (
12+
spaceNameID: string,
13+
docs: Documents,
14+
purpose: SpaceIngestionPurpose
15+
) => {
616
const endpoint = process.env.AZURE_OPENAI_ENDPOINT;
717
const key = process.env.AZURE_OPENAI_API_KEY;
818
const depolyment = process.env.EMBEDDINGS_DEPLOYMENT_NAME;
@@ -11,10 +21,6 @@ export default async (space: string, docs: Documents) => {
1121
throw new Error('AI configuration missing from ENV.');
1222
}
1323

14-
console.log({
15-
path: `http://${process.env.VECTOR_DB_HOST}:${process.env.VECTOR_DB_PORT}`,
16-
});
17-
1824
const client = new ChromaClient({
1925
path: `http://${process.env.VECTOR_DB_HOST}:${process.env.VECTOR_DB_PORT}`,
2026
});
@@ -27,7 +33,11 @@ export default async (space: string, docs: Documents) => {
2733
const openAi = new OpenAIClient(endpoint, new AzureKeyCredential(key));
2834
const { data } = await openAi.getEmbeddings(depolyment, forEmbed.documents);
2935

30-
const collection = await client.getOrCreateCollection({ name: space });
36+
const name = `${spaceNameID}-${purpose}`;
37+
logger.info(`Adding to collection ${name}`);
38+
const collection = await client.getOrCreateCollection({
39+
name,
40+
});
3141

3242
await collection.upsert({
3343
...forEmbed,

0 commit comments

Comments
 (0)