Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions js/plugins/ollama/src/embeddings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import type { Document, EmbedderAction, Genkit } from 'genkit';
import type { Document, EmbedderAction } from 'genkit';
import { embedder } from 'genkit/plugin';
import type { EmbedRequest, EmbedResponse } from 'ollama';
import type { DefineOllamaEmbeddingParams, RequestHeaders } from './types.js';

async function toOllamaEmbedRequest(
export async function toOllamaEmbedRequest(
modelName: string,
dimensions: number,
documents: Document[],
Expand Down Expand Up @@ -59,11 +60,13 @@ async function toOllamaEmbedRequest(
};
}

export function defineOllamaEmbedder(
ai: Genkit,
{ name, modelName, dimensions, options }: DefineOllamaEmbeddingParams
): EmbedderAction<any> {
return ai.defineEmbedder(
export function defineOllamaEmbedder({
name,
modelName,
dimensions,
options,
}: DefineOllamaEmbeddingParams): EmbedderAction<any> {
return embedder(
{
name: `ollama/${name}`,
info: {
Expand All @@ -76,12 +79,12 @@ export function defineOllamaEmbedder(
},
},
async (input, config) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename input to request, as I believe this better reflects the params intentions here.

const serverAddress = config?.serverAddress || options.serverAddress;
const serverAddress = options.serverAddress || 'http://localhost:11434';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where does that address come from? Is there no better alternatives than having this?


const { url, requestPayload, headers } = await toOllamaEmbedRequest(
modelName,
dimensions,
input,
input.input,
serverAddress,
options.requestHeaders
);
Expand Down
Loading