Skip to content

Commit

Permalink
Refactor and edit readme
Browse files Browse the repository at this point in the history
  • Loading branch information
MaskerPRC committed Sep 10, 2024
1 parent 47e26e4 commit 439fc1e
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 25 deletions.
13 changes: 12 additions & 1 deletion README.CN.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# 注意事项


## 前置条件
- 需要安装本地psql数据库
```shell
Expand All @@ -12,6 +11,18 @@ ALTER USER postgres PASSWORD 'postgres';
# 建立数据库(db)
CREATE DATABASE db;
```
- 需要安装qdrant本地服务
```shell
# docker环境准备
sudo apt update
sudo apt install docker.io
sudo systemctl start docker
sudo systemctl enable docker
# 安装
sudo docker run -p 6333:6333 -d --name qdrant qdrant/qdrant
# 测试
curl http://localhost:6333
```

## 本地启动
```shell
Expand Down
5 changes: 3 additions & 2 deletions infra_ai_service/api/ai_enhance/embedding.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ async def embed_text(input_data: TextInput):
# 生成嵌入
embeddings = list(fastembed_model.embed([input_data.content]))
if not embeddings:
logger.error(f"Failed to generate embedding", exc_info=True)
raise ValueError("Failed to generate embedding")

embedding_vector = embeddings[0]
Expand All @@ -51,7 +52,7 @@ async def embed_text(input_data: TextInput):

return EmbeddingOutput(id=point_id, embedding=embedding_vector.tolist())
except Exception as e:
logger.error(f"Error in vector search: {str(e)}", exc_info=True)
logger.error(f"Error processing embedding: {str(e)}", exc_info=True)
raise HTTPException(status_code=400,
detail=f"Error processing embedding: {str(e)}")

Expand All @@ -66,6 +67,6 @@ async def get_collection_status():
"status": "ready" if collection_info.status == "green" else "not ready"
}
except Exception as e:
logger.error(f"Error in vector search: {str(e)}", exc_info=True)
logger.error(f"Error getting collection status: {str(e)}", exc_info=True)
raise HTTPException(status_code=400,
detail=f"Error getting collection status: {str(e)}")
2 changes: 1 addition & 1 deletion infra_ai_service/api/ai_enhance/text_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ async def process_text(input_data: TextInput):
modified_text = clean_text(input_data.content)
return TextOutput(modified_content=modified_text)
except Exception as e:
logger.error(f"Error in vector search: {str(e)}", exc_info=True)
logger.error(f"Error processing text: {str(e)}", exc_info=True)
raise HTTPException(status_code=400, detail=f"Error processing text: {str(e)}")
7 changes: 3 additions & 4 deletions infra_ai_service/api/ai_enhance/vector_search.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
from fastapi import APIRouter, HTTPException
from pydantic import BaseModel
from typing import List
from fastembed.embedding import DefaultEmbedding
from qdrant_client import QdrantClient
from qdrant_client.http.models import Distance, VectorParams
from infra_ai_service.api.common.utils import setup_qdrant_environment
import logging

Expand Down Expand Up @@ -35,11 +32,13 @@ async def vector_search(input_data: SearchInput):
try:
# 检查集合是否存在
if not qdrant_client.get_collection(collection_name):
logger.error(f"Collection {collection_name} does not exist", exc_info=True)
raise ValueError(f"Collection {collection_name} does not exist")

# 生成查询文本的嵌入
query_vector = list(fastembed_model.embed([input_data.query_text]))
if not query_vector:
logger.error(f"Failed to generate query embedding", exc_info=True)
raise ValueError("Failed to generate query embedding")

# 执行向量搜索
Expand All @@ -62,5 +61,5 @@ async def vector_search(input_data: SearchInput):

return SearchOutput(results=results)
except Exception as e:
logger.error(f"Error in vector search: {str(e)}", exc_info=True)
logger.error(f"Error performing vector search: {str(e)}", exc_info=True)
raise HTTPException(status_code=500, detail=f"Error performing vector search: {str(e)}")
4 changes: 2 additions & 2 deletions infra_ai_service/api/common/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from fastapi import APIRouter, HTTPException
from fastapi import HTTPException
from fastembed.embedding import DefaultEmbedding
from qdrant_client import QdrantClient
from qdrant_client.http.models import Distance, VectorParams, PointStruct
from qdrant_client.http.models import Distance, VectorParams


def setup_qdrant_environment():
Expand Down
15 changes: 0 additions & 15 deletions tests/test_health.py

This file was deleted.

0 comments on commit 439fc1e

Please sign in to comment.