Skip to content

Commit 8819b65

Browse files
milvus build utilities, manifests, and seed generation script WIP
Signed-off-by: greg pereira <[email protected]>
1 parent e85a64d commit 8819b65

17 files changed

+352
-0
lines changed

Diff for: .gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ models
1212
generated
1313
.idea
1414
.DS_Store
15+
milvus/seed/data/*
16+
*.venv
17+
*venv
1518

1619
# UI assets
1720
**/node_modules

Diff for: milvus/build/Containerfile

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
FROM docker.io/milvusdb/milvus:master-20240426-bed6363f
2+
ADD embedEtcd.yaml /milvus/configs/embedEtcd.yaml

Diff for: milvus/build/Makefile

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
REGISTRY ?= quay.io
2+
REGISTRY_ORG ?= ai-lab
3+
COMPONENT = vector_dbs
4+
5+
IMAGE ?= $(REGISTRY)/$(REGISTRY_ORG)/$(COMPONENT)/milvus:latest
6+
7+
ARCH ?= $(shell uname -m)
8+
PLATFORM ?= linux/$(ARCH)
9+
10+
gRCP_PORT := 19530
11+
REST_PORT := 9091
12+
CLIENT_PORT := 2379
13+
14+
LIB_MILVUS_DIR_MOUNTPATH := $(shell pwd)/volumes/milvus
15+
16+
.PHONY: build
17+
build:
18+
podman build --platform $(PLATFORM) -f Containerfile -t ${IMAGE} .
19+
20+
.PHONY: run
21+
run:
22+
podman run -d \
23+
--name milvus-standalone \
24+
--security-opt seccomp:unconfined \
25+
-e ETCD_USE_EMBED=true \
26+
-e ETCD_CONFIG_PATH=/milvus/configs/embedEtcd.yaml \
27+
-e COMMON_STORAGETYPE=local \
28+
-v $(LIB_MILVUS_DIR_MOUNTPATH):/var/lib/milvus \
29+
-p $(gRCP_PORT):$(gRCP_PORT) \
30+
-p $(REST_PORT):$(REST_PORT) \
31+
-p $(CLIENT_PORT):$(CLIENT_PORT) \
32+
--health-cmd="curl -f http://localhost:$(REST_PORT)/healthz" \
33+
--health-interval=30s \
34+
--health-start-period=90s \
35+
--health-timeout=20s \
36+
--health-retries=3 \
37+
$(IMAGE) \
38+
milvus run standalone 1> /dev/null
39+
40+
.PHONY: stop
41+
stop:
42+
-podman stop milvus-standalone
43+
44+
.PHONY: delete
45+
delete:
46+
-podman rm milvus-standalone -f
47+
48+
.PHONY: podman-clean
49+
podman-clean:
50+
@container_ids=$$(podman ps -a --format "{{.ID}} {{.Image}}" | awk '$$2 == "$(IMAGE)" {print $$1}'); \
51+
echo "removing all containers with IMAGE=$(IMAGE)"; \
52+
for id in $$container_ids; do \
53+
echo "Removing container: $$id,"; \
54+
podman rm -f $$id; \
55+
done

Diff for: milvus/build/embedEtcd.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
listen-client-urls: http://0.0.0.0:2379
2+
advertise-client-urls: http://0.0.0.0:2379
3+
quota-backend-bytes: 4294967296
4+
auto-compaction-mode: revision
5+
auto-compaction-retention: '1000'

Diff for: milvus/build/merlinite-qq.sh

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
## EXPECTED INPUT IS STRING ECAPSULATED
3+
input="$1"
4+
echo "input: $input"
5+
request_body='{"model":"ibm/merlinite-7b","logprobs":false,"messages":[{"role": "system","content": "You are an AI language model developed by IBM Research. You are a cautious assistant. You carefully follow instructions. You are helpful and harmless and you follow ethical guidelines and promote positive behavior."},{"role":"user","content": "'$input'"}],"stream":false}'
6+
echo $request_body
7+
curl -X 'POST' 'https://merlinite-7b-vllm-openai.apps.fmaas-backend.fmaas.res.ibm.com/v1/chat/completions' -H 'accept: application/json' -H 'Content-Type: application/json' -k -d $request_body

