Skip to content

Commit

Permalink
Add docstring.
Browse files Browse the repository at this point in the history
  • Loading branch information
milistu committed May 28, 2024
1 parent 71140b2 commit ab03ee6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
7 changes: 3 additions & 4 deletions database/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def create_collection(
vector_size: int = 1536,
distance: Distance = Distance.COSINE,
) -> bool:
"""Create a collection in Qdrant."""
logger.info(f'Creating collection: "{name}" with vector size: {vector_size}.')
return client.recreate_collection(
collection_name=name,
Expand Down Expand Up @@ -53,6 +54,7 @@ def upsert(
collection: str,
points: List[PointStruct],
) -> UpdateResult:
"""Upsert data points into a Qdrant collection."""
return client.upsert(collection_name=collection, points=points)


Expand Down Expand Up @@ -88,10 +90,7 @@ def embed_text(
client: OpenAI, text: Union[str, list], model: str
) -> CreateEmbeddingResponse:
"""
- Default model (OpenAI): text-embedding-3-small
- Max input Tokens: 8191
- TikToken model: cl100k_base
- Embedding size: 1536
Create embeddings using OpenAI API.
"""
response = client.embeddings.create(input=text, model=model)
return response
Expand Down
3 changes: 2 additions & 1 deletion database/vector_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@


def main(args: argparse.Namespace) -> None:
"""Main function to create embeddings and vector database."""
logger.info("Creating embeddings.")
create_embeddings(
scraped_dir=args.scraped_dir,
Expand All @@ -34,7 +35,7 @@ def main(args: argparse.Namespace) -> None:
for path in tqdm(data_paths, total=len(data_paths), desc="Creating collections"):
# Check if this is necessary
collection_name = path.stem.replace("-", "_")
collection_name = collection_name + "_TESTIC"
collection_name = collection_name
points = load_and_process_embeddings(path=path)

create_collection(client=qdrant_client, name=collection_name)
Expand Down

0 comments on commit ab03ee6

Please sign in to comment.