Skip to content

Commit 556a5c6

Browse files
committed
fix: reading from saved file, ref #58
1 parent 14c6dda commit 556a5c6

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

example/e-rag.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ class VectorDatabase {
128128
out.write(reinterpret_cast<const char*>(&idx), sizeof(idx));
129129
content.write(out);
130130
}
131+
out.close();
131132
}
132133

133134
void loadIndex(const std::string& location) {
@@ -140,9 +141,13 @@ class VectorDatabase {
140141
int idx;
141142
T content;
142143
in.read(reinterpret_cast<char*>(&idx), sizeof(idx));
144+
if (in.eof()) {
145+
break;
146+
}
143147
content.read(in);
144148
m_documents[idx] = content;
145149
}
150+
in.close();
146151
}
147152

148153
private:
@@ -160,7 +165,7 @@ struct Document {
160165
size_t strSize = content.size();
161166

162167
out.write(reinterpret_cast<const char*>(&strSize), sizeof(strSize));
163-
out.write(content.data(), content.size() * sizeof(char));
168+
out.write(content.data(), strSize * sizeof(char));
164169
}
165170

166171
void read(std::istream& in) {

0 commit comments

Comments
 (0)