-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
76 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
import { type StoredDocument } from './corpus' | ||
import { chunk } from './doc/chunks' | ||
import { type Doc } from './doc/doc' | ||
|
||
export function corpusData(docs: Doc[]): CorpusData { | ||
const data: CorpusData = { docs: [] } | ||
|
||
const seenIDs = new Set<number>() | ||
for (const doc of docs) { | ||
const chunks = chunk(doc.text, { isMarkdown: doc.text.includes('##') }) | ||
data.docs.push({ doc, chunks }) | ||
if (seenIDs.has(doc.id)) { | ||
throw new Error(`duplicate doc ID: ${doc.id}`) | ||
} | ||
seenIDs.add(doc.id) | ||
} | ||
|
||
return data | ||
return { docs } | ||
} | ||
|
||
export interface CorpusData { | ||
docs: StoredDocument[] | ||
docs: Doc[] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { type CorpusData } from './data' | ||
import { chunk } from './doc/chunks' | ||
import { type IndexedDoc } from './doc/doc' | ||
|
||
export interface CorpusIndex { | ||
data: CorpusData | ||
|
||
docs: IndexedDoc[] | ||
} | ||
|
||
export function indexCorpus(data: CorpusData): CorpusIndex { | ||
const index: CorpusIndex = { data, docs: [] } | ||
|
||
for (const doc of data.docs) { | ||
const chunks = chunk(doc.text, { isMarkdown: doc.text.includes('##') }) | ||
index.docs.push({ doc, chunks }) | ||
} | ||
|
||
return index | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters