사용자 고유의 데이터 모델을 정의하지 않고 벡터 저장소 추상화 사용(미리 보기)
Warning
의미 체계 커널 벡터 저장소 기능은 미리 보기 상태이며 릴리스 전에 제한된 상황에서도 호환성이 손상되는 변경이 필요한 개선 사항이 계속 발생할 수 있습니다.
개요
의미 체계 커널 벡터 저장소 커넥터는 모델 첫 번째 접근 방식을 사용하여 데이터베이스와 상호 작용합니다. 이렇게 하면 데이터 모델이 데이터베이스 레코드의 스키마를 반영하고 필요한 추가 스키마 정보를 추가하기 때문에 커넥터를 쉽고 간단하게 사용할 수 있으므로 데이터 모델 속성에 특성을 추가할 수 있습니다.
사용자 고유의 데이터 모델을 정의하는 것이 바람직하지 않거나 가능한 경우가 있습니다. 예를 들어 컴파일 시간에 데이터베이스 스키마의 모양을 알지 못하며 스키마는 구성을 통해서만 제공됩니다. 이 경우 스키마를 반영하는 데이터 모델을 만드는 것은 불가능합니다.
이 시나리오를 수용하기 위해 일반 데이터 모델을 제공합니다.
제네릭 데이터 모델
제네릭 데이터 모델은 명명된 VectorStoreGenericDataModel
클래스이며 패키지에서 Microsoft.Extensions.VectorData.Abstractions
사용할 수 있습니다.
모든 유형의 데이터베이스를 지원하기 위해 키의 VectorStoreGenericDataModel
형식은 제네릭 매개 변수를 통해 지정됩니다.
다른 모든 속성은 속성으로 Data
Vector
나뉩니다. 벡터 또는 키가 아닌 모든 속성은 데이터 속성으로 간주됩니다.
Data
및 Vector
속성 집합은 개체의 문자열 키 사전으로 저장됩니다.
제네릭 데이터 모델을 사용할 때 스키마 정보 제공
제네릭 데이터 모델을 사용하는 경우 커넥터는 데이터베이스 스키마의 모양을 알고 있어야 합니다. 스키마 정보가 없으면 커넥터가 컬렉션을 만들 수 없거나 각 데이터베이스에서 사용하는 스토리지 표현과 매핑하는 방법을 알 수 없습니다.
레코드 정의를 사용하여 스키마 정보를 제공할 수 있습니다. 데이터 모델과 달리, 런타임에 구성에서 레코드 정의를 만들 수 있으며 컴파일 시간에 스키마 정보를 알 수 없는 경우에 대한 솔루션을 제공합니다.
팁
레코드 정의를 만드는 방법을 보려면 레코드 정의로 스키마 정의를 참조하세요.
예시
커넥터에서 제네릭 데이터 모델을 사용하려면 컬렉션을 만들 때 데이터 모델로 지정하고 동시에 레코드 정의를 제공합니다.
// Create the definition to define the schema.
VectorStoreRecordDefinition vectorStoreRecordDefinition = new()
{
Properties = new List<VectorStoreRecordProperty>
{
new VectorStoreRecordKeyProperty("Key", typeof(string)),
new VectorStoreRecordDataProperty("Term", typeof(string)),
new VectorStoreRecordDataProperty("Definition", typeof(string)),
new VectorStoreRecordVectorProperty("DefinitionEmbedding", typeof(ReadOnlyMemory<float>)) { Dimensions = 1536 }
}
};
// When getting your collection instance from a vector store instance
// specify the generic data model, using the appropriate key type for your database
// and also pass your record definition.
var genericDataModelCollection = vectorStore.GetCollection<string, VectorStoreGenericDataModel<string>>(
"glossary",
vectorStoreRecordDefinition);
// Since we have schema information available from the record definition
// it's possible to create a collection with the right vectors, dimensions,
// indexes and distance functions.
await genericDataModelCollection.CreateCollectionIfNotExistsAsync();
// When retrieving a record from the collection, data and vectors can
// now be accessed via the Data and Vector dictionaries respectively.
var record = await genericDataModelCollection.GetAsync("SK");
Console.WriteLine(record.Data["Definition"])
컬렉션 인스턴스를 직접 생성할 때 레코드 정의가 옵션으로 전달됩니다. 예를 들어 제네릭 데이터 모델을 사용하여 Azure AI Search 컬렉션 인스턴스를 생성하는 예제는 다음과 같습니다.
new AzureAISearchVectorStoreRecordCollection<VectorStoreGenericDataModel<string>>(
searchIndexClient,
"glossary",
new() { VectorStoreRecordDefinition = vectorStoreRecordDefinition });
서비스 예정
추가 정보는 곧 제공될 예정입니다.
서비스 예정
추가 정보는 곧 제공될 예정입니다.