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

/answer does not return Document metadata #353

Open
nenb opened this issue Mar 12, 2024 · 2 comments · May be fixed by #355
Open

/answer does not return Document metadata #353

nenb opened this issue Mar 12, 2024 · 2 comments · May be fixed by #355
Assignees
Labels
type: enhancement 💅 New feature or request
Milestone

Comments

@nenb
Copy link
Contributor

nenb commented Mar 12, 2024

Bug description

(I'm not sure if this is a bug or just user error, or deliberately intended.)

When I store Document metadata in the database, it's not returned when I make a request to /answer. This is unfortunate as the metadata contains lots of useful information about the data source that I would like to display.

How to reproduce the bug?

Upload a single document with metadata.

Make a request to /answer and inspect the response.

Versions and dependencies used

All

Anything else?

No response

@nenb nenb added the type: bug 🐛 Something isn't working label Mar 12, 2024
@pmeier
Copy link
Member

pmeier commented Mar 12, 2024

/chats/{id}/answer

@app.post("/chats/{id}/answer")
async def answer(
user: UserDependency,
id: uuid.UUID,
prompt: Annotated[str, Body(..., embed=True)],
stream: Annotated[bool, Body(..., embed=True)] = False,
) -> schemas.Message:

returns a Message

class Message(BaseModel):
id: uuid.UUID = Field(default_factory=uuid.uuid4)
content: str
role: ragna.core.MessageRole
sources: list[Source] = Field(default_factory=list)
timestamp: datetime.datetime = Field(
default_factory=lambda: datetime.datetime.utcnow()
)

So, directly, no document is returned here at all. The document is part of the Sources that are being returned

class Source(BaseModel):
# See orm.Source on why this is not a UUID
id: str
document: Document
location: str
content: str
num_tokens: int

Finally we arrive at the Document that indeed does not contain the metadata

class Document(BaseModel):
id: uuid.UUID = Field(default_factory=uuid.uuid4)
name: str

Since we do have the metadata in the DB already, it shouldn't be too hard to link it back to the Document model. Doing that should fix this.

@pmeier pmeier linked a pull request Mar 12, 2024 that will close this issue
@pmeier
Copy link
Member

pmeier commented Mar 12, 2024

I've played around with it for a bit and I think this is more a feature request than a bug. That being said, I think the change is for the better. I started a branch in #355. However, this includes breaking changes. I'd rather wait after the 0.2.0 release to merge this.

@pmeier pmeier added type: enhancement 💅 New feature or request and removed type: bug 🐛 Something isn't working labels Mar 12, 2024
@pmeier pmeier added this to the 0.3.0 milestone Mar 18, 2024
@pmeier pmeier self-assigned this Mar 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement 💅 New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants