Skip to content

Commit 679f342

Browse files
committed
add document title to chroma metadata
1 parent 4fbfbe6 commit 679f342

File tree

5 files changed

+19
-11
lines changed

5 files changed

+19
-11
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,6 @@
5555
"npm": ">=8.5.5"
5656
},
5757
"volta": {
58-
"node": "16.15.0"
58+
"node": "21.7.3"
5959
}
6060
}

src/documents.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@ export default class Documents {
1111
id: string,
1212
document: string,
1313
source: string,
14-
type: DocumentType
14+
type: DocumentType,
15+
title: string
1516
): Documents {
1617
this.ids.push(id);
1718
this.documents.push(document);
18-
this.metadatas.push({ source, type });
19+
this.metadatas.push({ source, type, title });
1920
return this;
2021
}
2122

src/generate-document.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ interface GeneratedDocument {
55
source: string;
66
document: string;
77
type: DocumentType;
8+
title: string;
89
}
910

1011
export default (docLike: any): GeneratedDocument => {
@@ -50,5 +51,5 @@ export default (docLike: any): GeneratedDocument => {
5051
if (processedRefs) document = `${document}\nReferences:\n${processedRefs}`;
5152

5253
document = `${document}\nURL: ${source}`;
53-
return { id, source, type, document };
54+
return { id, source, type, document, title: displayName };
5455
};

src/index.ts

+12-6
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,19 @@ export const main = async (spaceId: string) => {
1616
logger.info(`Space ${space.nameID} loaded.`);
1717

1818
const documents = new Documents();
19-
const { id, source, document, type } = generateDocument(space);
20-
documents.add(id, document, source, type);
19+
const { id, source, document, type, title } = generateDocument(space);
20+
documents.add(id, document, source, type, title);
2121

2222
for (let i = 0; i < (space.subspaces || []).length; i++) {
2323
const challenge = (space.subspaces || [])[i];
24-
const { id, source, document, type } = generateDocument(challenge);
25-
documents.add(id, document, source, type);
24+
const { id, source, document, type, title } = generateDocument(challenge);
25+
documents.add(id, document, source, type, title);
2626

2727
for (let j = 0; j < (challenge.collaboration?.callouts || []).length; j++) {
2828
const callout = (challenge.collaboration?.callouts || [])[j];
2929
const { id, type } = callout;
3030
const generated = generateDocument(callout.framing);
31-
const source = generated.source;
31+
const { title, source } = generated;
3232
let document = generated.document;
3333

3434
// extra loop but will do for now
@@ -59,7 +59,13 @@ export const main = async (spaceId: string) => {
5959
if (processedMessages)
6060
document = `${document}\nMessages:\n${processedMessages}`;
6161

62-
documents.add(id, document, source, type as unknown as DocumentType);
62+
documents.add(
63+
id,
64+
document,
65+
source,
66+
type as unknown as DocumentType,
67+
title
68+
);
6369
}
6470
}
6571
await ingest(space.nameID, documents);

src/ingest.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export default async (space: string, docs: Documents) => {
2929

3030
const collection = await client.getOrCreateCollection({ name: space });
3131

32-
await collection.add({
32+
await collection.upsert({
3333
...forEmbed,
3434
embeddings: data.map(({ embedding }) => embedding),
3535
});

0 commit comments

Comments
 (0)