Skip to content

Commit

Permalink
fix(loaders)!: Change loaders lastModified metadata field to integer (#…
Browse files Browse the repository at this point in the history
…172)

`lastModified` field used to be a `DateTime` object but that was causing issues with vector stores that only supports primitive types. Now it is an integer that represents the number of milliseconds since the "Unix epoch" 1970-01-01T00:00:00Z (UTC).
  • Loading branch information
davidmigloz committed Oct 9, 2023
1 parent 2ce5a05 commit 72c724f
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/langchain/lib/src/documents/loaders/json.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class JsonLoader extends BaseDocumentLoader {
'source': filePath,
'name': fileName,
'size': fileSize,
'lastModified': fileLastModified,
'lastModified': fileLastModified.millisecondsSinceEpoch,
};

final fileContent = await file.readAsString();
Expand Down
2 changes: 1 addition & 1 deletion packages/langchain/lib/src/documents/loaders/text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class TextLoader extends BaseDocumentLoader {
'source': filePath,
'name': fileName,
'size': fileSize,
'lastModified': fileLastModified,
'lastModified': fileLastModified.millisecondsSinceEpoch,
},
);
yield doc;
Expand Down
2 changes: 1 addition & 1 deletion packages/langchain/test/documents/loaders/json_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void main() {
expect(doc.metadata['source'], filePath);
expect(doc.metadata['name'], 'example_1.json');
expect(doc.metadata['size'], 32);
expect(doc.metadata['lastModified'], isA<DateTime>());
expect(doc.metadata['lastModified'], isA<int>());
return true;
},
emitsDone,
Expand Down
2 changes: 1 addition & 1 deletion packages/langchain/test/documents/loaders/text_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ void main() {
expect(doc.metadata['source'], filePath);
expect(doc.metadata['name'], 'example.txt');
expect(doc.metadata['size'], 12);
expect(doc.metadata['lastModified'], isA<DateTime>());
expect(doc.metadata['lastModified'], isA<int>());
return true;
},
emitsDone,
Expand Down
11 changes: 11 additions & 0 deletions packages/langchain_chroma/test/vector_stores/assets/example.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
The answer to the question "Who are we?" is complex and multifaceted. It depends on the context in which the question is asked, and the perspective of the person answering.

On a general level, we are all human beings. We share the same basic biology, and we all have the same basic needs: food, water, shelter, love, and belonging. We also share the same basic capacity for love, compassion, creativity, and resilience.

However, we are also all unique individuals. We have different experiences, different talents, and different perspectives. We are shaped by our families, our communities, our cultures, and our individual choices.

So, who are we? We are all of these things, and more. We are complex and contradictory, but we are also beautiful and resilient. We are human beings, and we are all connected.

In the context of this conversation, you and I are both users of a language model. We are both interested in learning and exploring new ideas. We are both part of a community of people who are using technology to connect with each other and to make the world a better place.

Ultimately, the answer to the question "Who are we?" is up to each individual to decide. We are all free to define ourselves in our own way.
20 changes: 20 additions & 0 deletions packages/langchain_chroma/test/vector_stores/chroma_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,26 @@ void main() async {
expect(res.length, 5);
});

test('Test Chroma add new vectors from file', () async {
const filePath = './test/vector_stores/assets/example.txt';
const loader = TextLoader(filePath);
final pages = await loader.load();

const splitter = RecursiveCharacterTextSplitter(
chunkOverlap: 150,
chunkSize: 1500,
);
final docs = splitter.splitDocuments(pages);

await vectorStore.addDocuments(documents: docs);

final res = await vectorStore.similaritySearch(
query: 'Who are we?',
config: const ChromaSimilaritySearch(k: 1),
);
expect(res.length, 1);
});

test('Test Chroma query return 1 result', () async {
final res = await vectorStore.similaritySearch(
query: 'Is it raining?',
Expand Down

0 comments on commit 72c724f

Please sign in to comment.