-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit aefb66f
Showing
8 changed files
with
3,143 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# 使用官方 golang 镜像作为基础镜像 | ||
FROM golang:1.17 AS builder | ||
|
||
# 设置工作目录 | ||
WORKDIR /app | ||
|
||
# 将 go.mod 和 go.sum 文件复制到容器中 | ||
COPY go.mod go.sum ./ | ||
|
||
# 下载依赖 | ||
RUN go mod download | ||
|
||
# 将源代码复制到容器中 | ||
COPY . . | ||
|
||
# 编译项目 | ||
RUN CGO_ENABLED=0 GOOS=linux go build -o VecTextSearch main.go | ||
|
||
# 使用官方 alpine 镜像作为基础镜像以减小镜像大小 | ||
FROM alpine:latest | ||
|
||
# 添加 ca 证书,以支持 HTTPS 请求 | ||
RUN apk --no-cache add ca-certificates | ||
|
||
# 从 builder 阶段复制编译好的二进制文件 | ||
COPY --from=builder /app/VecTextSearch /app/VecTextSearch | ||
|
||
# 设置工作目录 | ||
WORKDIR /app | ||
|
||
# 设置环境变量 | ||
ENV OPENAI_API_KEY=your_openai_api_key_here | ||
ENV API_PORT=8000 | ||
ENV WEAVIATE_HOST=localhost | ||
ENV WEAVIATE_PORT=8888 | ||
|
||
# 暴露端口 | ||
EXPOSE 8000 | ||
|
||
# 运行程序 | ||
CMD ["/app/VecTextSearch"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
# VecTextSearch | ||
## 项目介绍 | ||
VecTextSearch 是一个使用 OpenAI 语言模型生成文本向量并在 Weaviate 数据库中进行高效搜索的项目。它允许用户将文本数据存储在 Weaviate 数据库中,并根据文本相似性快速搜索和检索相关文本。项目使用 Golang 编写,并提供一个简单的 REST API 供客户端调用。 | ||
|
||
## 聊天记录 | ||
[聊天记录1](history/chat1.md) | ||
|
||
## 项目背景 | ||
在许多实际应用中,需要基于文本相似性进行快速搜索。例如,给定一篇文章,可以找到与其内容相似的其他文章。传统的基于关键词的搜索方法可能无法准确捕捉到文本之间的相似性。VecTextSearch 利用 OpenAI 的强大语言模型将文本转换为向量表示,然后使用 Weaviate 数据库进行高效的相似向量搜索。 | ||
|
||
## 用处与使用场景 | ||
VecTextSearch 可以应用于以下场景: | ||
|
||
- 为文章、博客、论文等寻找相关内容。 | ||
- 实现智能问答系统,根据用户提问快速匹配到相关问题及答案。 | ||
- 构建推荐系统,根据用户的阅读历史为其推荐相似文章。 | ||
- 检测重复或抄袭的内容。 | ||
|
||
## 接口介绍 | ||
VecTextSearch 提供了两个 REST API 接口: | ||
|
||
### 添加文本 | ||
- URL: /add-text | ||
- Method: POST | ||
- Content-Type: application/json | ||
- Request Payload: | ||
|
||
```json | ||
{ | ||
"name": "文章名称", | ||
"content": "文章内容" | ||
} | ||
``` | ||
- Response: 成功添加文本后,将返回一个包含文本 ID 的 JSON 对象。 | ||
|
||
```json | ||
{ | ||
"id": "文章唯一标识符" | ||
} | ||
``` | ||
|
||
### 搜索相似文本 | ||
- URL: /search-similar-texts | ||
- Method: POST | ||
- Content-Type: application/json | ||
- Request Payload: | ||
|
||
json | ||
Copy code | ||
{ | ||
"content": "查询内容" | ||
} | ||
Response: 搜索成功后,将返回一个包含相似文本信息的 JSON 对象。 | ||
|
||
```json | ||
{ | ||
"data": [ | ||
{ | ||
"id": "文章唯一标识符", | ||
"name": "文章名称", | ||
"content": "文章内容", | ||
"distance": "与查询内容的距离" | ||
}, | ||
... | ||
] | ||
} | ||
``` | ||
|
||
## 部署与运行 | ||
请参考项目的 Dockerfile 和 docker-compose.yml 文件,使用 Docker 和 Docker Compose 部署和运行 VecTextSearch 及其依赖的 Weaviate 服务。具体部署和运行方法,请参考本仓库中的 Docker 部署指南。 | ||
|
||
注意:在运行项目之前,请确保您已经配置了 config.yml 文件,设置了正确的 OpenAI API 密钥和 API 端口。 | ||
|
||
## 开发与贡献 | ||
如果您想为 VecTextSearch 做出贡献或者对项目进行二次开发,您可以按照以下步骤操作: | ||
|
||
1. 克隆本仓库到本地: | ||
|
||
```bash | ||
git clone https://github.com/szpnygo/VecTextSearch.git | ||
``` | ||
|
||
2. 进入项目目录并安装相关依赖: | ||
|
||
```bash | ||
cd VecTextSearch | ||
go get -u | ||
``` | ||
|
||
3. 在 config.yml 文件中填写正确的 OpenAI API 密钥。 | ||
|
||
4. 运行项目: | ||
|
||
```bash | ||
go run main.go | ||
``` | ||
|
||
如果您在使用 VecTextSearch 时遇到问题或者有新的想法和建议,欢迎提交 Issue 或 Pull Request。我们非常感谢您的贡献和支持! | ||
|
||
## 许可证 | ||
VecTextSearch 采用 MIT 许可证。有关详细信息,请参阅 LICENSE 文件。 | ||
|
||
## 联系我们 | ||
如果您在使用 VecTextSearch 过程中遇到任何问题,请随时与我们联系。您可以通过以下方式联系我们: | ||
|
||
- 在 GitHub 仓库中提交 Issue | ||
- 发送电子邮件至:[email protected] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package main | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/szpnygo/VecTextSearch/config" | ||
"github.com/szpnygo/VecTextSearch/server" | ||
) | ||
|
||
func main() { | ||
appConfig, err := config.LoadConfig() | ||
if err != nil { | ||
log.Fatalf("Failed to load configuration: %v", err) | ||
} | ||
|
||
server.StartServer(appConfig) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package config | ||
|
||
import ( | ||
"errors" | ||
"os" | ||
"strconv" | ||
) | ||
|
||
// AppConfig contains the application's configuration. | ||
type AppConfig struct { | ||
APIPort int | ||
WeaviateURL string | ||
OpenAIKey string | ||
} | ||
|
||
// LoadConfig loads the configuration from environment variables. | ||
func LoadConfig() (*AppConfig, error) { | ||
apiPort, err := strconv.Atoi(os.Getenv("VECTEXTSEARCH_API_PORT")) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
weaviateURL := os.Getenv("VECTEXTSEARCH_WEAVIATE_URL") | ||
if weaviateURL == "" { | ||
return nil, errors.New("VECTEXTSEARCH_WEAVIATE_URL not set") | ||
} | ||
|
||
openAIKey := os.Getenv("VECTEXTSEARCH_OPENAI_KEY") | ||
if openAIKey == "" { | ||
return nil, errors.New("VECTEXTSEARCH_OPENAI_KEY not set") | ||
} | ||
|
||
return &AppConfig{ | ||
APIPort: apiPort, | ||
WeaviateURL: weaviateURL, | ||
OpenAIKey: openAIKey, | ||
}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
module github.com/szpnygo/VecTextSearch | ||
|
||
go 1.19 | ||
|
||
require ( | ||
github.com/gin-gonic/gin v1.9.0 | ||
github.com/google/uuid v1.3.0 | ||
github.com/weaviate/weaviate-go-client/v4 v4.6.4 | ||
) | ||
|
||
require ( | ||
github.com/PuerkitoBio/purell v1.1.1 // indirect | ||
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect | ||
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d // indirect | ||
github.com/bytedance/sonic v1.8.6 // indirect | ||
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect | ||
github.com/gin-contrib/sse v0.1.0 // indirect | ||
github.com/go-openapi/analysis v0.21.2 // indirect | ||
github.com/go-openapi/errors v0.20.3 // indirect | ||
github.com/go-openapi/jsonpointer v0.19.5 // indirect | ||
github.com/go-openapi/jsonreference v0.19.6 // indirect | ||
github.com/go-openapi/loads v0.21.1 // indirect | ||
github.com/go-openapi/spec v0.20.4 // indirect | ||
github.com/go-openapi/strfmt v0.21.3 // indirect | ||
github.com/go-openapi/swag v0.22.3 // indirect | ||
github.com/go-openapi/validate v0.21.0 // indirect | ||
github.com/go-playground/locales v0.14.1 // indirect | ||
github.com/go-playground/universal-translator v0.18.1 // indirect | ||
github.com/go-playground/validator/v10 v10.12.0 // indirect | ||
github.com/goccy/go-json v0.10.2 // indirect | ||
github.com/golang/protobuf v1.5.2 // indirect | ||
github.com/josharian/intern v1.0.0 // indirect | ||
github.com/json-iterator/go v1.1.12 // indirect | ||
github.com/klauspost/cpuid/v2 v2.2.4 // indirect | ||
github.com/leodido/go-urn v1.2.2 // indirect | ||
github.com/mailru/easyjson v0.7.7 // indirect | ||
github.com/mattn/go-isatty v0.0.18 // indirect | ||
github.com/mitchellh/mapstructure v1.5.0 // indirect | ||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect | ||
github.com/modern-go/reflect2 v1.0.2 // indirect | ||
github.com/oklog/ulid v1.3.1 // indirect | ||
github.com/pelletier/go-toml/v2 v2.0.7 // indirect | ||
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect | ||
github.com/ugorji/go/codec v1.2.11 // indirect | ||
github.com/weaviate/weaviate v1.18.2 // indirect | ||
go.mongodb.org/mongo-driver v1.11.3 // indirect | ||
golang.org/x/arch v0.3.0 // indirect | ||
golang.org/x/crypto v0.7.0 // indirect | ||
golang.org/x/net v0.8.0 // indirect | ||
golang.org/x/oauth2 v0.0.0-20220822191816-0ebed06d0094 // indirect | ||
golang.org/x/sys v0.6.0 // indirect | ||
golang.org/x/text v0.8.0 // indirect | ||
google.golang.org/appengine v1.6.7 // indirect | ||
google.golang.org/protobuf v1.30.0 // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
) |
Oops, something went wrong.