-
Notifications
You must be signed in to change notification settings - Fork 4
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
Showing
12 changed files
with
261 additions
and
153 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
[workspace] | ||
members = [ | ||
members = [ | ||
"rs/demo", | ||
"rs/aggregator", | ||
"rs/cli", | ||
"rs/compression", | ||
|
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,32 @@ | ||
import h5py | ||
import numpy as np | ||
|
||
def create_hdf5(input_path, output_path, batch_size=100000): | ||
# Create HDF5 file | ||
with h5py.File(output_path, 'w') as hf: | ||
# Initialize dataset with unknown size | ||
dataset = hf.create_dataset('embeddings', | ||
shape=(0, 768), | ||
maxshape=(None, 768), | ||
dtype='float32') | ||
|
||
# Process file in batches | ||
with open(input_path, 'r') as f: | ||
while True: | ||
# Read batch of lines | ||
lines = [f.readline() for _ in range(batch_size)] | ||
if not lines[0]: # End of file | ||
break | ||
|
||
# Parse lines to numpy array | ||
embeddings = np.array([np.fromstring(line.strip('[]\n'), sep=',') | ||
for line in lines if line.strip()]) | ||
|
||
# Resize dataset and append new data | ||
dataset.resize(dataset.shape[0] + embeddings.shape[0], axis=0) | ||
dataset[-embeddings.shape[0]:] = embeddings | ||
|
||
if __name__ == '__main__': | ||
input_file = '/mnt/muopdb/raw/1m_embeddings.txt' | ||
output_file = '/mnt/muopdb/1m_embeddings.hdf5' | ||
create_hdf5(input_file, output_file) |
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
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,30 @@ | ||
import muopdb_client as mp | ||
import ollama | ||
import time | ||
|
||
if __name__ == "__main__": | ||
# Example usage for IndexServer | ||
muopdb_client = mp.IndexServerClient() | ||
query = "personal career development" | ||
query_vector = ollama.embeddings(model='nomic-embed-text', prompt=query)["embedding"] | ||
|
||
# Read back the raw data to print the responses | ||
with open("/mnt/muopdb/raw/1m_sentences.txt", "r") as f: | ||
sentences = [line.strip() for line in f] | ||
|
||
start = time.time() | ||
search_response = muopdb_client.search( | ||
index_name="test-collection-1", | ||
vector=query_vector, | ||
top_k=5, | ||
ef_construction=50, | ||
record_metrics=False | ||
) | ||
end = time.time() | ||
print(f"Time taken for search: {end - start} seconds") | ||
|
||
print(f"Number of results: {len(search_response.ids)}") | ||
print("================") | ||
for id in search_response.ids: | ||
print(f"RESULT: {sentences[id - 1]}") | ||
print("================") |
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,19 @@ | ||
import ollama | ||
import time | ||
import sys | ||
|
||
if __name__ == "__main__": | ||
# Read the first args | ||
input_file = sys.argv[1] | ||
with open(input_file, "r") as f: | ||
sentences = f.readlines() | ||
|
||
start = time.time() | ||
output_file = f"{input_file}_embeddings.txt" | ||
with open(output_file, "w") as f: | ||
for sentence in sentences: | ||
result = ollama.embeddings(model='nomic-embed-text', prompt=sentence) | ||
f.write(f"{result['embedding']}\n") | ||
|
||
end = time.time() | ||
print(f"Time taken: {end - start} seconds") |
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,9 @@ | ||
import datasets | ||
|
||
if __name__ == "__main__": | ||
ds = datasets.load_dataset("agentlans/high-quality-english-sentences") | ||
train = ds["train"] | ||
with open("/tmp/1m_sentences.txt", "w") as f: | ||
for ln in train: | ||
f.write(ln["text"] + "\n") | ||
f.flush() |
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
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,15 @@ | ||
import h5py | ||
|
||
def read_first_and_last_five_points(): | ||
with h5py.File("/mnt/muopdb/raw/1m_embeddings.hdf5", "r") as f: | ||
# Assuming the dataset is named 'embeddings' | ||
dataset = f['embeddings'] | ||
first_five = dataset[:5] | ||
last_five = dataset[-5:] | ||
print("First 5 points:") | ||
print(first_five) | ||
print("\nLast 5 points:") | ||
print(last_five) | ||
|
||
if __name__ == "__main__": | ||
read_first_and_last_five_points() |
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,14 @@ | ||
[package] | ||
name = "demo" | ||
version = "0.1.0" | ||
edition = "2024" | ||
|
||
[dependencies] | ||
tonic.workspace = true | ||
hdf5.workspace = true | ||
log.workspace = true | ||
env_logger.workspace = true | ||
anyhow.workspace = true | ||
proto.workspace = true | ||
tokio.workspace = true | ||
ndarray.workspace = true |
Oops, something went wrong.