Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(knowledgebase): add support for vector type #949

Merged
merged 6 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .projen/deps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .projenrc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
const GITHUB_USER = 'awslabs';
const PUBLICATION_NAMESPACE = 'cdklabs';
const PROJECT_NAME = 'generative-ai-cdk-constructs';
const CDK_VERSION: string = '2.177.0';
const CDK_VERSION: string = '2.178.0';

function camelCaseIt(input: string): string {
// Hypens and dashes to spaces and then CamelCase...
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# CDK Generative AI Constructs V0.1.293 (2025-02-10)

Based on CDK library version 2.178.0

# CDK Generative AI Constructs V0.1.291 (2025-01-26)

Based on CDK library version 2.177.0
Expand Down
2 changes: 1 addition & 1 deletion DEVELOPER_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Default output format [None]: json
```

- [Node](https://nodejs.org/en) >= v20.9.0
- [AWS CDK](https://github.com/aws/aws-cdk/releases/tag/v2.177.0) >= 2.177.0
- [AWS CDK](https://github.com/aws/aws-cdk/releases/tag/v2.178.0) >= 2.178.0
- [Python](https://www.python.org/downloads/) >=3.9
- [Projen](https://github.com/projen/projen) >= 0.91.5
- [Yarn](https://classic.yarnpkg.com/lang/en/docs/cli/install/) >= 1.22.19
Expand Down
1 change: 1 addition & 0 deletions apidocs/namespaces/bedrock/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
- [SharePointDataSourceAuthType](enumerations/SharePointDataSourceAuthType.md)
- [SharePointObjectType](enumerations/SharePointObjectType.md)
- [TransformationStep](enumerations/TransformationStep.md)
- [VectorType](enumerations/VectorType.md)

## Classes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ The ARN of the Bedrock invokable abstraction.

***

### supportedVectorType?

> `readonly` `optional` **supportedVectorType**: [`VectorType`](../enumerations/VectorType.md)[]

***

### supportsAgents

> `readonly` **supportsAgents**: `boolean`
Expand Down
28 changes: 28 additions & 0 deletions apidocs/namespaces/bedrock/enumerations/VectorType.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[**@cdklabs/generative-ai-cdk-constructs**](../../../README.md)

***

[@cdklabs/generative-ai-cdk-constructs](../../../README.md) / [bedrock](../README.md) / VectorType

# Enumeration: VectorType

The data type for the vectors when using a model to convert text into vector embeddings.
The model must support the specified data type for vector embeddings. Floating-point (float32)
is the default data type, and is supported by most models for vector embeddings. See Supported
embeddings models for information on the available models and their vector data types.

## Enumeration Members

### BINARY

> **BINARY**: `"BINARY"`

`BINARY` convert the data to binary vector embeddings (less precise, but less costly).

***

### FLOATING\_POINT

> **FLOATING\_POINT**: `"FLOAT32"`

`FLOATING_POINT` convert the data to floating-point (float32) vector embeddings (more precise, but more costly).
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@

## Properties

### supportedVectorType?

> `readonly` `optional` **supportedVectorType**: [`VectorType`](../enumerations/VectorType.md)[]

Embeddings models have different supported vector types

***

### supportsAgents?

> `readonly` `optional` **supportsAgents**: `boolean`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,17 @@ type `VectorCollection`, `RedisEnterpriseVectorStore`,
```ts
- A new OpenSearch Serverless vector collection is created.
```

***

### vectorType?

> `readonly` `optional` **vectorType**: [`VectorType`](../enumerations/VectorType.md)

The vector type to store vector embeddings.

#### Default

```ts
- VectorType.FLOATING_POINT
```
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ The OpenSearch Vector Collection.

***

### distanceType

> `readonly` **distanceType**: `string`

***

### indexName

> `readonly` **indexName**: `string`
Expand All @@ -48,6 +54,12 @@ The metadata management fields.

***

### precision

> `readonly` **precision**: `string`

***

### vectorDimensions

> `readonly` **vectorDimensions**: `number`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class AnalyzerProperties(TypedDict):

class VectorIndexProperties(TypedDict):
Endpoint: str
Precision: str
DistanceType: str
IndexName: str
VectorField: str
Dimensions: int | str
Expand All @@ -70,6 +72,10 @@ def validate_event(event: CustomResourceRequest[VectorIndexProperties]) -> bool:
raise ValueError("VectorField is required")
if event["ResourceProperties"]["Dimensions"] is None:
raise ValueError("Dimensions is required")
if event["ResourceProperties"]["Precision"] is None:
raise ValueError("Precision is required")
if event["ResourceProperties"]["DistanceType"] is None:
raise ValueError("DistanceType is required")
if isinstance(int(event["ResourceProperties"]["Dimensions"]), int) is False:
raise ValueError("Dimensions must be an integer")
if event["ResourceProperties"]["MetadataManagement"] is None:
Expand Down Expand Up @@ -125,16 +131,19 @@ def connect_opensearch(endpoint: str) -> OpenSearch:
def create_mapping(
vector_field: str,
dimensions: int,
precision: str,
distance_type: str,
metadata_management: Sequence[MetadataManagementField],
) -> dict:
mapping = {
"properties": {
vector_field: {
"type": "knn_vector",
"dimension": dimensions,
"data_type": precision,
"method": {
"engine": "faiss",
"space_type": "l2",
"space_type": distance_type,
"name": "hnsw",
"parameters": {},
},
Expand Down Expand Up @@ -206,14 +215,16 @@ def handle_create(
index_name: str,
vector_field: str,
dimensions: int,
precision: str,
distance_type: str,
metadata_management: Sequence[MetadataManagementField],
analyzer: AnalyzerProperties | None,
):
if client.indices.exists(index_name):
raise ValueError(f"Index {index_name} already exists")

try:
mapping = create_mapping(vector_field, dimensions, metadata_management)
mapping = create_mapping(vector_field, dimensions, precision, distance_type, metadata_management)
setting = create_setting(analyzer)
create_index(client, index_name, mapping, setting)
except Exception as e:
Expand Down Expand Up @@ -248,6 +259,8 @@ def on_create(
event["ResourceProperties"]["IndexName"],
event["ResourceProperties"]["VectorField"],
int(event["ResourceProperties"]["Dimensions"]),
event["ResourceProperties"]["Precision"],
event["ResourceProperties"]["DistanceType"],
event["ResourceProperties"]["MetadataManagement"],
event["ResourceProperties"].get("Analyzer", None),
)
Expand Down
Loading
Loading