Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Weaviate fix #36

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ async def delete(payload: RequestPayload):
encoder=encoder,
)
data = await vector_service.delete(file_url=payload.file_url)
return {"success": True, "data": data}
return ResponsePayload(success=True, data=data)
6 changes: 3 additions & 3 deletions api/ingest.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ async def ingest(payload: RequestPayload) -> Dict:
)

await asyncio.gather(
embedding_service.generate_embeddings(
embedding_service.generate_and_upsert_embeddings(
documents=chunks, encoder=encoder, index_name=payload.index_name
),
embedding_service.generate_embeddings(
embedding_service.generate_and_upsert_embeddings(
documents=summary_documents,
encoder=encoder,
index_name=f"{payload.index_name}-summary",
index_name=f"{payload.index_name}summary", # TODO maybe with '-summary'?
),
)

Expand Down
91 changes: 89 additions & 2 deletions dev/walkthrough.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
" \"files\": [\n",
" {\n",
" \"type\": \"PDF\",\n",
" \"url\": \"https://arxiv.org/pdf/2210.03629.pdf\"\n",
" \"url\": \"https://arxiv.org/pdf/2402.05131.pdf\"\n",
" }\n",
" ],\n",
" \"vector_database\": {\n",
Expand All @@ -54,6 +54,39 @@
"print(response.json())"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Ingest a file\n",
"url = f\"{API_URL}/api/v1/ingest\"\n",
"\n",
"payload = {\n",
" \"files\": [\n",
" {\n",
" \"type\": \"PDF\",\n",
" \"url\": \"https://arxiv.org/pdf/2402.05131.pdf\"\n",
" }\n",
" ],\n",
" \"vector_database\": {\n",
" \"type\": \"weaviate\",\n",
" \"config\": {\n",
" \"api_key\": \"9eXH8oNR0uqN3GvvzAgaUD11ltPnGqZG2RFQ\",\n",
" \"host\": \"https://superagent-ragas-1575sjfq.weaviate.network\"\n",
" }\n",
" },\n",
" \"index_name\": \"homanp11\",\n",
" \"encoder\": \"cohere\",\n",
" \"webhook_url\": \"https://webhook.site/0e217d1c-49f1-424a-9992-497db09f7793\"\n",
"}\n",
"\n",
"response = requests.post(url, json=payload)\n",
"\n",
"print(response.json())"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -64,7 +97,7 @@
"query_url = f\"{API_URL}/api/v1/query\"\n",
"\n",
"query_payload = {\n",
" \"input\": \"What is CoT?\",\n",
" \"input\": \"What are the chunking strategies?\",\n",
" \"vector_database\": {\n",
" \"type\": \"pinecone\",\n",
" \"config\": {\n",
Expand All @@ -81,6 +114,33 @@
"print(query_response.json())"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Query the index\n",
"query_url = f\"{API_URL}/api/v1/query\"\n",
"\n",
"query_payload = {\n",
" \"input\": \"What are the chunking strategies?\",\n",
" \"vector_database\": {\n",
" \"type\": \"weaviate\",\n",
" \"config\": {\n",
" \"api_key\": \"9eXH8oNR0uqN3GvvzAgaUD11ltPnGqZG2RFQ\",\n",
" \"host\": \"https://superagent-ragas-1575sjfq.weaviate.network\"\n",
" }\n",
" },\n",
" \"index_name\": \"homanp11\",\n",
" \"encoder\": \"cohere\",\n",
"}\n",
"\n",
"query_response = requests.post(query_url, json=query_payload)\n",
"\n",
"print(query_response.json())"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down Expand Up @@ -127,6 +187,33 @@
"\n",
"print(delete_response.json())"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Delete the index\n",
"query_url = f\"{API_URL}/api/v1/delete\"\n",
"\n",
"delete_payload = {\n",
" \"file_url\": \"https://arxiv.org/pdf/2402.05131.pdf\",\n",
" \"vector_database\": {\n",
" \"type\": \"weaviate\",\n",
" \"config\": {\n",
" \"api_key\": \"9eXH8oNR0uqN3GvvzAgaUD11ltPnGqZG2RFQ\",\n",
" \"host\": \"https://superagent-ragas-1575sjfq.weaviate.network\"\n",
" }\n",
" },\n",
" \"index_name\": \"homanp11\",\n",
" \"encoder\": \"cohere\"\n",
"}\n",
"\n",
"delete_response = requests.delete(query_url, json=delete_payload)\n",
"\n",
"print(delete_response.json())"
]
}
],
"metadata": {
Expand Down
6 changes: 5 additions & 1 deletion models/delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ class RequestPayload(BaseModel):
encoder: EncoderEnum


class DeleteResponse(BaseModel):
num_of_deleted_chunks: int


class ResponsePayload(BaseModel):
success: bool
data: dict = {}
data: DeleteResponse
29 changes: 26 additions & 3 deletions models/document.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from pydantic import BaseModel
import uuid
from typing import List, Optional

from pydantic import BaseModel, validator


class BaseDocument(BaseModel):
Expand All @@ -8,7 +11,27 @@ class BaseDocument(BaseModel):
metadata: dict | None = None


class BaseDocumentChunk(BaseDocument):
class BaseDocumentChunk(BaseModel):
id: str
document_id: str
content: str
doc_url: str
metadata: dict | None = None
page_number: str = ""
dense_embedding: list[float] | None = None
dense_embedding: Optional[List[float]] = None

@validator("id")
def id_must_be_valid_uuid(cls, v):
try:
uuid_obj = uuid.UUID(v, version=4)
return str(uuid_obj)
except ValueError:
raise ValueError("id must be a valid UUID")

@validator("dense_embedding")
def embeddings_must_be_list_of_floats(cls, v):
if v is None:
return v # Allow None to pass through
if not all(isinstance(item, float) for item in v):
raise ValueError("embeddings must be a list of floats")
return v
Loading
Loading