Diff for: milvus/build/volumes/Containerfile

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
FROM docker.io/milvusdb/milvus:master-20240426-bed6363f
2+
ADD embedEtcd.yaml /milvus/configs/embedEtcd.yaml

Diff for: milvus/build/volumes/Makefile

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
REGISTRY ?= quay.io
2+
REGISTRY_ORG ?= ai-lab
3+
COMPONENT = vector_dbs
4+
5+
IMAGE ?= $(REGISTRY)/$(REGISTRY_ORG)/$(COMPONENT)/milvus:latest
6+
7+
ARCH ?= $(shell uname -m)
8+
PLATFORM ?= linux/$(ARCH)
9+
10+
gRCP_PORT := 19530
11+
REST_PORT := 9091
12+
CLIENT_PORT := 2379
13+
14+
LIB_MILVUS_DIR_MOUNTPATH := $(shell pwd)/volumes/milvus
15+
16+
.PHONY: build
17+
build:
18+
podman build --platform $(PLATFORM) -f Containerfile -t ${IMAGE} .
19+
20+
.PHONY: run
21+
run:
22+
podman run -it \
23+
--name milvus-standalone \
24+
--security-opt seccomp:unconfined \
25+
-e ETCD_USE_EMBED=true \
26+
-e ETCD_CONFIG_PATH=/milvus/configs/embedEtcd.yaml \
27+
-e COMMON_STORAGETYPE=local \
28+
-v $(LIB_MILVUS_DIR_MOUNTPATH):/var/lib/milvus \
29+
-p $(gRCP_PORT):$(gRCP_PORT) \
30+
-p $(REST_PORT):$(REST_PORT) \
31+
-p $(CLIENT_PORT):$(CLIENT_PORT) \
32+
--health-cmd="curl -f http://localhost:$(REST_PORT)/healthz" \
33+
--health-interval=30s \
34+
--health-start-period=90s \
35+
--health-timeout=20s \
36+
--health-retries=3 \
37+
$(IMAGE) \
38+
milvus run standalone 1> /dev/null
39+
40+
.PHONY: stop
41+
stop:
42+
-podman stop milvus-standalone
43+
44+
.PHONY: delete
45+
delete:
46+
-podman rm milvus-standalone -f
47+
48+
.PHONY: podman-clean
49+
podman-clean:
50+
@container_ids=$$(podman ps --format "{{.ID}} {{.Image}}" | awk '$$2 == "$(IMAGE)" {print $$1}'); \
51+
echo "removing all containers with IMAGE=$(IMAGE)"; \
52+
for id in $$container_ids; do \
53+
echo "Removing container: $$id,"; \
54+
podman rm -f $$id; \
55+
done

Diff for: milvus/build/volumes/embedEtcd.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
listen-client-urls: http://0.0.0.0:2379
2+
advertise-client-urls: http://0.0.0.0:2379
3+
quota-backend-bytes: 4294967296
4+
auto-compaction-mode: revision
5+
auto-compaction-retention: '1000'

Diff for: milvus/build/volumes/milvus/.gitkeep

Whitespace-only changes.

Diff for: milvus/seed/.env.example

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
MODEL_NAME=
2+
MODEL_ENDPOINT=
3+
MODEL_TOKEN=

Diff for: milvus/seed/README.md

Whitespace-only changes.

