@@ -42,6 +42,7 @@ export function registerDocsTools(agent: CloudflareMcpAgentNoAccount, env: Requi
4242 . map ( ( result ) => {
4343 return `<result>
4444<url>${ result . url } </url>
45+ <title>${ result . title } </title>
4546<text>
4647${ result . text }
4748</text>
@@ -93,10 +94,8 @@ ${result.text}
9394}
9495
9596async function queryVectorize ( ai : Ai , vectorizeIndex : VectorizeIndex , query : string , topK : number ) {
96- // Recommendation from: https://huggingface.co/BAAI/bge-base-en-v1.5#model-list
97- const [ queryEmbedding ] = await getEmbeddings ( ai , [
98- 'Represent this sentence for searching relevant passages: ' + query ,
99- ] )
97+ // Recommendation from: https://ai.google.dev/gemma/docs/embeddinggemma/model_card#prompt_instructions
98+ const [ queryEmbedding ] = await getEmbeddings ( ai , [ 'task: search result | query: ' + query ] )
10099
101100 const { matches } = await vectorizeIndex . query ( queryEmbedding , {
102101 topK,
@@ -108,6 +107,7 @@ async function queryVectorize(ai: Ai, vectorizeIndex: VectorizeIndex, query: str
108107 similarity : Math . min ( match . score , 1 ) ,
109108 id : match . id ,
110109 url : sourceToUrl ( String ( match . metadata ?. filePath ?? '' ) ) ,
110+ title : String ( match . metadata ?. title ?? '' ) ,
111111 text : String ( match . metadata ?. text ?? '' ) ,
112112 } ) )
113113}
@@ -123,15 +123,15 @@ function sourceToUrl(path: string) {
123123 )
124124}
125125
126- async function getEmbeddings ( ai : Ai , strings : string [ ] ) {
126+ async function getEmbeddings ( ai : Ai , strings : string [ ] ) : Promise < number [ ] [ ] > {
127127 const response = await doWithRetries ( ( ) =>
128- ai . run ( '@cf/baai/bge-base-en-v1.5' , {
128+ // @ts -expect-error embeddinggemma not in types yet
129+ ai . run ( '@cf/google/embeddinggemma-300m' , {
129130 text : strings ,
130- // @ts -expect-error pooling not in types yet
131- pooling : 'cls' ,
132131 } )
133132 )
134133
134+ // @ts -expect-error embeddinggemma not in types yet
135135 return response . data
136136}
137137
0 commit comments