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

upload one chunk #744

Closed
wants to merge 3 commits into from
Closed
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
33 changes: 32 additions & 1 deletion core/cat/rabbit_hole.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,37 @@ def ingest_file(
source=filename
)

def ingest_string(
self,
stray,
text: str
):
"""Load a string in the Cat's declarative memory.

The method convert the string in Langchain `Document`. Then, it stores the `Document` in the Cat's memory.

Parameters
----------
text : string
The text to store in the Cat's memory

See Also
----------
before_rabbithole_stores_documents
"""

docs = self.string_to_docs(
stray,
text,
chunk_size=len(text),
chunk_overlap=0
)
self.store_documents(
stray,
docs,
)


def file_to_docs(
self,
stray,
Expand Down Expand Up @@ -293,7 +324,7 @@ def string_to_docs(
return docs


def store_documents(self, stray, docs: List[Document], source: str) -> None:
def store_documents(self, stray, docs: List[Document], source: str=None) -> None:
"""Add documents to the Cat's declarative memory.

This method loops a list of Langchain `Document` and adds some metadata. Namely, the source filename and the
Expand Down
22 changes: 22 additions & 0 deletions core/cat/routes/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,28 @@ async def upload_file(
"info": "File is being ingested asynchronously",
}

# receive chunk via http endpoint
@router.post("/chunk")
async def upload_chunk(
request: Request,
background_tasks: BackgroundTasks,
chunk: str = Body(
description="A chunk to upload in the cat memory",
examples={"Example of chunk with length greater than 20"},
min_length=20
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there any particular reason for the choice of 20?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no particular reason, what value is best to have? 10 like here ?

),
stray = Depends(session),
) -> Dict:
"""Upload a single chunk, The chunk will be vectorized and stored into documents memory."""

# upload chunk to long term memory, in the background
background_tasks.add_task(
stray.rabbit_hole.ingest_string, stray, chunk,
)

# reply to client
return {"info": "Chunk is being ingested asynchronously"}


@router.post("/web")
async def upload_url(
Expand Down