Почему магазин векторов mongo не сохраняет мои документы?JAVA

Программисты JAVA общаются здесь
Ответить
Anonymous
 Почему магазин векторов mongo не сохраняет мои документы?

Сообщение Anonymous »

Я пытаюсь следовать инструкциям для Spring AI, представленным здесь. Я немного изменил проект репозитория, чтобы добавить дополнительное ведение журнала...

Код: Выделить всё

package org.example.repo;

import lombok.Data;
import org.example.model.WikiDocument;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ai.document.Document;
import org.springframework.ai.transformer.splitter.TokenTextSplitter;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Data
@Component
public class WikiDocumentsRepository {
private final VectorStore vectorStore;
private static final Logger logger = LoggerFactory.getLogger(WikiDocumentsRepository.class);

public void saveWikiDocument(WikiDocument wikiDocument) {
logger.info("Saving WikiDocument: {}", wikiDocument);

Map metadata = new HashMap();
metadata.put("filePath", wikiDocument.getFilePath());
Document document = new Document(wikiDocument.getContent(), metadata);
List documents = new TokenTextSplitter().apply(List.of(document));

logger.info("Metadata: {}", metadata);
logger.info("Documents before saving: {}", documents);

vectorStore.add(documents);

logger.info("Documents saved to vectorStore: {}", documents);
}
}
Я запускаю тест, как описано здесь, и результаты сохраняются правильно

Код: Выделить всё

2024-10-18T08:53:13.064-04:00  INFO 22484 --- [    Test worker] o.e.RAGMongoDBApplicationManualTest      : Starting RAGMongoDBApplicationManualTest using Java 23 with PID 22484 (started by jgleason in /home/jgleason/code/spring-ai/app)
2024-10-18T08:53:13.065-04:00  INFO 22484 --- [    Test worker] o.e.RAGMongoDBApplicationManualTest      : No active profile set, falling back to 1 default profile: "default"
2024-10-18T08:53:14.018-04:00  INFO 22484 --- [    Test worker] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data MongoDB repositories in DEFAULT mode.
2024-10-18T08:53:14.031-04:00  INFO 22484 --- [    Test worker] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 9 ms.  Found 0 MongoDB repository interfaces.
2024-10-18T08:53:14.465-04:00  INFO 22484 --- [    Test worker] org.mongodb.driver.client                : MongoClient with metadata {"driver": {"name": "mongo-java-driver|sync|spring-boot", "version": "5.0.1"}, "os": {"type": "Linux", "name": "Linux", "architecture": "amd64", "version": "5.15.153.1-microsoft-standard-WSL2"}, "platform": "Java/Oracle Corporation/23+37-2369"} created with settings MongoClientSettings{readPreference=primary, writeConcern=WriteConcern{w=null, wTimeout=null ms, journal=null}, retryWrites=true, retryReads=true, readConcern=ReadConcern{level=null}, credential=MongoCredential{mechanism=null, userName='admin', source='admin', password=, mechanismProperties=}, transportSettings=null, commandListeners=[io.micrometer.core.instrument.binder.mongodb.MongoMetricsCommandListener@72a3462f], codecRegistry=ProvidersCodecRegistry{codecProviders=[ValueCodecProvider{}, BsonValueCodecProvider{}, DBRefCodecProvider{}, DBObjectCodecProvider{}, DocumentCodecProvider{}, CollectionCodecProvider{}, IterableCodecProvider{}, MapCodecProvider{}, GeoJsonCodecProvider{}, GridFSFileCodecProvider{}, Jsr310CodecProvider{}, JsonObjectCodecProvider{}, BsonCodecProvider{}, EnumCodecProvider{}, com.mongodb.client.model.mql.ExpressionCodecProvider@4ffa7041, com.mongodb.Jep395RecordCodecProvider@632c3f55, com.mongodb.KotlinCodecProvider@56b05bd7]}, loggerSettings=LoggerSettings{maxDocumentLength=1000}, clusterSettings={hosts=[10.0.0.58:30087], srvServiceName=mongodb, mode=SINGLE, requiredClusterType=UNKNOWN, requiredReplicaSetName='null', serverSelector='null', clusterListeners='[]', serverSelectionTimeout='30000 ms', localThreshold='15 ms'}, socketSettings=SocketSettings{connectTimeoutMS=10000, readTimeoutMS=0, receiveBufferSize=0, proxySettings=ProxySettings{host=null, port=null, username=null, password=null}}, heartbeatSocketSettings=SocketSettings{connectTimeoutMS=10000, readTimeoutMS=10000, receiveBufferSize=0, proxySettings=ProxySettings{host=null, port=null, username=null, password=null}}, connectionPoolSettings=ConnectionPoolSettings{maxSize=100, minSize=0, maxWaitTimeMS=120000, maxConnectionLifeTimeMS=0, maxConnectionIdleTimeMS=0, maintenanceInitialDelayMS=0, maintenanceFrequencyMS=60000, connectionPoolListeners=[io.micrometer.core.instrument.binder.mongodb.MongoMetricsConnectionPoolListener@3e4afd10], maxConnecting=2}, serverSettings=ServerSettings{heartbeatFrequencyMS=10000, minHeartbeatFrequencyMS=500, serverListeners='[]', serverMonitorListeners='[]'}, sslSettings=SslSettings{enabled=false, invalidHostNameAllowed=false, context=null}, applicationName='null', compressorList=[], uuidRepresentation=JAVA_LEGACY, serverApi=null, autoEncryptionSettings=null, dnsClient=null, inetAddressResolver=null, contextProvider=null}
2024-10-18T08:53:14.543-04:00  INFO 22484 --- [10.0.0.58:30087] org.mongodb.driver.cluster               : Monitor thread successfully connected to server with description ServerDescription{address=10.0.0.58:30087, type=REPLICA_SET_PRIMARY, state=CONNECTED, ok=true, minWireVersion=0, maxWireVersion=25, maxDocumentSize=16777216, logicalSessionTimeoutMinutes=30, roundTripTimeNanos=21262679, setName='rs-localdev', canonicalAddress=localhost:27017, hosts=[localhost:27017], passives=[], arbiters=[], primary='localhost:27017', tagSet=TagSet{[]}, electionId=7fffffff0000000000000002, setVersion=1, topologyVersion=TopologyVersion{processId=6711964c6bfc3c21605fe477, counter=6}, lastWriteDate=Fri Oct 18 08:53:09 EDT 2024, lastUpdateTimeNanos=40013758872404}
2024-10-18T08:53:15.815-04:00  WARN 22484 --- [    Test worker] .s.s.UserDetailsServiceAutoConfiguration :

