MCPcopy Create free account
hub / github.com/CaviraOSS/OpenReason / vectorize

Function vectorize

src/utils/vectorize.ts:1–15  ·  view source on GitHub ↗
(text: string)

Source from the content-addressed store, hash-verified

1export const vectorize = (text: string): number[] => {
2 const tokens = text.toLowerCase().split(/\s+/)
3 const vec = new Array(128).fill(0)
4
5 for (let i = 0; i < tokens.length; i++) {
6 const token = tokens[i]
7 for (let j = 0; j < token.length; j++) {
8 const code = token.charCodeAt(j) % 128
9 vec[code] += 1
10 }
11 }
12
13 const mag = Math.sqrt(vec.reduce((sum, val) => sum + val * val, 0))
14 return mag > 0 ? vec.map(v => v / mag) : vec
15}

Callers 5

load_prompt_seedsFunction · 0.90
choose_active_seedFunction · 0.90
get_similar_tracesFunction · 0.90
createCacheNodeFunction · 0.90
standard_reasonFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected