> ## Documentation Index
> Fetch the complete documentation index at: https://javaai.pig4cloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Oracle 向量数据库

Spring AI 中的 Oracle 向量数据库集成了 Oracle 的向量功能，提供向量存储和搜索能力。

## 概述

Oracle 向量数据库支持：

* 关系型向量存储
* 基于 SQL 的向量操作
* 企业级安全
* 高性能扩展

## 特性

<CardGroup cols={2}>
  <Card title="关系型" icon="database">
    关系型向量存储
  </Card>

  <Card title="企业级" icon="building">
    企业级特性
  </Card>

  <Card title="安全" icon="shield-alt">
    高级安全
  </Card>

  <Card title="可扩展" icon="arrows-up-down-left-right">
    高性能扩展
  </Card>
</CardGroup>

## 实现

### 基本设置

```xml theme={"system"}
<dependency>
    <groupId>org.springframework.ai</groupId>
    <artifactId>spring-ai-oracle-vectordb</artifactId>
    <version>${spring-ai.version}</version>
</dependency>
```

### 配置

```properties theme={"system"}
# Oracle 向量数据库配置
spring.ai.oracle.vectordb.enabled=true
spring.ai.oracle.vectordb.url=jdbc:oracle:thin:@localhost:1521:XE
spring.ai.oracle.vectordb.username=system
spring.ai.oracle.vectordb.password=oracle
spring.ai.oracle.vectordb.table-name=vectors
```

### 用法

```java theme={"system"}
@Service
public class OracleVectorService {
    private final OracleVectorClient vectorClient;

    public OracleVectorService(OracleVectorClient vectorClient) {
        this.vectorClient = vectorClient;
    }

    public void storeVector(String id, float[] vector, Map<String, Object> metadata) {
        vectorClient.store(id, vector, metadata);
    }

    public List<SearchResult> searchSimilar(float[] queryVector, int k) {
        return vectorClient.search(queryVector, k);
    }
}
```

## 向量操作

### 1. 向量存储

```java theme={"system"}
@Configuration
public class OracleVectorStorageConfig {
    @Bean
    public VectorStorage oracleVectorStorage(OracleVectorProperties properties) {
        return new OracleVectorStorage(properties);
    }
}
```

### 2. 相似性搜索

```java theme={"system"}
@Configuration
public class OracleSimilaritySearchConfig {
    @Bean
    public SimilaritySearch oracleSimilaritySearch(OracleVectorProperties properties) {
        return new OracleSimilaritySearch(properties);
    }
}
```

### 3. 表管理

```java theme={"system"}
@Service
public class TableService {
    private final OracleVectorClient vectorClient;

    public void createTable(String name, int dimension) {
        vectorClient.createTable(name, dimension);
    }

    public void dropTable(String name) {
        vectorClient.dropTable(name);
    }
}
```

## 高级特性

### 自定义表配置

```java theme={"system"}
@Configuration
public class TableConfig {
    @Bean
    public TableConfig tableConfig() {
        return TableConfig.builder()
            .name("custom_vectors")
            .vectorColumn("vector")
            .metadataColumns(Arrays.asList("title", "content"))
            .build();
    }
}
```

### 索引管理

```java theme={"system"}
@Configuration
public class IndexConfig {
    @Bean
    public IndexConfig indexConfig() {
        return IndexConfig.builder()
            .name("vector_idx")
            .type(IndexType.VECTOR)
            .dimension(1536)
            .build();
    }
}
```

### 安全配置

```java theme={"system"}
@Configuration
public class SecurityConfig {
    @Bean
    public SecurityConfig securityConfig() {
        return SecurityConfig.builder()
            .encryptionEnabled(true)
            .auditEnabled(true)
            .build();
    }
}
```

### 监控

```properties theme={"system"}
management.endpoints.web.exposure.include=oracle-vectordb
management.endpoint.oracle-vectordb.enabled=true
```

## 最佳实践

<Note>
  使用 Oracle 向量数据库时，请考虑以下最佳实践：
</Note>

* **表设计**：设计高效的表结构
* **索引管理**：优化索引配置
* **安全**：实施适当的安全措施
* **资源管理**：配置资源分配
* **监控**：设置全面的监控

## 故障排除

常见问题及解决方案：

1. **连接问题**
   * 验证连接 URL
   * 检查凭据
   * 查看网络设置

2. **性能问题**
   * 优化表结构
   * 配置索引
   * 查看查询模式

3. **存储问题**
   * 监控表大小
   * 执行清理
   * 查看保留策略

<Card title="文档有误？请协助编辑" icon="pencil" href="https://github.com/javaai-pig4cloud-com/javaai-docs/edit/main/spring-ai/api/vectordbs/oracle.mdx">
  发现文档问题？点击此处直接在 GitHub 上编辑并提交 PR，帮助我们改进文档！
</Card>
