Skip to content

Commit 50e4918

Browse files
committed
changes
1 parent 224d562 commit 50e4918

File tree

5 files changed

+30
-10
lines changed

5 files changed

+30
-10
lines changed

src/client/components/Rag/Rag.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import React, { useState } from 'react'
2-
import { TextField, Button, Box, Typography, Table, TableHead, TableBody, TableRow, TableCell, Paper, IconButton, Link } from '@mui/material'
2+
import { TextField, Button, Box, Typography, Table, TableHead, TableBody, TableRow, TableCell, Paper, Link } from '@mui/material'
33
import apiClient from '../../util/apiClient'
44
import { useMutation, useQuery } from '@tanstack/react-query'
5-
import { Settings } from '@mui/icons-material'
6-
import { useSnackbar } from 'notistack'
75
import { useNavigate, Link as RouterLink } from 'react-router-dom'
86
import { Chunk } from './Chunk'
97

@@ -50,9 +48,8 @@ const useCreateRagIndexMutation = () => {
5048
}
5149

5250
const Rag: React.FC = () => {
53-
const { enqueueSnackbar } = useSnackbar()
5451
const navigate = useNavigate()
55-
const { data: indices, refetch } = useRagIndices()
52+
const { data: indices } = useRagIndices()
5653
const createIndexMutation = useCreateRagIndexMutation()
5754
const [indexName, setIndexName] = useState('')
5855
const [selectedIndex, setSelectedIndex] = useState<RagIndexAttributes>(null)

src/config.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@ export const PUBLIC_URL = process.env.PUBLIC_URL || ''
1212

1313
export const UPDATER_CRON_ENABLED = process.env.UPDATER_CRON_ENABLED === 'true'
1414

15-
export const OLLAMA_URL = process.env.OLLAMA_HOST || 'http://ollama:11434/v1/'
15+
export const OLLAMA_URL = process.env.OLLAMA_URL || 'http://ollama:11434/v1/'
1616
export const RAG_ENABLED = process.env.RAG_ENABLED === 'true'
1717

18+
export const LAAMA_API_URL = process.env.LAAMA_API_URL || ''
19+
export const LAAMA_API_TOKEN = process.env.LAAMA_API_TOKEN || ''
20+
1821
export const DEFAULT_TOKEN_LIMIT = Number(process.env.DEFAULT_TOKEN_LIMIT) || 150_000
1922

2023
export const FREE_MODEL = process.env.FREE_MODEL || 'gpt-4o-mini' // as it was decided in 23th Sept 2024 meeting

src/server/services/rag/embed.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { EMBED_DIM, EMBED_MODEL } from '../../../config'
22
import type OpenAI from 'openai'
3+
import { getOllamaClient } from '../../util/ollama'
34

45
export const getEmbeddingVector = async (client: OpenAI, query: string) => {
56
const response = await client.embeddings.create({
@@ -22,3 +23,13 @@ export const getEmbeddingVectorBatch = async (client: OpenAI, queries: string[])
2223

2324
return response.data
2425
}
26+
27+
export const getOllamaEmbeddingVectorBatch = async (query: string[]) => {
28+
const client = getOllamaClient()
29+
const response = await client.embed({
30+
model: EMBED_MODEL,
31+
input: query,
32+
})
33+
34+
return response.embeddings
35+
}

src/server/services/rag/ingestion/embedder.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { Chunk } from './chunkingAlgorithms.ts'
22
import { mkdirSync } from 'node:fs'
33
import { writeFile } from 'node:fs/promises'
4-
import { getEmbeddingVectorBatch } from '../embed'
4+
import { getEmbeddingVectorBatch, getOllamaEmbeddingVectorBatch } from '../embed'
55
import OpenAI from 'openai'
66

77
export type EmbeddedChunk = Chunk & {
@@ -42,13 +42,13 @@ export class Embedder {
4242
private async embedBatch() {
4343
const chunkContents = this.currentBatch.map((chunk) => chunk.content.join('\n'))
4444
const startedAt = Date.now()
45-
const result = await getEmbeddingVectorBatch(this.client, chunkContents)
45+
const result = await getOllamaEmbeddingVectorBatch(chunkContents)
4646
const elapsed = Date.now() - startedAt
4747
console.log(`Embedded ${chunkContents.length} chunks in ${elapsed}ms`)
4848

4949
const embeddedChunks: EmbeddedChunk[] = this.currentBatch.map((chunk, index) => ({
5050
...chunk,
51-
embedding: result[index].embedding,
51+
embedding: result[index],
5252
}))
5353

5454
await Promise.all(

src/server/util/ollama.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
1-
import { OLLAMA_URL } from '../../config'
1+
import { Ollama } from 'ollama'
2+
import { LAAMA_API_TOKEN, LAAMA_API_URL, OLLAMA_URL } from '../../config'
23
import OpenAI from 'openai'
34

5+
export const getOllamaClient = () =>
6+
new Ollama({
7+
host: LAAMA_API_URL,
8+
headers: {
9+
token: LAAMA_API_TOKEN,
10+
},
11+
})
12+
413
export const getOllamaOpenAIClient = () =>
514
new OpenAI({
615
apiKey: 'NOT_NEEDED',

0 commit comments

Comments
 (0)