-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix failures to compute embeddings too much context & Shorten RAG Re…
…sults (#279) # Fix failures to compute embeddings because of computing too much context. * Prior to this document we were computing the embeddings using the entire notebook. This would lead to context exceeded errors on longer documents. * This had two negative impacts 1. We stop learning from long documents because we no longer compute embeddings for the document 1. When making suggestions we don't embed up retrieving any documents from RAG because we can't compute the embeddings for the current document # Don't include the full Document in the RAG example * In Example.Query we were including the full document which would then be injected into the context when generating new suggests * This can end up using a lot of tokens and potentially confusing the agent when generating new suggestions * Use a simple algorithm to shorten the example. The aglorithm is as follows * Include the current selected cell * Keep including previous cells as long as they are markup cells # Results * On our evaluation results the number of match cells is approximately the same; 6 correct whereas we got 7 before prior to this change * Of these only 4 examples are the same ones that the two experiments both got correct * We should probably add level 1 assertions to test whether results are retrieved to identify bugs like this in the future. # Other * This PR also refactors the code to share code for computing embeddings between the learner and the Agent to minimize risk of training and serving skew. * Treat learner failures as permanent failures rather than retrying. If we see concrete examples of retryable errors than we can add retries * Right now we were retrying on permanent errors (i.e. the context length being exceeded). * Fix #260
- Loading branch information
Showing
14 changed files
with
266 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package docs | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/jlewi/foyle/protos/go/foyle/v1alpha1" | ||
) | ||
|
||
// CreateQuery creates a query from a GenerateRequest | ||
// It returns the blocks that should be used to query for similar documents | ||
func CreateQuery(ctx context.Context, req *v1alpha1.GenerateRequest) ([]*v1alpha1.Block, error) { | ||
// Use a simple algorithm. | ||
// 1. Always select at least the current block | ||
// 2. Select additional blocks if they are markup blocks. | ||
startIndex := req.GetSelectedIndex() - 1 | ||
|
||
for ; startIndex >= 0; startIndex-- { | ||
if req.GetDoc().GetBlocks()[startIndex].Kind != v1alpha1.BlockKind_MARKUP { | ||
break | ||
} | ||
} | ||
|
||
blocks := req.GetDoc().GetBlocks()[startIndex+1 : req.GetSelectedIndex()+1] | ||
return blocks, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package docs | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
"github.com/jlewi/foyle/app/pkg/testutil" | ||
"github.com/jlewi/foyle/protos/go/foyle/v1alpha1" | ||
) | ||
|
||
func Test_CreateQuery(t *testing.T) { | ||
doc1 := &v1alpha1.Doc{ | ||
Blocks: []*v1alpha1.Block{ | ||
{ | ||
Kind: v1alpha1.BlockKind_MARKUP, | ||
Contents: "cell 0", | ||
}, | ||
{ | ||
Kind: v1alpha1.BlockKind_MARKUP, | ||
Contents: "cell 1", | ||
}, | ||
{ | ||
Kind: v1alpha1.BlockKind_CODE, | ||
Contents: "cell 2", | ||
}, | ||
{ | ||
Kind: v1alpha1.BlockKind_MARKUP, | ||
Contents: "cell 3", | ||
}, | ||
{ | ||
Kind: v1alpha1.BlockKind_MARKUP, | ||
Contents: "cell 4", | ||
}, | ||
}, | ||
} | ||
|
||
type testCase struct { | ||
name string | ||
input *v1alpha1.GenerateRequest | ||
expected []*v1alpha1.Block | ||
} | ||
|
||
cases := []testCase{ | ||
{ | ||
name: "stop-at-start", | ||
input: &v1alpha1.GenerateRequest{ | ||
Doc: doc1, | ||
SelectedIndex: 1, | ||
}, | ||
expected: doc1.Blocks[0:2], | ||
}, | ||
{ | ||
name: "start-on-codeblock", | ||
input: &v1alpha1.GenerateRequest{ | ||
Doc: doc1, | ||
SelectedIndex: 2, | ||
}, | ||
expected: doc1.Blocks[0:3], | ||
}, | ||
{ | ||
name: "stop-on-code", | ||
input: &v1alpha1.GenerateRequest{ | ||
Doc: doc1, | ||
SelectedIndex: 4, | ||
}, | ||
expected: doc1.Blocks[3:5], | ||
}, | ||
} | ||
|
||
for _, tc := range cases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
blocks, err := CreateQuery(context.Background(), tc.input) | ||
if err != nil { | ||
t.Fatalf("CreateQuery failed: %v", err) | ||
} | ||
if len(blocks) != len(tc.expected) { | ||
t.Errorf("CreateQuery returned %d blocks; want %d", len(blocks), len(tc.expected)) | ||
} | ||
|
||
if d := cmp.Diff(tc.expected, blocks, testutil.DocComparer, testutil.BlockComparer); d != "" { | ||
t.Errorf("CreateQuery returned unexpected blocks:\n%v", d) | ||
} | ||
|
||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package llms |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.