- Spring AI 란
- Spring AI 환경 설정
① CMD에 로컬 LLM 세팅
ollama run llama3

터미널로도 LLM (AI Agent) 사용 가능하다.
물론, GUI가 훨씬 편하겠지만.
llama에 직접 물어보았다.
Q. ollama + spring ai 기반 rag 서비스 모델의 아키텍쳐 구축 절차는 ?

6단계 까지 절차를 상세히 알려주었다.
환경설정을 제외하고 다음의 절차를 참고하면 된다.
Step 4: Implement the LLaMA Service
LlamaService.java. This will be the entry point for your LLaMApom.xml file:<dependency>
<groupId>com.meta.ai</groupId>
<artifactId>llama-api-client</artifactId>
<version>1.0.0</version>
</dependency>
LlamaService class using the LLaMA API client library. You can use the following example code asimport com.meta.ai.llama.LlamaApi;
import com.meta.ai.llma.LlamaResponse;
public class LlamaService {
private static final String LLA_MA_API_KEY = "YOUR_LLA_MA_API_KEY";
private static final LlamaApi llamaApi = new LlamaApi(LLLLA_MA_API_KEY);
public LLaMAResponse processRequest(String input) {
// Call the LLaMA API to generate a response
return llamaApi.generateResponse(input);
}
}
Step 5: Create a RESTful API endpoint
LlamaController.java. This will handle incoming requests andLlamaService class.LlamaController class using Spring Boot's Web annotation:import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class LlamaController {
private final LlamaService llamaService;
public LlamaController(LlamaService llamaService) {
this.llamaService = llamaService;
}
@PostMapping("/llama")
public LLaMAResponse processRequest(@RequestBody String input) {
return llamaService.processRequest(input);
}
}
Step 6: Configure Spring Cloud
application.properties file, add the following configuration:spring:
cloud:
bus:
enabled: true
This enables Spring Cloud's event bus, which will allow you to publish and subscribe to events in your
application.
Step 7: Deploy and test
plugins {
id 'java'
id 'org.springframework.boot' version '4.0.6'
id 'io.spring.dependency-management' version '1.1.7'
}
group = 'com.github.hjyang.rag'
version = '0.0.1-SNAPSHOT'
java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
}
repositories {
mavenCentral()
maven { url 'https://repo.spring.io/milestone' }
}
dependencyManagement {
imports {
mavenBom "org.springframework.ai:spring-ai-bom:1.0.0-M4"
}
}
dependencies {
// Starter 위주로 선언 (Starter가 core와 연관 라이브러리를 자동으로 가져옵니다)
implementation "org.springframework.ai:spring-ai-openai-spring-boot-starter"
implementation 'org.springframework.ai:spring-ai-chroma-store-spring-boot-starter'
// 문서 파싱 라이브러리
implementation 'org.springframework.ai:spring-ai-pdf-document-reader'
implementation 'org.springframework.ai:spring-ai-tika-document-reader'
// Spring Boot 기본 스타터
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web' // webmvc 대신 starter-web 권장
// Lombok 및 도구
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
// DB
runtimeOnly 'com.h2database:h2'
// Test
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testCompileOnly 'org.projectlombok:lombok'
testAnnotationProcessor 'org.projectlombok:lombok'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}
tasks.named('test') {
useJUnitPlatform()
}

결과에 llama3랑 nomic-embed-text 없으면:
ollama pull llama3
ollama pull nomic-embed-text
ollama pull 이란?
- 모델 원격 저장소에서 llm을 로컬로 가져오는 명령어
ollama run 이란?- 모델을 실행하여 대화 세션을 시작하기 위한 명령어
curl http://localhost:8000/api/v1/heartbeat
-- v1이 안되면 v2로 시도
chroma run --path ./chroma-data --port 8000

⭕ 올바르게 동작 중인 경우