Diff for: milvus/seed/client.py

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import httpx
2+
import os
3+
import ssl
4+
5+
# manage ENV
6+
model_endpoint=os.getenv('MODEL_ENDPOINT')
7+
if model_endpoint == "":
8+
model_endpoint = "http://localhost:8001"
9+
10+
model_name=os.getenv('MODEL_NAME')
11+
if model_name == "":
12+
model_name = "ibm/merlinite-7b"
13+
14+
model_token=os.getenv('MODEL_TOKEN')
15+
16+
# HTTPS client
17+
client_key_path = "/home/fedora/client-tls-key.pem2"
18+
client_crt_path = "/home/fedora/client-tls-crt.pem2"
19+
server_ca_crt = "/home/fedora/server-ca-crt.pem2"
20+
21+
ssl_context = ssl.create_default_context(cafile=server_ca_crt)
22+
ssl_context.load_cert_chain(certfile=client_crt_path, keyfile=client_key_path)
23+
24+
client = httpx.Client(verify=ssl_context)
25+
26+
27+
def get_openai_response(prompt, **kwargs):
28+
url = model_endpoint
29+
headers = {
30+
"Authorization": f"Bearer {model_token}",
31+
"Content-Type": "application/json"
32+
}
33+
data = {
34+
"model": model_name,
35+
"max_tokens": 4096,
36+
"messages": [
37+
{
38+
"role": "system",
39+
"content": "You are an AI language model developed by IBM Research. You are a cautious assistant that carefully follows instructions. You are helpful and harmless and you follow ethical guidelines and promote positive behavior."
40+
},
41+
{
42+
"role":"user",
43+
"content": prompt
44+
}
45+
],
46+
"logprobs":False,
47+
"stream":False
48+
}
49+
50+
response = client.post(url, json=data, headers=headers)
51+
response.raise_for_status()
52+
return response.json()
53+
54+
question = """ Question: I am training for an upcoming marathon but I am completely out of shape! Can you help me to implement a plan to prepare me for running a marathon in 12 weeks?
55+
56+
Answer: Let's think step by step. """
57+
58+
# get_openai_response(question)

Diff for: milvus/seed/new-seed.py

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import os
2+
from pymilvus import MilvusClient, DataType
3+
from langchain_experimental.text_splitter import SemanticChunker
4+
from langchain_community.document_loaders import PyPDFLoader, WebBaseLoader
5+
from langchain_community.embeddings import HuggingFaceBgeEmbeddings, HuggingFaceInstructEmbeddings
6+
from tika import parser # pip install tika
7+
8+
def log_step(step_num, step_name) -> None:
9+
print("-----------------------------------------------")
10+
print(f"{step_num}. {step_name}")
11+
print("-----------------------------------------------")
12+
13+
model_name = "ibm/merlinite-7b"
14+
model_kwargs = {"device": "cpu"}
15+
encode_kwargs = {"normalize_embeddings": True}
16+
17+
log_step(0, "Generate embeddings")
18+
embeddings = HuggingFaceBgeEmbeddings(
19+
model_name=model_name,
20+
model_kwargs=model_kwargs,
21+
encode_kwargs=encode_kwargs,
22+
query_instruction = "search_query:",
23+
embed_instruction = "search_document:"
24+
)
25+
26+
27+
# data_url = "https://orkerhulen.dk/onewebmedia/DnD%205e%20Players%20Handbook%20%28BnW%20OCR%29.pdf"
28+
# loader = WebBaseLoader(data_url)
29+
# data = loader.load()
30+
raw = parser.from_file("data/DnD-5e-Handbook.pdf")
31+
print(raw['content'])

