Skip to content

Commit

Permalink
Support non-text document elements in Applications, closes #335
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmezzetti committed Sep 12, 2022
1 parent 3f824ec commit c2c3216
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/python/txtai/app/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ def indexes(self, loaddata):
functions = []
for fn in config["functions"]:
if isinstance(fn, dict):
fn = fn.copy()
fn["function"] = self.function(fn["function"])
else:
fn = self.function(fn)
Expand Down Expand Up @@ -331,17 +332,17 @@ def add(self, documents):
index = self.count() + len(self.documents)
for document in documents:
if isinstance(document, dict):
# Pass dictionary, the embeddings instance handles parsing out the "text" field
# Create (id, data, tags) tuple from dictionary
document = (document["id"], document, None)
elif isinstance(document, str):
# Add id via autosequence
elif isinstance(document, tuple):
# Create (id, data, tags) tuple
document = (document[0], document[1], None) if len(document) < 3 else document[:3]
else:
# Create (id, data, tags) tuple using id autosequence
document = (index, document, None)
index += 1
elif isinstance(document, tuple) and len(document) < 3:
# Copy partial tuple
document = (document[0], document[1], None)

# Add document tuple (id, text, element)
# Add document tuple (id, data, tags)
batch.append(document)

# Add batch
Expand Down

0 comments on commit c2c3216

Please sign in to comment.