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

RAG Template Set indexing_key variable from upstream listener #2

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
12 changes: 8 additions & 4 deletions content/templates/retrieval_augmented_generation.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ won't be necessary.

CHUNK_SIZE = 200

@model(flatten=True, model_update_kwargs={})
@model(flatten=True, model_update_kwargs={'document_embedded': False})
Copy link
Contributor

Choose a reason for hiding this comment

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

No longer necessary in latest code-base since this option is disabled.

def chunker(text):
text = text.split()
chunks = [' '.join(text[i:i + CHUNK_SIZE]) for i in range(0, len(text), CHUNK_SIZE)]
Expand All @@ -94,7 +94,7 @@ won't be necessary.

CHUNK_SIZE = 500

@model(flatten=True)
@model(flatten=True, model_update_kwargs={'document_embedded': False})
def chunker(pdf_file):
elements = partition_pdf(pdf_file)
text = '\n'.join([e.text for e in elements])
Expand Down Expand Up @@ -125,6 +125,10 @@ features, or chunking your data. You can use this query to
operate on those outputs.
:::

```python
indexing_key = upstream_listener.outputs
indexing_key
```
<!-- TABS -->
## Build text embedding model

Expand Down Expand Up @@ -192,7 +196,7 @@ vector_index = \
## Create Vector Search Model

```python
item = {'_outputs__chunker': '<var:query>'}
item = {indexing_key: '<var:query>'}
```

```python
Expand All @@ -202,7 +206,7 @@ vector_search_model = QueryModel(
identifier="VectorSearch",
select=db[upstream_listener.outputs].like(item, vector_index=vector_index_name, n=5).select(),
# The _source is the identifier of the upstream data, which can be used to locate the data from upstream sources using `_source`.
postprocess=lambda docs: [{"text": doc['_outputs__chunker'], "_source": doc["_source"]} for doc in docs],
postprocess=lambda docs: [{"text": doc[indexing_key], "_source": doc["_source"]} for doc in docs],
db=db
)
```
Expand Down