Diff for: milvus/seed/requirements-lock.txt

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
aiohttp==3.9.5
2+
aiosignal==1.3.1
3+
annotated-types==0.7.0
4+
anyio==4.3.0
5+
attrs==23.2.0
6+
beautifulsoup4==4.12.3
7+
bs4==0.0.2
8+
certifi==2024.2.2
9+
charset-normalizer==3.3.2
10+
dataclasses-json==0.6.6
11+
distro==1.9.0
12+
environs==9.5.0
13+
filelock==3.14.0
14+
frozenlist==1.4.1
15+
fsspec==2024.5.0
16+
grpcio==1.63.0
17+
h11==0.14.0
18+
httpcore==1.0.5
19+
httpx==0.27.0
20+
huggingface-hub==0.23.1
21+
idna==3.7
22+
Jinja2==3.1.4
23+
joblib==1.4.2
24+
jsonpatch==1.33
25+
jsonpointer==2.4
26+
langchain==0.2.1
27+
langchain-community==0.2.1
28+
langchain-core==0.2.1
29+
langchain-experimental==0.0.59
30+
langchain-openai==0.1.7
31+
langchain-text-splitters==0.2.0
32+
langsmith==0.1.63
33+
MarkupSafe==2.1.5
34+
marshmallow==3.21.2
35+
milvus-lite==2.4.5
36+
mpmath==1.3.0
37+
multidict==6.0.5
38+
mypy-extensions==1.0.0
39+
networkx==3.3
40+
numpy==1.26.4
41+
openai==1.30.3
42+
orjson==3.10.3
43+
packaging==23.2
44+
pandas==2.2.2
45+
pillow==10.3.0
46+
protobuf==5.27.0
47+
pydantic==2.7.1
48+
pydantic_core==2.18.2
49+
pymilvus==2.4.3
50+
python-dateutil==2.9.0.post0
51+
python-dotenv==1.0.1
52+
pytz==2024.1
53+
PyYAML==6.0.1
54+
regex==2024.5.15
55+
requests==2.32.2
56+
safetensors==0.4.3
57+
scikit-learn==1.5.0
58+
scipy==1.13.1
59+
sentence-transformers==2.7.0
60+
six==1.16.0
61+
sniffio==1.3.1
62+
soupsieve==2.5
63+
SQLAlchemy==2.0.30
64+
sympy==1.12
65+
tenacity==8.3.0
66+
threadpoolctl==3.5.0
67+
tika==2.6.0
68+
tiktoken==0.7.0
69+
tokenizers==0.19.1
70+
torch==2.3.0
71+
tqdm==4.66.4
72+
transformers==4.41.1
73+
typing-inspect==0.9.0
74+
typing_extensions==4.12.0
75+
tzdata==2024.1
76+
ujson==5.10.0
77+
urllib3==2.2.1
78+
yarl==1.9.4

Diff for: milvus/seed/requirements.txt

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
pymilvus==2.4.3
2+
langchain==0.2.1
3+
langchain-community==0.2.1
4+
langchain-core==0.2.1
5+
langchain-openai==0.1.7
6+
langchain-experimental==0.0.59
7+
tika==2.6.0
8+
sentence-transformers==2.7.0
9+
beautifulsoup4==4.12.3

Diff for: milvus/seed/seed.py

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import os
2+
from pymilvus import MilvusClient, DataType
3+
from langchain_experimental.text_splitter import SemanticChunker
4+
from langchain_community.document_loaders import PyPDFLoader, WebBaseLoader
5+
from langchain_community.embeddings import HuggingFaceBgeEmbeddings, HuggingFaceInstructEmbeddings
6+
from tika import parser # pip install tika
7+
8+
def log_step(step_num, step_name) -> None:
9+
print("-----------------------------------------------")
10+
print(f"{step_num}. {step_name}")
11+
print("-----------------------------------------------")
12+
13+
# model_name = "ibm/merlinite-7b"
14+
# model_kwargs = {"device": "cpu"}
15+
# encode_kwargs = {"normalize_embeddings": True}
16+
17+
model_name = "ibm/merlinite-7b"
18+
model_kwargs={"device": "cuda"},
19+
encode_kwargs = {"device": "cuda", "batch_size": 100, "normalize_embeddings": True}
20+
21+
log_step(0, "Generate embeddings")
22+
embeddings = HuggingFaceBgeEmbeddings(
23+
model_name=model_name,
24+
model_kwargs=model_kwargs,
25+
encode_kwargs=encode_kwargs,
26+
query_instruction = "search_query:",
27+
embed_instruction = "search_document:"
28+
)
29+
30+
log_step(1, "Init text splitter")
31+
text_splitter = SemanticChunker(embeddings=embeddings)
32+
log_step(2, "Read Raw data from PDF")
33+
raw = parser.from_file("data/DnD-5e-Handbook.pdf")
34+
log_step(3, "Text splitting")
35+
print(len(raw['content']))
36+
docs = text_splitter.create_documents([raw['content']])
37+
log_step(4, "Log result")
38+
print(len(docs))

Diff for: ui/compose.ui

+1
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ services:
9393
COMMON_STORAGETYPE: "local"
9494
volumes:
9595
- /home/fedora/milvus-volume:/var/lib/milvus
96+
- /home/fedora/instruct-lab-bot/milvus/seed:data/milvus/seed
9697
ports:
9798
- 19530:19530
9899
- 9091:9091

0 commit comments

Comments
 (0)