Using generated security password: ....

This generated password is for development use only.  Your security configuration must be updated before running your application in production.

2024-10-18T08:53:15.827-04:00  INFO 22484 --- [    Test worker] r$InitializeUserDetailsManagerConfigurer : Global AuthenticationManager configured with UserDetailsService bean with name inMemoryUserDetailsManager
2024-10-18T08:53:16.305-04:00  INFO 22484 --- [    Test worker] o.s.b.a.e.web.EndpointLinksResolver      : Exposing 1 endpoint beneath base path '/actuator'
2024-10-18T08:53:16.340-04:00  INFO 22484 --- [    Test worker] o.s.b.t.m.w.SpringBootMockServletContext : Initializing Spring TestDispatcherServlet ''
2024-10-18T08:53:16.340-04:00  INFO 22484 --- [    Test worker] o.s.t.web.servlet.TestDispatcherServlet  : Initializing Servlet ''
2024-10-18T08:53:16.341-04:00  INFO 22484 --- [    Test worker] o.s.t.web.servlet.TestDispatcherServlet  : Completed initialization in 1 ms
2024-10-18T08:53:16.592-04:00  INFO 22484 --- [    Test worker] o.e.RAGMongoDBApplicationManualTest      : Started RAGMongoDBApplicationManualTest in 3.744 seconds (process running for 4.679)
2024-10-18T08:53:17.317-04:00  INFO 22484 --- [    Test worker] o.example.repo.WikiDocumentsRepository   : Saving WikiDocument: WikiDocument(filePath=src/test/resources/documentation/owl-documentation.md, content=# Test 1)
2024-10-18T08:53:17.395-04:00  INFO 22484 --- [    Test worker] o.example.repo.WikiDocumentsRepository   : Metadata: {filePath=src/test/resources/documentation/owl-documentation.md}
2024-10-18T08:53:17.395-04:00  INFO 22484 --- [    Test worker] o.example.repo.WikiDocumentsRepository   : Documents before saving: [Document{id='dfcd9100-2396-4275-9a01-555806f25a45', metadata={filePath=src/test/resources/documentation/owl-documentation.md}, content='# Test 1', media=[]}]
2024-10-18T08:53:17.617-04:00  INFO 22484 --- [    Test worker] o.example.repo.WikiDocumentsRepository   : Documents saved to vectorStore: [Document{id='dfcd9100-2396-4275-9a01-555806f25a45', metadata={filePath=src/test/resources/documentation/owl-documentation.md}, content='# Test 1', media=[]}]
2024-10-18T08:53:17.632-04:00  INFO 22484 --- [    Test worker] o.example.repo.WikiDocumentsRepository   : Saving WikiDocument: WikiDocument(filePath=src/test/resources/documentation/rag-documentation.md, content=# Test 2)
2024-10-18T08:53:17.707-04:00  INFO 22484 --- [    Test worker] o.example.repo.WikiDocumentsRepository   : Metadata: {filePath=src/test/resources/documentation/rag-documentation.md}
2024-10-18T08:53:17.707-04:00  INFO 22484 --- [    Test worker] o.example.repo.WikiDocumentsRepository   : Documents before saving: [Document{id='def6b154-e867-480e-b28e-e0bbf2aaaf26', metadata={filePath=src/test/resources/documentation/rag-documentation.md}, content='# Test 2', media=[]}]
2024-10-18T08:53:18.017-04:00  INFO 22484 --- [    Test worker] o.example.repo.WikiDocumentsRepository   : Documents saved to vectorStore: [Document{id='def6b154-e867-480e-b28e-e0bbf2aaaf26', metadata={filePath=src/test/resources/documentation/rag-documentation.md}, content='# Test 2', media=[]}]
Однако, когда я пытаюсь все подтвердить с помощью

Код: Выделить всё

use wiki
db.vector_store.countDocuments({})
Я получаю 0.
Что здесь происходит? Кажется, все говорит о том, что документы должны быть там, но их нет. Я подтвердил, что информация о моем сервере одинакова в обоих случаях, для записи вот конфигурация

Код: Выделить всё

server:
port: 8055
spring:
data:
mongodb:
uri: mongodb://admin:...@10.0.0.58:30087/admin
database: wiki
ai:
vectorstore:
mongodb:
collection-name: vector_store
initialize-schema: true
path-name: embedding
indexName: vector_index
openai:
api-key: ${OPENAI_API_KEY}
chat:
options:
model: gpt-3.5-turbo
Изображение
Так почему после сохранения в векторное хранилище документы не отображаются?

Подробнее здесь: https://stackoverflow.com/questions/791 ... -documents
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «JAVA»