Реализована операции Milvus для управления документами и встраиванием, включая функции вставки, запроса и удаления. Внедрите архитектуру RAG с LLM и сервисами встраивания. Добавьте обработку текста для фрагментации и конкатенации. Создайте автономный скрипт для настройки и управления Milvus. Разработайте комплексные тесты API для обработки документов и взаимодействия с LLM, включая имитации для сервисов. Расширьте возможности конфигурации пользователя с помощью дополнительных настроек YAML.
This commit is contained in:
50
internal/pkg/textprocessor/textprocessor.go
Normal file
50
internal/pkg/textprocessor/textprocessor.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package textprocessor
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"strings"
|
||||
|
||||
"github.com/jonathanhecl/chunker"
|
||||
)
|
||||
|
||||
func CreateChunks(text string) []string {
|
||||
// Maximum characters per chunk
|
||||
const maxCharacters = 5000 // too slow otherwise
|
||||
|
||||
var chunks []string
|
||||
var currentChunk strings.Builder
|
||||
|
||||
// Use the chunker library to split text into sentences
|
||||
sentences := chunker.ChunkSentences(text)
|
||||
|
||||
for _, sentence := range sentences {
|
||||
// Check if adding the sentence exceeds the character limit
|
||||
if currentChunk.Len()+len(sentence) <= maxCharacters {
|
||||
if currentChunk.Len() > 0 {
|
||||
currentChunk.WriteString(" ") // Add a space between sentences
|
||||
}
|
||||
currentChunk.WriteString(sentence)
|
||||
} else {
|
||||
// Add the completed chunk to the chunks slice
|
||||
chunks = append(chunks, currentChunk.String())
|
||||
currentChunk.Reset() // Start a new chunk
|
||||
currentChunk.WriteString(sentence) // Add the sentence to the new chunk
|
||||
}
|
||||
}
|
||||
|
||||
// Add the last chunk if it has content
|
||||
if currentChunk.Len() > 0 {
|
||||
chunks = append(chunks, currentChunk.String())
|
||||
}
|
||||
|
||||
// Return the chunks
|
||||
return chunks
|
||||
}
|
||||
|
||||
func ConcatenateStrings(strings []string) string {
|
||||
var result bytes.Buffer
|
||||
for _, str := range strings {
|
||||
result.WriteString(str)
|
||||
}
|
||||
return result.String()
|
||||
}
|
||||
Reference in New Issue
Block a user