72 lines
2.5 KiB
Java
72 lines
2.5 KiB
Java
package com.superbiz.agent.service;
|
|
|
|
import com.superbiz.agent.dto.DocumentChunk;
|
|
import com.superbiz.agent.dto.Frontmatter;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
import java.util.Map;
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
|
|
class VectorIndexServiceTest {
|
|
|
|
@Test
|
|
void buildEmbeddingTextIncludesTitleAndBreadcrumb() {
|
|
DocumentChunk chunk = DocumentChunk.builder()
|
|
.title("Connection Pool")
|
|
.breadcrumb("Database > MySQL > Connection Pool")
|
|
.content("Check active connections and leak detection.")
|
|
.build();
|
|
|
|
String embeddingText = VectorIndexService.buildEmbeddingText(chunk);
|
|
|
|
assertEquals("""
|
|
Title: Connection Pool
|
|
Path: Database > MySQL > Connection Pool
|
|
Content:
|
|
Check active connections and leak detection.""", embeddingText);
|
|
}
|
|
|
|
@Test
|
|
void buildEmbeddingTextKeepsPlainContentWhenNoStructureExists() {
|
|
DocumentChunk chunk = DocumentChunk.builder()
|
|
.title(" ")
|
|
.breadcrumb(null)
|
|
.content("Plain chunk content.")
|
|
.build();
|
|
|
|
assertEquals("Plain chunk content.", VectorIndexService.buildEmbeddingText(chunk));
|
|
}
|
|
|
|
@Test
|
|
void buildDocumentMetadataUsesFrontmatterRetrievalFields() {
|
|
DocumentChunk chunk = DocumentChunk.builder()
|
|
.chunkIndex(0)
|
|
.title("Chunk Title")
|
|
.breadcrumb("Chunk > Path")
|
|
.content("content")
|
|
.build();
|
|
Frontmatter frontmatter = Frontmatter.builder()
|
|
.title("Document Title")
|
|
.source("mysql-connection-pool")
|
|
.breadcrumb("Database > MySQL > Connection Pool")
|
|
.kbScope("rag-eval")
|
|
.build();
|
|
|
|
Map<String, Object> metadata = VectorIndexService.buildDocumentMetadata(
|
|
"mysql-connection-pool",
|
|
chunk,
|
|
2,
|
|
"database",
|
|
frontmatter
|
|
);
|
|
|
|
assertEquals("mysql-connection-pool", metadata.get("docId"));
|
|
assertEquals("mysql-connection-pool", metadata.get("_source"));
|
|
assertEquals("mysql-connection-pool", metadata.get("source"));
|
|
assertEquals("database", metadata.get("category"));
|
|
assertEquals("rag-eval", metadata.get("kb_scope"));
|
|
assertEquals("Database > MySQL > Connection Pool", metadata.get("breadcrumb"));
|
|
}
|
|
}
|